Hoodow-bitly-api 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,9 @@
1
+ == 0.1.1 2009-07-21 (by Luke Francl)
2
+
3
+ * Use HTTPClient instead of Net::HTTP
4
+ * make sure long_url is CGI escaped before submitting it to Bit.ly
5
+
6
+
1
7
  == 0.1.0 2009-07-07
2
8
 
3
9
  * Covering all api methods
@@ -17,6 +17,10 @@ Small library to access bitly api
17
17
  gem sources -a http://gems.github.com
18
18
  gem install Hoodow-bitly-api
19
19
 
20
+ == CONTRIBUTORS:
21
+
22
+ * Luke Francl ( http://github.com/look )
23
+
20
24
  == LICENSE:
21
25
 
22
26
  (The MIT License)
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{bitly-api}
5
- s.version = "0.1.0"
5
+ s.version = "0.1.1"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Ole Riesenberg"]
@@ -34,4 +34,6 @@ Gem::Specification.new do |s|
34
34
  s.add_dependency(%q<newgem>, [">= 1.4.1"])
35
35
  s.add_dependency(%q<hoe>, [">= 1.8.0"])
36
36
  end
37
+
38
+ s.add_dependency(%q<httpclient>, [">= 2.1.5.2"])
37
39
  end
@@ -2,11 +2,11 @@ $:.unshift(File.dirname(__FILE__)) unless
2
2
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
3
 
4
4
  require 'rubygems'
5
- require 'net/http'
6
- require 'open-uri'
5
+ require 'httpclient'
7
6
  require 'json'
7
+ require 'cgi'
8
8
  require 'bitly-api/bitly-api'
9
9
 
10
10
  module BitlyApi
11
- VERSION = '0.1.0'
11
+ VERSION = '0.1.1'
12
12
  end
@@ -5,7 +5,7 @@ module BitlyApi
5
5
  class Bitly
6
6
  attr_accessor :login
7
7
  attr_accessor :api_key
8
- attr_accessor :api_version
8
+ attr_accessor :api_version
9
9
 
10
10
  def initialize(options = {})
11
11
  raise ArgumentError.new(":login and :api_key are required") if (options[:login].nil? or options[:api_key].nil?)
@@ -14,38 +14,40 @@ module BitlyApi
14
14
  self.login = options[:login]
15
15
  self.api_key = options[:api_key]
16
16
  self.api_version = options[:version]
17
+ @httpclient = HTTPClient.new
17
18
  end
18
19
 
20
+ # shorten +long_url+. +long_url+ is CGI escaped, so you shouldn't escape it yourself.
19
21
  def shorten(long_url)
20
- http_response = open(build_url("shorten", "longUrl=#{long_url}")).read
22
+ http_response = @httpclient.get_content(build_url("shorten", "longUrl=#{CGI::escape(long_url)}"))
21
23
  data = JSON.parse(http_response)
22
24
  raise BitlyError.new(data["errorMessage"]) unless data["statusCode"] == "OK"
23
25
  data["results"][long_url]
24
26
  end
25
27
 
26
28
  def expand(short_url)
27
- http_response = open(build_url("expand", "shortUrl=#{short_url}")).read
29
+ http_response = @httpclient.get_content(build_url("expand", "shortUrl=#{short_url}"))
28
30
  data = JSON.parse(http_response)
29
31
  raise BitlyError.new(data["errorMessage"]) unless data["statusCode"] == "OK"
30
32
  data["results"][short_url]
31
33
  end
32
34
 
33
35
  def info(short_url)
34
- http_response = open(build_url("info", "shortUrl=#{short_url}")).read
36
+ http_response = @httpclient.get_content(build_url("info", "shortUrl=#{short_url}"))
35
37
  data = JSON.parse(http_response)
36
38
  raise BitlyError.new(data["errorMessage"]) unless data["statusCode"] == "OK"
37
39
  data["results"][short_url.split(/\//)[-1]]
38
40
  end
39
41
 
40
42
  def stats(short_url)
41
- http_response = open(build_url("stats", "shortUrl=#{short_url}")).read
43
+ http_response = @httpclient.get_content(build_url("stats", "shortUrl=#{short_url}"))
42
44
  data = JSON.parse(http_response)
43
45
  raise BitlyError.new(data["errorMessage"]) unless data["statusCode"] == "OK"
44
46
  data["results"]
45
47
  end
46
48
 
47
49
  def errors
48
- http_response = open("http://api.bit.ly/errors?version=#{api_version}&login=#{login}&apiKey=#{api_key}").read
50
+ http_response = @httpclient.get_content("http://api.bit.ly/errors?version=#{api_version}&login=#{login}&apiKey=#{api_key}")
49
51
  data = JSON.parse(http_response)
50
52
  raise BitlyError.new(data["errorMessage"]) unless data["statusCode"] == "OK"
51
53
  data["results"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Hoodow-bitly-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ole Riesenberg
@@ -32,6 +32,16 @@ dependencies:
32
32
  - !ruby/object:Gem::Version
33
33
  version: 1.8.0
34
34
  version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: httpclient
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 2.1.5.2
44
+ version:
35
45
  description: Small library to access bitly api
36
46
  email:
37
47
  - or@oleriesenberg.com