bitly 1.1.2 → 2.0.0.beta.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.
- checksums.yaml +5 -5
- data/.gitignore +36 -3
- data/.rspec +3 -0
- data/.travis.yml +5 -2
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +5 -2
- data/History.txt +18 -1
- data/LICENSE.md +1 -1
- data/README.md +151 -58
- data/Rakefile +4 -9
- data/bin/console +14 -0
- data/bin/oauth +10 -0
- data/bin/setup +8 -0
- data/bitly.gemspec +24 -29
- data/config/env.yml.example +5 -0
- data/docs/authentication.md +51 -0
- data/docs/bitlinks.md +2 -0
- data/docs/branded_short_domains.md +20 -0
- data/docs/groups.md +80 -0
- data/docs/oauth_apps.md +20 -0
- data/docs/organizations.md +74 -0
- data/docs/premium_apis.md +0 -0
- data/docs/users.md +1 -0
- data/lib/bitly.rb +6 -7
- data/lib/bitly/api.rb +16 -0
- data/lib/bitly/api/base.rb +22 -0
- data/lib/bitly/api/bitlink.rb +341 -0
- data/lib/bitly/api/bitlink/clicks_summary.rb +35 -0
- data/lib/bitly/api/bitlink/deeplink.rb +29 -0
- data/lib/bitly/api/bitlink/link_click.rb +74 -0
- data/lib/bitly/api/bitlink/paginated_list.rb +51 -0
- data/lib/bitly/api/bsd.rb +24 -0
- data/lib/bitly/api/click_metric.rb +185 -0
- data/lib/bitly/api/client.rb +588 -0
- data/lib/bitly/api/group.rb +232 -0
- data/lib/bitly/api/group/preferences.rb +73 -0
- data/lib/bitly/api/list.rb +22 -0
- data/lib/bitly/api/oauth_app.rb +26 -0
- data/lib/bitly/api/organization.rb +104 -0
- data/lib/bitly/api/shorten_counts.rb +61 -0
- data/lib/bitly/api/user.rb +107 -0
- data/lib/bitly/error.rb +33 -0
- data/lib/bitly/http.rb +6 -0
- data/lib/bitly/http/adapters/net_http.rb +27 -0
- data/lib/bitly/http/client.rb +33 -0
- data/lib/bitly/http/request.rb +116 -0
- data/lib/bitly/http/response.rb +65 -0
- data/lib/bitly/oauth.rb +109 -0
- data/lib/bitly/version.rb +3 -1
- metadata +88 -108
- data/Manifest +0 -37
- data/lib/bitly/url.rb +0 -103
- data/lib/bitly/utils.rb +0 -57
- data/lib/bitly/v3.rb +0 -14
- data/lib/bitly/v3/bitly.rb +0 -7
- data/lib/bitly/v3/country.rb +0 -13
- data/lib/bitly/v3/day.rb +0 -13
- data/lib/bitly/v3/missing_url.rb +0 -15
- data/lib/bitly/v3/oauth.rb +0 -41
- data/lib/bitly/v3/realtime_link.rb +0 -18
- data/lib/bitly/v3/referrer.rb +0 -13
- data/lib/bitly/v3/url.rb +0 -154
- data/test/bitly/test_client.rb +0 -266
- data/test/bitly/test_config.rb +0 -28
- data/test/bitly/test_url.rb +0 -167
- data/test/bitly/test_utils.rb +0 -79
- data/test/fixtures/cnn.json +0 -1
- data/test/fixtures/cnn_and_google.json +0 -1
- data/test/fixtures/expand_cnn.json +0 -1
- data/test/fixtures/expand_cnn_and_google.json +0 -1
- data/test/fixtures/google_and_cnn_info.json +0 -1
- data/test/fixtures/google_info.json +0 -1
- data/test/fixtures/google_stats.json +0 -1
- data/test/fixtures/shorten_error.json +0 -1
- data/test/test_helper.rb +0 -39
data/test/bitly/test_client.rb
DELETED
@@ -1,266 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '..', 'test_helper.rb')
|
2
|
-
|
3
|
-
class TestClient < Minitest::Test
|
4
|
-
context "bitly module" do
|
5
|
-
setup do
|
6
|
-
Bitly.api_version = nil
|
7
|
-
end
|
8
|
-
|
9
|
-
should "create a new bitly client" do
|
10
|
-
b = Bitly.new(login, api_key)
|
11
|
-
assert_equal Bitly::Client, b.class
|
12
|
-
end
|
13
|
-
|
14
|
-
should "create a new bitly client with generic OAuth2 access token" do
|
15
|
-
b = Bitly.new(access_token)
|
16
|
-
assert_equal Bitly::Client, b.class
|
17
|
-
end
|
18
|
-
|
19
|
-
should "create a new bitly client and configure with a block" do
|
20
|
-
Bitly.configure do |config|
|
21
|
-
config.api_key = api_key
|
22
|
-
config.login = login
|
23
|
-
end
|
24
|
-
b = Bitly.client
|
25
|
-
assert_kind_of Bitly::Client, b
|
26
|
-
assert_equal api_key, b.api_key
|
27
|
-
assert_equal login, b.login
|
28
|
-
end
|
29
|
-
|
30
|
-
should "create a proper OAuth2 authorization url" do
|
31
|
-
client = Bitly::V3::OAuth.new('CLIENT_ID', 'CLIENT_SECRET')
|
32
|
-
url = client.authorize_url('http://www.example.com/oauth_callback')
|
33
|
-
assert_equal "https://bitly.com/oauth/authorize?client_id=CLIENT_ID&redirect_uri=http%3A%2F%2Fwww.example.com%2Foauth_callback&response_type=code", url
|
34
|
-
end
|
35
|
-
|
36
|
-
should "create a proper OAuth2 authorization url with a state parameter" do
|
37
|
-
client = Bitly::V3::OAuth.new('CLIENT_ID', 'CLIENT_SECRET')
|
38
|
-
url = client.authorize_url('http://www.example.com/oauth_callback', 'some_state')
|
39
|
-
assert_equal "https://bitly.com/oauth/authorize?client_id=CLIENT_ID&redirect_uri=http%3A%2F%2Fwww.example.com%2Foauth_callback&response_type=code&state=some_state", url
|
40
|
-
end
|
41
|
-
|
42
|
-
context "setting api versions" do
|
43
|
-
teardown do
|
44
|
-
Bitly.api_version = nil
|
45
|
-
end
|
46
|
-
|
47
|
-
should "set the api version to 2" do
|
48
|
-
Bitly.use_api_version_2
|
49
|
-
assert_equal Bitly.api_version, 2
|
50
|
-
assert_kind_of Bitly::Client, Bitly.client
|
51
|
-
end
|
52
|
-
|
53
|
-
should "set the api version to 3" do
|
54
|
-
Bitly.use_api_version_3
|
55
|
-
assert_equal Bitly.api_version, 3
|
56
|
-
assert_kind_of Bitly::V3::Client, Bitly.client
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
context "using the bitly client" do
|
61
|
-
setup do
|
62
|
-
Bitly.use_api_version_2
|
63
|
-
@bitly = Bitly.new(login, api_key)
|
64
|
-
end
|
65
|
-
|
66
|
-
context "shortening" do
|
67
|
-
context "a single link" do
|
68
|
-
setup do
|
69
|
-
stub_get(/^https:\/\/api-ssl\.bitly\.com\/shorten\?.*longUrl=.*cnn.com.*$/,"cnn.json")
|
70
|
-
@url = @bitly.shorten('http://cnn.com')
|
71
|
-
end
|
72
|
-
should "return a Bitly::Url" do
|
73
|
-
assert_kind_of Bitly::Url, @url
|
74
|
-
end
|
75
|
-
should "return a short bitly url" do
|
76
|
-
assert_equal "http://bit.ly/15DlK", @url.short_url
|
77
|
-
assert_equal "http://bit.ly/15DlK", @url.bitly_url
|
78
|
-
end
|
79
|
-
should "return a short jmp url" do
|
80
|
-
assert_equal "http://j.mp/15DlK", @url.jmp_url
|
81
|
-
end
|
82
|
-
should "save the long url" do
|
83
|
-
assert_equal "http://cnn.com", @url.long_url
|
84
|
-
end
|
85
|
-
end
|
86
|
-
context "multiple links" do
|
87
|
-
setup do
|
88
|
-
stub_get(/^https:\/\/api-ssl\.bitly\.com\/shorten\?.*longUrl=.*longUrl=.*$/,"cnn_and_google.json")
|
89
|
-
@urls = @bitly.shorten(['http://cnn.com', 'http://google.com'])
|
90
|
-
end
|
91
|
-
should "return an array of Bitly::Urls" do
|
92
|
-
assert_kind_of Array, @urls
|
93
|
-
assert_kind_of Bitly::Url, @urls[0]
|
94
|
-
end
|
95
|
-
should "shorten the urls in order" do
|
96
|
-
assert_equal "http://bit.ly/15DlK", @urls[0].short_url
|
97
|
-
assert_equal "http://bit.ly/11etr", @urls[1].short_url
|
98
|
-
end
|
99
|
-
should "save the long urls" do
|
100
|
-
assert_equal "http://cnn.com", @urls[0].long_url
|
101
|
-
assert_equal "http://google.com", @urls[1].long_url
|
102
|
-
end
|
103
|
-
end
|
104
|
-
context "no links" do
|
105
|
-
should "raise an ArgumentError" do
|
106
|
-
assert_raises ArgumentError do
|
107
|
-
@bitly.shorten
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
context "expanding" do
|
113
|
-
context "a hash" do
|
114
|
-
setup do
|
115
|
-
stub_get(/^https:\/\/api-ssl\.bitly\.com\/expand\?.*hash=31IqMl.*$/,"expand_cnn.json")
|
116
|
-
@url = @bitly.expand("31IqMl")
|
117
|
-
end
|
118
|
-
should "return a Bitly::Url" do
|
119
|
-
assert_kind_of Bitly::Url, @url
|
120
|
-
end
|
121
|
-
should "return the expanded url" do
|
122
|
-
assert_equal "http://cnn.com/", @url.long_url
|
123
|
-
end
|
124
|
-
should "save the hash" do
|
125
|
-
assert_equal "31IqMl", @url.hash
|
126
|
-
end
|
127
|
-
should "save the short url" do
|
128
|
-
assert_equal "http://bit.ly/31IqMl", @url.short_url
|
129
|
-
end
|
130
|
-
end
|
131
|
-
context "a short bitly url" do
|
132
|
-
setup do
|
133
|
-
stub_get(/^https:\/\/api-ssl\.bitly\.com\/expand\?.*hash=31IqMl.*$/,"expand_cnn.json")
|
134
|
-
@url = @bitly.expand("http://bit.ly/31IqMl")
|
135
|
-
end
|
136
|
-
should "return a Bitly::Url" do
|
137
|
-
assert_kind_of Bitly::Url, @url
|
138
|
-
end
|
139
|
-
should "return the expanded url" do
|
140
|
-
assert_equal "http://cnn.com/", @url.long_url
|
141
|
-
end
|
142
|
-
should "save the hash" do
|
143
|
-
assert_equal "31IqMl", @url.hash
|
144
|
-
end
|
145
|
-
should "save the bitly url" do
|
146
|
-
assert_equal "http://bit.ly/31IqMl", @url.bitly_url
|
147
|
-
end
|
148
|
-
should "save a jmp url" do
|
149
|
-
assert_equal "http://j.mp/31IqMl", @url.jmp_url
|
150
|
-
end
|
151
|
-
end
|
152
|
-
context "a short jmp url" do
|
153
|
-
setup do
|
154
|
-
stub_get(/^https:\/\/api-ssl\.bitly\.com\/expand\?.*hash=31IqMl.*$/,"expand_cnn.json")
|
155
|
-
@url = @bitly.expand("http://j.mp/31IqMl")
|
156
|
-
end
|
157
|
-
should "return a Bitly::Url" do
|
158
|
-
assert_kind_of Bitly::Url, @url
|
159
|
-
end
|
160
|
-
should "return the expanded url" do
|
161
|
-
assert_equal "http://cnn.com/", @url.long_url
|
162
|
-
end
|
163
|
-
should "save the hash" do
|
164
|
-
assert_equal "31IqMl", @url.hash
|
165
|
-
end
|
166
|
-
should "save the bitly url" do
|
167
|
-
assert_equal "http://bit.ly/31IqMl", @url.bitly_url
|
168
|
-
end
|
169
|
-
should "save a jmp url" do
|
170
|
-
assert_equal "http://j.mp/31IqMl", @url.jmp_url
|
171
|
-
end
|
172
|
-
end
|
173
|
-
context "multiple hashes" do
|
174
|
-
setup do
|
175
|
-
stub_get(/^https:\/\/api-ssl\.bitly\.com\/expand\?.*hash=15DlK.*3j4ir4.*$/,"expand_cnn_and_google.json")
|
176
|
-
@urls = @bitly.expand(["15DlK","3j4ir4"])
|
177
|
-
end
|
178
|
-
should "return an array of Bitly::Urls" do
|
179
|
-
assert_kind_of Array, @urls
|
180
|
-
assert_kind_of Bitly::Url, @urls[0]
|
181
|
-
assert_kind_of Bitly::Url, @urls[1]
|
182
|
-
end
|
183
|
-
should "expand the hashes in order" do
|
184
|
-
assert_equal "http://cnn.com/", @urls[0].long_url
|
185
|
-
assert_equal "http://google.com/", @urls[1].long_url
|
186
|
-
end
|
187
|
-
should "save the hash to each url" do
|
188
|
-
assert_equal "15DlK", @urls[0].hash
|
189
|
-
assert_equal "3j4ir4", @urls[1].hash
|
190
|
-
end
|
191
|
-
end
|
192
|
-
end
|
193
|
-
context "to get info on" do
|
194
|
-
context "a single link" do
|
195
|
-
setup do
|
196
|
-
stub_get(/^https:\/\/api-ssl\.bitly\.com\/info\?.*hash=3j4ir4.*$/,"google_info.json")
|
197
|
-
@url = @bitly.info('http://bit.ly/3j4ir4')
|
198
|
-
end
|
199
|
-
should "return a Bitly::Url" do
|
200
|
-
assert_kind_of Bitly::Url, @url
|
201
|
-
end
|
202
|
-
should "return an info object with the url" do
|
203
|
-
assert !@url.info.nil?
|
204
|
-
end
|
205
|
-
end
|
206
|
-
context "a single hash" do
|
207
|
-
setup do
|
208
|
-
stub_get(/^https:\/\/api-ssl\.bitly\.com\/info\?.*hash=3j4ir4.*$/,"google_info.json")
|
209
|
-
@url = @bitly.info('3j4ir4')
|
210
|
-
end
|
211
|
-
should "return a Bitly::Url" do
|
212
|
-
assert_kind_of Bitly::Url, @url
|
213
|
-
end
|
214
|
-
should "return an info object with the url" do
|
215
|
-
assert !@url.info.nil?
|
216
|
-
end
|
217
|
-
end
|
218
|
-
context "a list of hashes" do
|
219
|
-
setup do
|
220
|
-
stub_get(/^https:\/\/api-ssl\.bitly\.com\/info\?.*hash=3j4ir4.*31IqMl.*$/,"google_and_cnn_info.json")
|
221
|
-
@urls = @bitly.info(['3j4ir4','31IqMl'])
|
222
|
-
end
|
223
|
-
should "return a Bitly::Url" do
|
224
|
-
assert_kind_of Array, @urls
|
225
|
-
end
|
226
|
-
should "return an info object with the url" do
|
227
|
-
assert !@urls[0].info.nil?
|
228
|
-
assert !@urls[1].info.nil?
|
229
|
-
end
|
230
|
-
end
|
231
|
-
end
|
232
|
-
context "to get stats on" do
|
233
|
-
context "a single link" do
|
234
|
-
setup do
|
235
|
-
stub_get(/^https:\/\/api-ssl\.bitly\.com\/stats\?.*hash=3j4ir4.*$/,"google_stats.json")
|
236
|
-
@url = @bitly.stats('http://bit.ly/3j4ir4')
|
237
|
-
end
|
238
|
-
should "return a Bitly::Url" do
|
239
|
-
assert_kind_of Bitly::Url, @url
|
240
|
-
end
|
241
|
-
should "return an stats object" do
|
242
|
-
assert !@url.stats.nil?
|
243
|
-
end
|
244
|
-
end
|
245
|
-
context "a single hash" do
|
246
|
-
setup do
|
247
|
-
stub_get(/^https:\/\/api-ssl\.bitly\.com\/stats\?.*hash=3j4ir4.*$/,"google_stats.json")
|
248
|
-
@url = @bitly.stats('3j4ir4')
|
249
|
-
end
|
250
|
-
should "return a Bitly::Url" do
|
251
|
-
assert_kind_of Bitly::Url, @url
|
252
|
-
end
|
253
|
-
should "return an stats object" do
|
254
|
-
assert !@url.stats.nil?
|
255
|
-
end
|
256
|
-
end
|
257
|
-
context "a list of hashes" do
|
258
|
-
should "return an argument error" do
|
259
|
-
assert_raises ArgumentError do
|
260
|
-
@bitly.stats(['3j4ir4','31IqMl'])
|
261
|
-
end
|
262
|
-
end
|
263
|
-
end
|
264
|
-
end
|
265
|
-
end
|
266
|
-
end
|
data/test/bitly/test_config.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '..', 'test_helper.rb')
|
2
|
-
|
3
|
-
class TestConfig < Minitest::Test
|
4
|
-
context "bitly module" do
|
5
|
-
should "create a new bitly v3 client through initializer" do
|
6
|
-
# configure
|
7
|
-
Bitly.configure do |config|
|
8
|
-
config.api_version = 3
|
9
|
-
config.login = login
|
10
|
-
config.api_key = api_key
|
11
|
-
config.timeout = 10
|
12
|
-
end
|
13
|
-
b = Bitly.client
|
14
|
-
assert_equal Bitly::V3::Client, b.class
|
15
|
-
end
|
16
|
-
|
17
|
-
should "create a new bitly v2 client through initializer" do
|
18
|
-
# configure
|
19
|
-
Bitly.configure do |config|
|
20
|
-
config.api_version = 2
|
21
|
-
config.login = login
|
22
|
-
config.api_key = api_key
|
23
|
-
end
|
24
|
-
b = Bitly.client
|
25
|
-
assert_equal Bitly::Client, b.class
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
data/test/bitly/test_url.rb
DELETED
@@ -1,167 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '..', 'test_helper.rb')
|
2
|
-
|
3
|
-
class TestUrl < Minitest::Test
|
4
|
-
context "a new Bitly::Url" do
|
5
|
-
should "require a login and api_key" do
|
6
|
-
assert_raises ArgumentError do Bitly::Url.new end
|
7
|
-
assert_raises ArgumentError do Bitly::Url.new(login) end
|
8
|
-
assert_raises ArgumentError do Bitly::Url.new(nil, api_key) end
|
9
|
-
end
|
10
|
-
context "shortening" do
|
11
|
-
context "with a long url" do
|
12
|
-
setup do
|
13
|
-
stub_get(/^https:\/\/api-ssl\.bitly\.com\/shorten\?.*longUrl=.*cnn.com.*$/,"cnn.json")
|
14
|
-
@url = Bitly::Url.new(login, api_key, :long_url => 'http://cnn.com/')
|
15
|
-
end
|
16
|
-
should "return a short url" do
|
17
|
-
assert_equal "http://bit.ly/15DlK", @url.shorten
|
18
|
-
end
|
19
|
-
should "create bitly and jmp urls" do
|
20
|
-
@url.shorten
|
21
|
-
assert_equal "http://bit.ly/15DlK", @url.bitly_url
|
22
|
-
assert_equal "http://j.mp/15DlK", @url.jmp_url
|
23
|
-
end
|
24
|
-
end
|
25
|
-
context "with no long url" do
|
26
|
-
setup do
|
27
|
-
@url = Bitly::Url.new(login, api_key)
|
28
|
-
end
|
29
|
-
should "raise an error" do
|
30
|
-
assert_raises ArgumentError do
|
31
|
-
@url.shorten
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
context "with a short url already" do
|
36
|
-
setup do
|
37
|
-
@url = Bitly::Url.new(login, api_key, :short_url => 'http://bit.ly/31IqMl')
|
38
|
-
flexmock(@url).should_receive(:create_url).never
|
39
|
-
end
|
40
|
-
should "not need to call the api" do
|
41
|
-
assert_equal "http://bit.ly/31IqMl", @url.shorten
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
context "expanding" do
|
46
|
-
context "with a hash" do
|
47
|
-
setup do
|
48
|
-
stub_get(/^https:\/\/api-ssl\.bitly\.com\/expand\?.*hash=31IqMl.*$/,"expand_cnn.json")
|
49
|
-
@url = Bitly::Url.new(login, api_key, :hash => '31IqMl')
|
50
|
-
end
|
51
|
-
should "return an expanded url" do
|
52
|
-
assert_equal "http://cnn.com/", @url.expand
|
53
|
-
end
|
54
|
-
end
|
55
|
-
context "with a short url" do
|
56
|
-
setup do
|
57
|
-
stub_get(/^https:\/\/api-ssl\.bitly\.com\/expand\?.*hash=31IqMl.*$/,"expand_cnn.json")
|
58
|
-
@url = Bitly::Url.new(login, api_key, :short_url => 'http://bit.ly/31IqMl')
|
59
|
-
end
|
60
|
-
should "return an expanded url" do
|
61
|
-
assert_equal "http://cnn.com/", @url.expand
|
62
|
-
end
|
63
|
-
end
|
64
|
-
context "with no short url or hash" do
|
65
|
-
setup do
|
66
|
-
@url = Bitly::Url.new(login, api_key)
|
67
|
-
end
|
68
|
-
should "raise an error" do
|
69
|
-
assert_raises ArgumentError do
|
70
|
-
@url.expand
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
context "with a long url already" do
|
75
|
-
setup do
|
76
|
-
@url = Bitly::Url.new(login, api_key, :long_url => 'http://google.com')
|
77
|
-
flexmock(@url).should_receive(:create_url).never
|
78
|
-
end
|
79
|
-
should "not need to call the api" do
|
80
|
-
assert_equal "http://google.com", @url.expand
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
context "info" do
|
85
|
-
context "with a hash" do
|
86
|
-
setup do
|
87
|
-
stub_get(/^https:\/\/api-ssl\.bitly\.com\/info\?.*hash=3j4ir4.*$/,"google_info.json")
|
88
|
-
@url = Bitly::Url.new(login, api_key, :hash => '3j4ir4')
|
89
|
-
end
|
90
|
-
should "return info" do
|
91
|
-
assert_equal "Google", @url.info['htmlTitle']
|
92
|
-
end
|
93
|
-
end
|
94
|
-
context "with a short url" do
|
95
|
-
setup do
|
96
|
-
stub_get(/^https:\/\/api-ssl\.bitly\.com\/info\?.*hash=3j4ir4.*$/,"google_info.json")
|
97
|
-
@url = Bitly::Url.new(login, api_key, :short_url => 'http://bit.ly/3j4ir4')
|
98
|
-
end
|
99
|
-
should "return an expanded url" do
|
100
|
-
assert_equal "Google", @url.info['htmlTitle']
|
101
|
-
end
|
102
|
-
end
|
103
|
-
context "without a short url or hash" do
|
104
|
-
setup do
|
105
|
-
@url = Bitly::Url.new(login, api_key, :long_url => 'http://google.com')
|
106
|
-
end
|
107
|
-
should "raise an error" do
|
108
|
-
assert_raises ArgumentError do
|
109
|
-
@url.info
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
context "with info already" do
|
114
|
-
setup do
|
115
|
-
stub_get(/^https:\/\/api-ssl\.bitly\.com\/info\?.*hash=3j4ir4.*$/,"google_info.json")
|
116
|
-
@url = Bitly::Url.new(login, api_key, :short_url => 'http://bit.ly/3j4ir4')
|
117
|
-
@url.info
|
118
|
-
end
|
119
|
-
should "not call the api twice" do
|
120
|
-
flexmock(@url).should_receive(:create_url).never
|
121
|
-
@url.info
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
context "stats" do
|
126
|
-
context "with a hash" do
|
127
|
-
setup do
|
128
|
-
stub_get(/^https:\/\/api-ssl\.bitly\.com\/stats\?.*hash=3j4ir4.*$/,"google_stats.json")
|
129
|
-
@url = Bitly::Url.new(login, api_key, :hash => '3j4ir4')
|
130
|
-
end
|
131
|
-
should "return info" do
|
132
|
-
assert_equal 2644, @url.stats['clicks']
|
133
|
-
end
|
134
|
-
end
|
135
|
-
context "with a short url" do
|
136
|
-
setup do
|
137
|
-
stub_get(/^https:\/\/api-ssl\.bitly\.com\/stats\?.*hash=3j4ir4.*$/,"google_stats.json")
|
138
|
-
@url = Bitly::Url.new(login, api_key, :short_url => 'http://bit.ly/3j4ir4')
|
139
|
-
end
|
140
|
-
should "return an expanded url" do
|
141
|
-
assert_equal 2644, @url.stats['clicks']
|
142
|
-
end
|
143
|
-
end
|
144
|
-
context "without a short url or hash" do
|
145
|
-
setup do
|
146
|
-
@url = Bitly::Url.new(login, api_key, :long_url => 'http://google.com')
|
147
|
-
end
|
148
|
-
should "raise an error" do
|
149
|
-
assert_raises ArgumentError do
|
150
|
-
@url.stats
|
151
|
-
end
|
152
|
-
end
|
153
|
-
end
|
154
|
-
context "with info already" do
|
155
|
-
setup do
|
156
|
-
stub_get(/^https:\/\/api-ssl\.bitly\.com\/stats\?.*hash=3j4ir4.*$/,"google_stats.json")
|
157
|
-
@url = Bitly::Url.new(login, api_key, :short_url => 'http://bit.ly/3j4ir4')
|
158
|
-
@url.stats
|
159
|
-
end
|
160
|
-
should "not call the api twice" do
|
161
|
-
flexmock(@url).should_receive(:create_url).never
|
162
|
-
@url.stats
|
163
|
-
end
|
164
|
-
end
|
165
|
-
end
|
166
|
-
end
|
167
|
-
end
|