bitly-oauth 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,32 +1,36 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bitly-oauth (0.2.1)
4
+ bitly-oauth (0.2.2)
5
+ httparty
5
6
  httparty
6
7
  oauth2
7
8
 
8
9
  GEM
9
10
  remote: http://rubygems.org/
10
11
  specs:
11
- addressable (2.2.6)
12
12
  fakeweb (1.3.0)
13
- faraday (0.7.6)
14
- addressable (~> 2.2)
13
+ faraday (0.8.4)
15
14
  multipart-post (~> 1.1)
16
- rack (~> 1.1)
17
- httparty (0.8.1)
18
- multi_json
15
+ httparty (0.8.3)
16
+ multi_json (~> 1.0)
19
17
  multi_xml
18
+ httpauth (0.1)
19
+ jwt (0.1.5)
20
+ multi_json (>= 1.0)
20
21
  metaclass (0.0.1)
21
22
  mocha (0.10.3)
22
23
  metaclass (~> 0.0.1)
23
- multi_json (1.0.4)
24
- multi_xml (0.4.1)
25
- multipart-post (1.1.4)
26
- oauth2 (0.5.2)
27
- faraday (~> 0.7)
24
+ multi_json (1.3.6)
25
+ multi_xml (0.5.1)
26
+ multipart-post (1.1.5)
27
+ oauth2 (0.8.0)
28
+ faraday (~> 0.8)
29
+ httpauth (~> 0.1)
30
+ jwt (~> 0.1.4)
28
31
  multi_json (~> 1.0)
29
- rack (1.4.0)
32
+ rack (~> 1.2)
33
+ rack (1.4.1)
30
34
  rake (0.9.2.2)
31
35
  shoulda (2.11.3)
32
36
 
@@ -17,7 +17,7 @@ module BitlyOAuth
17
17
 
18
18
  private
19
19
  def request(verb, method, options={})
20
- response = access_token.send(verb, method, :params => params(options), :parse => :json)
20
+ response = access_token.send(verb, method.to_s, :params => params(options), :parse => :json)
21
21
  response = BitlyOAuth::Response.new(response)
22
22
  if response.success?
23
23
  response.body
@@ -1,7 +1,7 @@
1
1
  module BitlyOAuth
2
2
  class Client
3
- extend Forwardable
4
- delegate [ :get, :post ] => :access_token
3
+ include HTTParty
4
+ base_uri 'https://api-ssl.bit.ly/v3/'
5
5
 
6
6
  BASE_URL = 'https://api-ssl.bit.ly/v3/'
7
7
 
@@ -151,5 +151,19 @@ module BitlyOAuth
151
151
  def key_for(input)
