Skip to content
Browse files

removing em-bitly - api has changed

  • Loading branch information...
1 parent 4e7c432 commit 764fbac3d435c6562f517dacdc4e321ce70df20d @igrigorik committed Aug 27, 2011
Showing with 0 additions and 83 deletions.
  1. +0 −25 examples/bitly.rb
  2. +0 −58 lib/em-synchrony/em-bitly.rb
View
25 examples/bitly.rb
@@ -1,25 +0,0 @@
-require 'lib/em-synchrony'
-
-require "em-synchrony/em-bitly"
-EM.synchrony do
- bitly = Bitly.new('[INSERT_LOGIN]', '[INSERT_API_KEY]')
- url = 'http://github.com/igrigorik/em-synchrony'
- short = bitly.shorten(url)
-
- p "Short #{url} => #{short.jmp_url}"
- EM.stop
-end
-
-
-Bitly.use_api_version_3
-EM.synchrony do
- bitly = Bitly.new('[INSERT_LOGIN]', '[INSERT_API_KEY]')
-
- url = 'http://github.com/igrigorik/em-synchrony'
- domain='nyti.ms'
-
- pro = bitly.bitly_pro_domain(domain)
- p "Domain #{domain} pro=#{pro}"
-
- EM.stop
-end
View
58 lib/em-synchrony/em-bitly.rb
@@ -1,58 +0,0 @@
-require 'cgi'
-
-begin
- require "em-synchrony/em-http"
- require "bitly"
-rescue LoadError => error
- raise "Missing EM-Synchrony dependencies: gem install em-http-request; gem install bitly -v=0.5.0"
-end
-
-module Bitly
- module Utils
- def get_result(request)
- http = EventMachine::HttpRequest.new(request).get(:timeout => 100)
-
- result = if (http.response_header.status == 200)
- Crack::JSON.parse(http.response)
- else
- {'errorMessage' => 'JSON Parse Error(Bit.ly messed up)', 'errorCode' => 69, 'statusCode' => 'ERROR'}
- end
-
- if 'OK' == result['statusCode']
- result['results']
- else
- raise BitlyError.new(result['errorMessage'],result['errorCode'])
- end
- end
- end
-
- module V3
- class Client
- class << self
- def get(method, query)
- query_values=[]
- query[:query].each do |key, value|
- query_values << "#{key}=#{CGI::escape(value.to_s)}"
- end
- query_values=query_values.join('&')
- request=(method[0]=='/' ? "#{base_uri}#{method}" : method)
- request=(request.include?('?') ? "#{request}&#{query_values}" : "#{request}?#{query_values}")
-
- http = EventMachine::HttpRequest.new(request).get(:timeout => 100)
- response = if (http.response_header.status == 200)
- Crack::JSON.parse(http.response)
- else
- {'errorMessage' => 'JSON Parse Error(Bit.ly messed up)', 'errorCode' => 69, 'statusCode' => 'ERROR'}
- end
-
- if response['status_code'] == 200
- return response
- else
- raise BitlyError.new(response['status_txt'], response['status_code'])
- end
-
- end
- end
- end
- end
-end

0 comments on commit 764fbac

Please sign in to comment.
Something went wrong with that request. Please try again.