bitlyr 0.9.0

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.
Files changed (95) hide show
  1. data/History.txt +146 -0
  2. data/LICENSE +20 -0
  3. data/README.md +97 -0
  4. data/README.rdoc +37 -0
  5. data/Rakefile +43 -0
  6. data/VERSION +1 -0
  7. data/bitlyr.gemspec +154 -0
  8. data/lib/bitlyr/client.rb +153 -0
  9. data/lib/bitlyr/country.rb +10 -0
  10. data/lib/bitlyr/day.rb +12 -0
  11. data/lib/bitlyr/error.rb +13 -0
  12. data/lib/bitlyr/lib/core_ext/hash.rb +27 -0
  13. data/lib/bitlyr/lib/core_ext/string.rb +5 -0
  14. data/lib/bitlyr/missing_url.rb +12 -0
  15. data/lib/bitlyr/realtime_link.rb +16 -0
  16. data/lib/bitlyr/referrer.rb +12 -0
  17. data/lib/bitlyr/response.rb +39 -0
  18. data/lib/bitlyr/strategy/access_token.rb +26 -0
  19. data/lib/bitlyr/strategy/api_key.rb +33 -0
  20. data/lib/bitlyr/strategy/base.rb +26 -0
  21. data/lib/bitlyr/strategy/oauth.rb +50 -0
  22. data/lib/bitlyr/url.rb +124 -0
  23. data/lib/bitlyr/user.rb +100 -0
  24. data/lib/bitlyr.rb +39 -0
  25. data/test/fixtures/9uX1TE.json +1 -0
  26. data/test/fixtures/9uX1TEclicks.json +1 -0
  27. data/test/fixtures/9uX1TEclicks2.json +1 -0
  28. data/test/fixtures/9uX1TEinfo.json +1 -0
  29. data/test/fixtures/9uX1TEinfo2.json +1 -0
  30. data/test/fixtures/auth_fail.json +1 -0
  31. data/test/fixtures/auth_success.json +1 -0
  32. data/test/fixtures/betaworks.json +1 -0
  33. data/test/fixtures/betaworks2.json +1 -0
  34. data/test/fixtures/betaworks_jmp.json +1 -0
  35. data/test/fixtures/betaworks_other_user.json +1 -0
  36. data/test/fixtures/bitly9uX1TE.json +1 -0
  37. data/test/fixtures/bitly_pro_domain.json +1 -0
  38. data/test/fixtures/clicks_by_day.json +1 -0
  39. data/test/fixtures/clicks_by_day1.json +1 -0
  40. data/test/fixtures/clicks_by_day2.json +1 -0
  41. data/test/fixtures/clicks_by_minute1_url.json +1 -0
  42. data/test/fixtures/clicks_by_minute2_url.json +1 -0
  43. data/test/fixtures/clicks_by_minute_hash.json +1 -0
  44. data/test/fixtures/clicks_by_minute_hashes.json +1 -0
  45. data/test/fixtures/country_hash.json +1 -0
  46. data/test/fixtures/country_hash2.json +1 -0
  47. data/test/fixtures/country_url.json +1 -0
  48. data/test/fixtures/failure.json +1 -0
  49. data/test/fixtures/invalid_bitly_pro_domain.json +1 -0
  50. data/test/fixtures/invalid_credentials.json +1 -0
  51. data/test/fixtures/invalid_domain.json +1 -0
  52. data/test/fixtures/invalid_user.json +1 -0
  53. data/test/fixtures/invalid_x_api_key.json +1 -0
  54. data/test/fixtures/lookup_multiple_url.json +1 -0
  55. data/test/fixtures/lookup_not_real_url.json +1 -0
  56. data/test/fixtures/lookup_single_url.json +1 -0
  57. data/test/fixtures/missing_hash.json +1 -0
  58. data/test/fixtures/multiple_info.json +1 -0
  59. data/test/fixtures/multiple_url_click.json +1 -0
  60. data/test/fixtures/multiple_urls.json +1 -0
  61. data/test/fixtures/not_bitly_pro_domain.json +1 -0
  62. data/test/fixtures/not_found_info.json +1 -0
  63. data/test/fixtures/referrer_hash.json +1 -0
  64. data/test/fixtures/referrer_hash2.json +1 -0
  65. data/test/fixtures/referrer_url.json +1 -0
  66. data/test/fixtures/success.json +1 -0
  67. data/test/fixtures/url_info.json +1 -0
  68. data/test/fixtures/user_clicks.json +32 -0
  69. data/test/fixtures/user_countries.json +60 -0
  70. data/test/fixtures/user_realtime_links.json +15 -0
  71. data/test/fixtures/user_referrers.json +1 -0
  72. data/test/fixtures/valid_user.json +1 -0
  73. data/test/integration/strategy/test_api_key.rb +20 -0
  74. data/test/integration/strategy/test_oauth.rb +52 -0
  75. data/test/integration/test_client.rb +1415 -0
  76. data/test/integration/test_user.rb +97 -0
  77. data/test/test_helper.rb +54 -0
  78. data/test/unit/core_ext/test_hash.rb +69 -0
  79. data/test/unit/core_ext/test_string.rb +14 -0
  80. data/test/unit/strategy/test_access_token.rb +14 -0
  81. data/test/unit/strategy/test_api_key.rb +11 -0
  82. data/test/unit/strategy/test_base.rb +71 -0
  83. data/test/unit/strategy/test_oauth.rb +32 -0
  84. data/test/unit/test_bitly.rb +43 -0
  85. data/test/unit/test_client.rb +21 -0
  86. data/test/unit/test_country.rb +20 -0
  87. data/test/unit/test_day.rb +22 -0
  88. data/test/unit/test_error.rb +11 -0
  89. data/test/unit/test_missing.rb +34 -0
  90. data/test/unit/test_realtime_link.rb +30 -0
  91. data/test/unit/test_referrer.rb +20 -0
  92. data/test/unit/test_response.rb +86 -0
  93. data/test/unit/test_url.rb +155 -0
  94. data/test/unit/test_user.rb +17 -0
  95. metadata +233 -0