152
152
  input.match(/^http:\/\//) ? :shortUrl : :hash
153
153
  end
154
+
155
+ def get(path, params = {})
156
+ response = self.class.get("/#{path}", query(params))
157
+ response = BitlyOAuth::Response.new(response)
158
+ if response.success?
159
+ response.body
160
+ else
161
+ raise BitlyOAuth::Error.new(response)
162
+ end
163
+ end
164
+
165
+ def query(params)
166
+ { :query => { :access_token => access_token.token }.merge(params).to_query }
167
+ end
154
168
  end
155
169
  end
@@ -1,6 +1,15 @@
1
1
  class Hash
2
2
  def to_query
3
- map {|k, v|"#{k}=#{v}"}.sort * '&'
3
+ map do |key, value|
4
+ case value
5
+ when Array
6
+ value.map do |v|
7
+ "#{key}=#{CGI.escape(v.to_s)}"
8
+ end.join('&')
9
+ else
10
+ "#{key}=#{CGI.escape(value.to_s)}"
11
+ end
12
+ end.sort * '&'
4
13
  end
5
14
 
6
15
  def stringify_keys!
@@ -1,3 +1,3 @@
1
1
  module BitlyOAuth
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -0,0 +1 @@
1
+ {"status_code": 200, "data": { "referring_domains": [ { "domain": "direct", "clicks": 700} ] }, "status_txt": "OK"}
@@ -48,10 +48,8 @@ class TestClient < Test::Unit::TestCase
48
48
  end
49
49
  context "requests to the bitly api" do
50
50
  setup do
51
- token = stub(:get => { 'bitly_pro_domain' => true },
52
- :token => 'token' )
53
- BitlyOAuth::AccessToken.stubs(:new => token)
54
51
  @client.set_access_token_from_token('token')
52
+ stub_get('https://api-ssl.bit.ly/v3/bitly_pro_domain?access_token=token&domain=http%3A%2F%2Fpro.domain%2F', 'bitly_pro_domain.json')
55
53
  end
56
54
  context "bitly_pro_domain" do
57
55
  should 'return true when it is a bitly pro domain' do
@@ -67,10 +65,9 @@ class TestClient < Test::Unit::TestCase
67
65
  end
68
66
  context "#referring_domains" do
69
67
  setup do
70
- token = stub(:get => { "referring_domains" => [ {'domain' => 'direct', 'clicks' => 700} ] } )
71
- BitlyOAuth::AccessToken.stubs(:new => token)
72
68
  @client = BitlyOAuth::Client.new('id', 'secret')
73
69
  @client.set_access_token_from_token('token')
70
+ stub_get('https://api-ssl.bit.ly/v3/link/referring_domains?access_token=token&link=http%3A%2F%2Fbit.ly%2Fsomelink%2F', 'referring_domains.json')
74
71
  end
75
72
  should "return an array" do
76
73
  assert @client.referring_domains('http://bit.ly/somelink/').is_a?(Array)
@@ -22,7 +22,7 @@ class TestResponse < Test::Unit::TestCase
22
22
  end
23
23
  should "return the status code" do
24
24
  response = BitlyOAuth::Response.new(stub('oauth', :parsed => {'status_code' => 'some status code'}))
25
- assert_equal 'some status code', response.status,
25
+ assert_equal 'some status code', response.status
26
26
  end
27
27
  should "return the response body" do
28
28
  response = BitlyOAuth::Response.new(stub('oauth', :parsed => { 'data' => {} } ))
@@ -60,7 +60,7 @@ class TestResponse < Test::Unit::TestCase
60
60
  end
61
61
  should "return the status code" do
62
62
  response = BitlyOAuth::Response.new(stub(:parsed_response => { 'status_code' => 'some status code' }))
63
- assert_equal 'some status code', response.status,
63
+ assert_equal 'some status code', response.status
64
64
  end
65
65
  should "return the response body" do
66
66
  response = BitlyOAuth::Response.new(stub(:parsed_response => { 'data' => {} } ))
@@ -141,7 +141,7 @@ class TestUrl < Test::Unit::TestCase
141
141
  context "getting clicks by minute" do
142
142
  setup do
143
143
  @short_url = "http://j.mp/9DguyN"
144
- stub_get("https://api-ssl.bit.ly/v3/clicks_by_minute?shortUrl=#{CGI.escape(@short_url)}&access_token=token", ['clicks_by_minute1_url.json', 'clicks_by_minute2_url.json'])
144
+ stub_get("https://api-ssl.bit.ly/v3/clicks_by_minute?access_token=token&shortUrl=#{CGI.escape(@short_url)}", ['clicks_by_minute1_url.json', 'clicks_by_minute2_url.json'])
145
145
  @url = BitlyOAuth::Url.new(@client, 'short_url' => @short_url)
146
146
  end
147
147
  should 'get clicks_by_minute when called' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitly-oauth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-24 00:00:00.000000000Z
12
+ date: 2012-08-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
16
- requirement: &70117703752660 !ruby/object:Gem::Requirement
16
+ requirement: &70326365070320 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70117703752660
24
+ version_requirements: *70326365070320
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: oauth2
27
- requirement: &70117703752200 !ruby/object:Gem::Requirement
27
+ requirement: &70326365068700 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70117703752200
35
+ version_requirements: *70326365068700
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: shoulda
38
- requirement: &70117703751720 !ruby/object:Gem::Requirement
38
+ requirement: &70326365067000 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70117703751720
46
+ version_requirements: *70326365067000
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rake
49
- requirement: &70117703751300 !ruby/object:Gem::Requirement
49
+ requirement: &70326365081660 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70117703751300
57
+ version_requirements: *70326365081660
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: mocha
60
- requirement: &70117703750860 !ruby/object:Gem::Requirement
60
+ requirement: &70326365080680 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70117703750860
68
+ version_requirements: *70326365080680
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: fakeweb
71
- requirement: &70117703750400 !ruby/object:Gem::Requirement
71
+ requirement: &70326365079840 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70117703750400
79
+ version_requirements: *70326365079840
80
80
  description: ! 'A ruby wrapper for version 3 of the bit.ly API
81
81
 
82
82
  Supports OAuth authentication
@@ -155,6 +155,7 @@ files:
155
155
  - test/fixtures/referrer_hash.json
156
156
  - test/fixtures/referrer_hash2.json
157
157
  - test/fixtures/referrer_url.json
158
+ - test/fixtures/referring_domains.json
158
159
  - test/fixtures/success.json
159
160
  - test/fixtures/url_info.json
160
161
  - test/fixtures/user_clicks.json
@@ -192,18 +193,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
192
193
  - - ! '>='
193
194
  - !ruby/object:Gem::Version
194
195
  version: '0'
195
- segments:
196
- - 0
197
- hash: -3882379535477319837
198
196
  required_rubygems_version: !ruby/object:Gem::Requirement
199
197
  none: false
200
198
  requirements:
201
199
  - - ! '>='
202
200
  - !ruby/object:Gem::Version
203
201
  version: '0'
204
- segments:
205
- - 0
206
- hash: -3882379535477319837
207
202
  requirements: []
208
203
  rubyforge_project:
209
204
  rubygems_version: 1.8.10
@@ -252,6 +247,7 @@ test_files:
252
247
  - test/fixtures/referrer_hash.json
253
248
  - test/fixtures/referrer_hash2.json
254
249
  - test/fixtures/referrer_url.json
250
+ - test/fixtures/referring_domains.json
255
251
  - test/fixtures/success.json
256
252
  - test/fixtures/url_info.json
257
253
  - test/fixtures/user_clicks.json