@@ -0,0 +1,155 @@
1
+ require 'test_helper'
2
+
3
+ class TestUrl < Test::Unit::TestCase
4
+ context "with a client" do
5
+ setup do
6
+ @client = Bitlyr.new(:login => login_fixture, :api_key => api_key_fixture)
7
+ end
8
+ context "and a url" do
9
+ setup do
10
+ @url = Bitlyr::Url.new(@client)
11
+ end
12
+ [:short_url,
13
+ :long_url,
14
+ :user_hash,
15
+ :global_hash,
16
+ :user_clicks,
17
+ :global_clicks,
18
+ :new_hash?,
19
+ :title,
20
+ :created_by,
21
+ :referrers,
22
+ :countries,
23
+ :clicks_by_minute,
24
+ :clicks_by_day].each do |method|
25
+ should "respond to #{method}" do
26
+ assert_respond_to @url, method
27
+ end
28
+ end
29
+ end
30
+
31
+ context "and an expanded url" do
32
+ context "getting click data" do
33
+ setup do
34
+ stub_get("http://api.bit.ly/v3/clicks?hash=9uX1TE&login=test_account&apiKey=test_key", ['9uX1TEclicks.json', '9uX1TEclicks2.json'])
35
+ @url = Bitlyr::Url.new(@client, 'hash' => '9uX1TE')
36
+ end
37
+ should "get clicks when global clicks is called" do
38
+ assert_equal 81, @url.global_clicks
39
+ end
40
+ should "get clicks when user clicks is called" do
41
+ assert_equal 0, @url.user_clicks
42
+ end
43
+ should "get global clicks the first time and only update when forced" do
44
+ assert_equal 81, @url.global_clicks
45
+ assert_equal 81, @url.global_clicks
46
+ assert_equal 82, @url.global_clicks(:force => true)
47
+ end
48
+ should "get user clicks the first time and only update when forced" do
49
+ assert_equal 0, @url.user_clicks
50
+ assert_equal 0, @url.user_clicks
51
+ assert_equal 1, @url.user_clicks(:force => true)
52
+ end
53
+ end
54
+ context "getting info" do
55
+ setup do
56
+ stub_get("http://api.bit.ly/v3/info?hash=9uX1TE&login=test_account&apiKey=test_key", ['9uX1TEinfo.json', '9uX1TEinfo2.json'])
57
+ @url = Bitlyr::Url.new(@client, 'hash' => '9uX1TE')
58
+ end
59
+ should "get info when title is called" do
60
+ assert_equal "A title", @url.title
61
+ end
62
+ should "get info when created_by is called" do
63
+ assert_equal 'philnash', @url.created_by
64
+ end
65
+ should "get title the first time and only update when forced" do
66
+ assert_equal "A title", @url.title
67
+ assert_equal "A title", @url.title
68
+ assert_equal "A New Title", @url.title(:force => true)
69
+ end
70
+ should "get the creator the first time and only update when forced" do
71
+ assert_equal 'philnash', @url.created_by
72
+ assert_equal 'philnash', @url.created_by
73
+ # updating just to prove it works, creator is unlikely to change
74
+ assert_equal 'philnash2', @url.created_by(:force => true)
75
+ end
76
+ context "steps to prevent an infinite loop" do
77
+ should "doesn't get info if the title is an empty string" do
78
+ @url = Bitlyr::Url.new(@client, 'hash' => '9uX1TE', 'title' => '')
79
+ assert_equal "", @url.title
80
+ end
81
+ should "doesn't get info if the title is explicitly set to nil" do
82
+ @url = Bitlyr::Url.new(@client, 'hash' => '9uX1TE', 'title' => nil)
83
+ assert_equal "", @url.title
84
+ end
85
+ end
86
+ end
87
+ context "getting referrers" do
88
+ setup do
89
+ stub_get("http://api.bit.ly/v3/referrers?hash=djZ9g4&login=test_account&apiKey=test_key", ['referrer_hash.json', 'referrer_hash2.json'])
90
+ @url = Bitlyr::Url.new(@client, 'hash' => 'djZ9g4')
91
+ end
92
+ should 'get referrers when called' do
93
+ assert_instance_of Array, @url.referrers
94
+ assert_instance_of Bitlyr::Referrer, @url.referrers.first
95
+ assert_equal 'direct', @url.referrers.first.referrer
96
+ assert_equal 62, @url.referrers.first.clicks
97
+ end
98
+ should 'force update when told to' do
99
+ assert_equal 62, @url.referrers.first.clicks
100
+ assert_equal 62, @url.referrers.first.clicks
101
+ assert_equal 63, @url.referrers(:force => true).first.clicks
102
+ end
103
+ end
104
+ context "getting countries" do
105
+ setup do
106
+ stub_get("http://api.bit.ly/v3/countries?hash=djZ9g4&login=test_account&apiKey=test_key", ['country_hash.json', 'country_hash2.json'])
107
+ @url = Bitlyr::Url.new(@client, 'hash' => 'djZ9g4')
108
+ end
109
+ should 'get countries when called' do
110
+ assert_instance_of Array, @url.countries
111
+ assert_instance_of Bitlyr::Country, @url.countries.first
112
+ assert_equal 'US', @url.countries.first.country
113
+ assert_equal 58, @url.countries.first.clicks
114
+ end
115
+ should 'force update when told to' do
116
+ assert_equal 58, @url.countries.first.clicks
117
+ assert_equal 58, @url.countries.first.clicks
118
+ assert_equal 59, @url.countries(:force => true).first.clicks
119
+ end
120
+ end
121
+ context "getting clicks by minute" do
122
+ setup do
123
+ @short_url = "http://j.mp/9DguyN"
124
+ stub_get("http://api.bit.ly/v3/clicks_by_minute?shortUrl=#{CGI.escape(@short_url)}&login=test_account&apiKey=test_key", ['clicks_by_minute1_url.json', 'clicks_by_minute2_url.json'])
125
+ @url = Bitlyr::Url.new(@client, 'short_url' => @short_url)
126
+ end
127
+ should 'get clicks_by_minute when called' do
128
+ assert_instance_of Array, @url.clicks_by_minute
129
+ assert_equal 0, @url.clicks_by_minute[0]
130
+ end
131
+ should 'force update when told to' do
132
+ assert_equal 0, @url.clicks_by_minute[2]
133
+ assert_equal 0, @url.clicks_by_minute[2]
134
+ assert_equal 1, @url.clicks_by_minute(:force => true)[2]
135
+ end
136
+ end
137
+ context "getting clicks by day" do
138
+ setup do
139
+ @hash = "9DguyN"
140
+ stub_get("http://api.bit.ly/v3/clicks_by_day?hash=#{@hash}&login=test_account&apiKey=test_key", ['clicks_by_day1.json', 'clicks_by_day2.json'])
141
+ @url = Bitlyr::Url.new(@client, 'hash' => @hash)
142
+ end
143
+ should 'get clicks_by_day when called' do
144
+ assert_instance_of Array, @url.clicks_by_day
145
+ assert_instance_of Bitlyr::Day, @url.clicks_by_day[0]
146
+ end
147
+ should 'force update when told to' do
148
+ assert_equal 1, @url.clicks_by_day[0].clicks
149
+ assert_equal 1, @url.clicks_by_day[0].clicks
150
+ assert_equal 2, @url.clicks_by_day(:force => true)[0].clicks
151
+ end
152
+ end
153
+ end
154
+ end
155
+ end
@@ -0,0 +1,17 @@
1
+ require 'test_helper'
2
+
3
+ class TestUser < Test::Unit::TestCase
4
+ context "with an access_token" do
5
+ setup do
6
+ consumer = Bitlyr::Strategy::OAuth.new('consumer_token', 'consumer_secret')
7
+ access_token = consumer.get_access_token_from_token('token', 'login' => 'login', 'apiKey' => 'api_key')
8
+ @user = Bitlyr::User.new(access_token)
9
+ end
10
+
11
+ context 'the user' do
12
+ should 'get a client' do
13
+ assert_kind_of Bitlyr::Client, @user.client
14
+ end
15
+ end
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,233 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bitlyr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - jonstorer
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-17 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: &70221722565860 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.7.6
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70221722565860
25
+ - !ruby/object:Gem::Dependency
26
+ name: crack
27
+ requirement: &70221722565380 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 0.1.4
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70221722565380
36
+ - !ruby/object:Gem::Dependency
37
+ name: oauth2
38
+ requirement: &70221722564860 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: 0.1.1
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70221722564860
47
+ - !ruby/object:Gem::Dependency
48
+ name: shoulda
49
+ requirement: &70221722564380 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70221722564380
58
+ - !ruby/object:Gem::Dependency
59
+ name: jeweler
60
+ requirement: &70221722563900 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: 1.4.0
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70221722563900
69
+ - !ruby/object:Gem::Dependency
70
+ name: rcov
71
+ requirement: &70221722563420 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70221722563420
80
+ - !ruby/object:Gem::Dependency
81
+ name: mocha
82
+ requirement: &70221722562940 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: 0.10.0
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *70221722562940
91
+ - !ruby/object:Gem::Dependency
92
+ name: fakeweb
93
+ requirement: &70221722562460 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: 1.2.8
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: *70221722562460
102
+ description: ! 'A ruby wrapper for version 3 of the bit.ly API
103
+
104
+ Supports Login/ApiKey & OAuth authentication
105
+
106
+ '
107
+ email: jonathon.scott.storer@gmail.com
108
+ executables: []
109
+ extensions: []
110
+ extra_rdoc_files:
111
+ - LICENSE
112
+ - README.md
113
+ - README.rdoc
114
+ files:
115
+ - History.txt
116
+ - LICENSE
117
+ - README.md
118
+ - README.rdoc
119
+ - Rakefile
120
+ - VERSION
121
+ - bitlyr.gemspec
122
+ - lib/bitlyr.rb
123
+ - lib/bitlyr/client.rb
124
+ - lib/bitlyr/country.rb
125
+ - lib/bitlyr/day.rb
126
+ - lib/bitlyr/error.rb
127
+ - lib/bitlyr/lib/core_ext/hash.rb
128
+ - lib/bitlyr/lib/core_ext/string.rb
129
+ - lib/bitlyr/missing_url.rb
130
+ - lib/bitlyr/realtime_link.rb
131
+ - lib/bitlyr/referrer.rb
132
+ - lib/bitlyr/response.rb
133
+ - lib/bitlyr/strategy/access_token.rb
134
+ - lib/bitlyr/strategy/api_key.rb
135
+ - lib/bitlyr/strategy/base.rb
136
+ - lib/bitlyr/strategy/oauth.rb
137
+ - lib/bitlyr/url.rb
138
+ - lib/bitlyr/user.rb
139
+ - test/fixtures/9uX1TE.json
140
+ - test/fixtures/9uX1TEclicks.json
141
+ - test/fixtures/9uX1TEclicks2.json
142
+ - test/fixtures/9uX1TEinfo.json
143
+ - test/fixtures/9uX1TEinfo2.json
144
+ - test/fixtures/auth_fail.json
145
+ - test/fixtures/auth_success.json
146
+ - test/fixtures/betaworks.json
147
+ - test/fixtures/betaworks2.json
148
+ - test/fixtures/betaworks_jmp.json
149
+ - test/fixtures/betaworks_other_user.json
150
+ - test/fixtures/bitly9uX1TE.json
151
+ - test/fixtures/bitly_pro_domain.json
152
+ - test/fixtures/clicks_by_day.json
153
+ - test/fixtures/clicks_by_day1.json
154
+ - test/fixtures/clicks_by_day2.json
155
+ - test/fixtures/clicks_by_minute1_url.json
156
+ - test/fixtures/clicks_by_minute2_url.json
157
+ - test/fixtures/clicks_by_minute_hash.json
158
+ - test/fixtures/clicks_by_minute_hashes.json
159
+ - test/fixtures/country_hash.json
160
+ - test/fixtures/country_hash2.json
161
+ - test/fixtures/country_url.json
162
+ - test/fixtures/failure.json
163
+ - test/fixtures/invalid_bitly_pro_domain.json
164
+ - test/fixtures/invalid_credentials.json
165
+ - test/fixtures/invalid_domain.json
166
+ - test/fixtures/invalid_user.json
167
+ - test/fixtures/invalid_x_api_key.json
168
+ - test/fixtures/lookup_multiple_url.json
169
+ - test/fixtures/lookup_not_real_url.json
170
+ - test/fixtures/lookup_single_url.json
171
+ - test/fixtures/missing_hash.json
172
+ - test/fixtures/multiple_info.json
173
+ - test/fixtures/multiple_url_click.json
174
+ - test/fixtures/multiple_urls.json
175
+ - test/fixtures/not_bitly_pro_domain.json
176
+ - test/fixtures/not_found_info.json
177
+ - test/fixtures/referrer_hash.json
178
+ - test/fixtures/referrer_hash2.json
179
+ - test/fixtures/referrer_url.json
180
+ - test/fixtures/success.json
181
+ - test/fixtures/url_info.json
182
+ - test/fixtures/user_clicks.json
183
+ - test/fixtures/user_countries.json
184
+ - test/fixtures/user_realtime_links.json
185
+ - test/fixtures/user_referrers.json
186
+ - test/fixtures/valid_user.json
187
+ - test/integration/strategy/test_api_key.rb
188
+ - test/integration/strategy/test_oauth.rb
189
+ - test/integration/test_client.rb
190
+ - test/integration/test_user.rb
191
+ - test/test_helper.rb
192
+ - test/unit/core_ext/test_hash.rb
193
+ - test/unit/core_ext/test_string.rb
194
+ - test/unit/strategy/test_access_token.rb
195
+ - test/unit/strategy/test_api_key.rb
196
+ - test/unit/strategy/test_base.rb
197
+ - test/unit/strategy/test_oauth.rb
198
+ - test/unit/test_bitly.rb
199
+ - test/unit/test_client.rb
200
+ - test/unit/test_country.rb
201
+ - test/unit/test_day.rb
202
+ - test/unit/test_error.rb
203
+ - test/unit/test_missing.rb
204
+ - test/unit/test_realtime_link.rb
205
+ - test/unit/test_referrer.rb
206
+ - test/unit/test_response.rb
207
+ - test/unit/test_url.rb
208
+ - test/unit/test_user.rb
209
+ homepage: http://github.com/jonstorer/bitlyr
210
+ licenses: []
211
+ post_install_message:
212
+ rdoc_options: []
213
+ require_paths:
214
+ - lib
215
+ required_ruby_version: !ruby/object:Gem::Requirement
216
+ none: false
217
+ requirements:
218
+ - - ! '>='
219
+ - !ruby/object:Gem::Version
220
+ version: '0'
221
+ required_rubygems_version: !ruby/object:Gem::Requirement
222
+ none: false
223
+ requirements:
224
+ - - ! '>='
225
+ - !ruby/object:Gem::Version
226
+ version: '0'
227
+ requirements: []
228
+ rubyforge_project:
229
+ rubygems_version: 1.8.10
230
+ signing_key:
231
+ specification_version: 3
232
+ summary: A ruby wrapper for the bit.ly API
233
+ test_files: []