bitly 0.10.3 → 0.10.4
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.
- data/History.txt +13 -0
- data/Manifest +1 -0
- data/README.md +38 -23
- data/Rakefile +2 -1
- data/bitly.gemspec +6 -3
- data/lib/bitly/v3/oauth.rb +4 -2
- data/lib/bitly/version.rb +1 -1
- data/test/bitly/test_client.rb +12 -0
- metadata +19 -3
data/History.txt
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
=== 0.10.4 / 2015-01-08
|
2
|
+
|
3
|
+
* 1 minor update
|
4
|
+
|
5
|
+
* You can now pass a state parameter to the OAuth authorize url.
|
6
|
+
|
7
|
+
=== 0.10.3 / 2014-09-22
|
8
|
+
|
9
|
+
* 1 minor update
|
10
|
+
|
11
|
+
* Due to a tooling mishap, the previous gem version didn't update the OAuth2
|
12
|
+
gem versions. This has been updated now.
|
13
|
+
|
1
14
|
=== 0.10.2 / 2014-09-20
|
2
15
|
|
3
16
|
* 1 minor update
|
data/Manifest
CHANGED
data/README.md
CHANGED
@@ -12,7 +12,9 @@ Bitly recently released their version 3 API. From this 0.5.0 release, the gem wi
|
|
12
12
|
|
13
13
|
To move to using the version 3 API, call:
|
14
14
|
|
15
|
-
|
15
|
+
```ruby
|
16
|
+
Bitly.use_api_version_3
|
17
|
+
```
|
16
18
|
|
17
19
|
Then, when you call ``Bitly.new(username, api_key)`` you will get a ``Bitly::V3::Client`` instead, which provides the version 3 api calls (``shorten``, ``expand``, ``clicks``, ``validate`` and ``bitly_pro_domain``). See [http://dev.bitly.com](http://dev.bitly.com) for details.
|
18
20
|
|
@@ -30,50 +32,63 @@ Eventually, this will become the default version used and finally, the V3 module
|
|
30
32
|
|
31
33
|
Create a Bitly client using your username and api key as follows:
|
32
34
|
|
33
|
-
|
35
|
+
```ruby
|
36
|
+
bitly = Bitly.new(username, api_key)
|
37
|
+
```
|
34
38
|
|
35
39
|
You can then use that client to shorten or expand urls or return more information or statistics as so:
|
36
40
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
41
|
+
```ruby
|
42
|
+
bitly.shorten('http://www.google.com')
|
43
|
+
bitly.shorten('http://www.google.com', :history => 1) # adds the url to the api user's history
|
44
|
+
bitly.expand('wQaT')
|
45
|
+
bitly.info('http://bit.ly/wQaT')
|
46
|
+
bitly.stats('http://bit.ly/wQaT')
|
47
|
+
```
|
42
48
|
|
43
49
|
Each can be used in all the methods described in the API docs, the shorten function, for example, takes a url or an array of urls.
|
44
50
|
|
45
51
|
All four functions return a ``Bitly::Url`` object (or an array of ``Bitly::Url`` objects if you supplied an array as the input). You can then get all the information required from that object.
|
46
52
|
|
47
|
-
|
53
|
+
```ruby
|
54
|
+
u = bitly.shorten('http://www.google.com') #=> Bitly::Url
|
48
55
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
56
|
+
u.long_url #=> "http://www.google.com"
|
57
|
+
u.short_url #=> "http://bit.ly/Ywd1"
|
58
|
+
u.bitly_url #=> "http://bit.ly/Ywd1"
|
59
|
+
u.jmp_url #=> "http://j.mp/Ywd1"
|
60
|
+
u.user_hash #=> "Ywd1"
|
61
|
+
u.hash #=> "2V6CFi"
|
62
|
+
u.info #=> a ruby hash of the JSON returned from the API
|
63
|
+
u.stats #=> a ruby hash of the JSON returned from the API
|
57
64
|
|
58
|
-
|
65
|
+
bitly.shorten('http://www.google.com', 'keyword')
|
66
|
+
```
|
59
67
|
|
60
68
|
### Version 3 API
|
61
69
|
|
62
70
|
Please see the Bit.ly API documentation [http://api.bit.ly](http://api.bit.ly) for details on the V3 API.
|
63
71
|
|
72
|
+
Get your access token here: [https://bitly.com/a/oauth_apps](https://bitly.com/a/oauth_apps).
|
73
|
+
|
64
74
|
### Configure bitly through initializer
|
65
75
|
|
66
76
|
If you want to configure bitly through an initializer (e.g. `config/initializers/bitly.rb`), do the following:
|
67
77
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
78
|
+
```ruby
|
79
|
+
Bitly.use_api_version_3
|
80
|
+
|
81
|
+
Bitly.configure do |config|
|
82
|
+
config.api_version = 3
|
83
|
+
config.access_token = "API_KEY"
|
84
|
+
end
|
85
|
+
```
|
73
86
|
|
74
87
|
Instead of using `Bitly.new(username, api_key)` to get the client, use `Bitly.client`:
|
75
88
|
|
76
|
-
|
89
|
+
```ruby
|
90
|
+
Bitly.client.shorten('http://www.google.com')
|
91
|
+
```
|
77
92
|
|
78
93
|
## LICENSE:
|
79
94
|
|
data/Rakefile
CHANGED
data/bitly.gemspec
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "bitly"
|
5
|
-
s.version = "0.10.
|
5
|
+
s.version = "0.10.4"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Phil Nash"]
|
9
|
-
s.date = "
|
9
|
+
s.date = "2015-01-09"
|
10
10
|
s.description = "Use the bit.ly API to shorten or expand URLs"
|
11
11
|
s.email = "philnash@gmail.com"
|
12
12
|
s.extra_rdoc_files = ["README.md", "lib/bitly.rb", "lib/bitly/client.rb", "lib/bitly/config.rb", "lib/bitly/url.rb", "lib/bitly/utils.rb", "lib/bitly/v3.rb", "lib/bitly/v3/bitly.rb", "lib/bitly/v3/client.rb", "lib/bitly/v3/country.rb", "lib/bitly/v3/day.rb", "lib/bitly/v3/missing_url.rb", "lib/bitly/v3/oauth.rb", "lib/bitly/v3/realtime_link.rb", "lib/bitly/v3/referrer.rb", "lib/bitly/v3/url.rb", "lib/bitly/v3/user.rb", "lib/bitly/version.rb"]
|
13
|
-
s.files = ["Gemfile", "History.txt", "Manifest", "README.md", "Rakefile", "lib/bitly.rb", "lib/bitly/client.rb", "lib/bitly/config.rb", "lib/bitly/url.rb", "lib/bitly/utils.rb", "lib/bitly/v3.rb", "lib/bitly/v3/bitly.rb", "lib/bitly/v3/client.rb", "lib/bitly/v3/country.rb", "lib/bitly/v3/day.rb", "lib/bitly/v3/missing_url.rb", "lib/bitly/v3/oauth.rb", "lib/bitly/v3/realtime_link.rb", "lib/bitly/v3/referrer.rb", "lib/bitly/v3/url.rb", "lib/bitly/v3/user.rb", "lib/bitly/version.rb", "test/bitly/test_client.rb", "test/bitly/test_config.rb", "test/bitly/test_url.rb", "test/bitly/test_utils.rb", "test/fixtures/cnn.json", "test/fixtures/cnn_and_google.json", "test/fixtures/expand_cnn.json", "test/fixtures/expand_cnn_and_google.json", "test/fixtures/google_and_cnn_info.json", "test/fixtures/google_info.json", "test/fixtures/google_stats.json", "test/fixtures/shorten_error.json", "test/test_helper.rb"
|
13
|
+
s.files = ["Gemfile", "History.txt", "Manifest", "README.md", "Rakefile", "bitly.gemspec", "lib/bitly.rb", "lib/bitly/client.rb", "lib/bitly/config.rb", "lib/bitly/url.rb", "lib/bitly/utils.rb", "lib/bitly/v3.rb", "lib/bitly/v3/bitly.rb", "lib/bitly/v3/client.rb", "lib/bitly/v3/country.rb", "lib/bitly/v3/day.rb", "lib/bitly/v3/missing_url.rb", "lib/bitly/v3/oauth.rb", "lib/bitly/v3/realtime_link.rb", "lib/bitly/v3/referrer.rb", "lib/bitly/v3/url.rb", "lib/bitly/v3/user.rb", "lib/bitly/version.rb", "test/bitly/test_client.rb", "test/bitly/test_config.rb", "test/bitly/test_url.rb", "test/bitly/test_utils.rb", "test/fixtures/cnn.json", "test/fixtures/cnn_and_google.json", "test/fixtures/expand_cnn.json", "test/fixtures/expand_cnn_and_google.json", "test/fixtures/google_and_cnn_info.json", "test/fixtures/google_info.json", "test/fixtures/google_stats.json", "test/fixtures/shorten_error.json", "test/test_helper.rb"]
|
14
14
|
s.homepage = "http://github.com/philnash/bitly"
|
15
15
|
s.rdoc_options = ["--line-numbers", "--title", "Bitly", "--main", "README.md"]
|
16
16
|
s.require_paths = ["lib"]
|
@@ -31,6 +31,7 @@ Gem::Specification.new do |s|
|
|
31
31
|
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
32
32
|
s.add_development_dependency(%q<flexmock>, [">= 0"])
|
33
33
|
s.add_development_dependency(%q<fakeweb>, [">= 0"])
|
34
|
+
s.add_development_dependency(%q<activesupport>, ["~> 3.2"])
|
34
35
|
else
|
35
36
|
s.add_dependency(%q<multi_json>, ["~> 1.3"])
|
36
37
|
s.add_dependency(%q<httparty>, [">= 0.7.6"])
|
@@ -40,6 +41,7 @@ Gem::Specification.new do |s|
|
|
40
41
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
41
42
|
s.add_dependency(%q<flexmock>, [">= 0"])
|
42
43
|
s.add_dependency(%q<fakeweb>, [">= 0"])
|
44
|
+
s.add_dependency(%q<activesupport>, ["~> 3.2"])
|
43
45
|
end
|
44
46
|
else
|
45
47
|
s.add_dependency(%q<multi_json>, ["~> 1.3"])
|
@@ -50,5 +52,6 @@ Gem::Specification.new do |s|
|
|
50
52
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
51
53
|
s.add_dependency(%q<flexmock>, [">= 0"])
|
52
54
|
s.add_dependency(%q<fakeweb>, [">= 0"])
|
55
|
+
s.add_dependency(%q<activesupport>, ["~> 3.2"])
|
53
56
|
end
|
54
57
|
end
|
data/lib/bitly/v3/oauth.rb
CHANGED
@@ -19,8 +19,10 @@ module Bitly
|
|
19
19
|
|
20
20
|
# Get the url to redirect a user to, pass the url you want the user
|
21
21
|
# to be redirected back to.
|
22
|
-
def authorize_url(redirect_url)
|
23
|
-
|
22
|
+
def authorize_url(redirect_url, state=nil)
|
23
|
+
params = {:redirect_uri => redirect_url}
|
24
|
+
params[:state] = state if state
|
25
|
+
client.auth_code.authorize_url(params).gsub(/api-ssl\./,'')
|
24
26
|
end
|
25
27
|
|
26
28
|
# Get the access token. You must pass the exact same redirect_url passed
|
data/lib/bitly/version.rb
CHANGED
data/test/bitly/test_client.rb
CHANGED
@@ -22,6 +22,18 @@ class TestClient < Test::Unit::TestCase
|
|
22
22
|
assert_equal api_key, b.api_key
|
23
23
|
assert_equal login, b.login
|
24
24
|
end
|
25
|
+
|
26
|
+
should "create a proper OAuth2 authorization url" do
|
27
|
+
client = Bitly::V3::OAuth.new('CLIENT_ID', 'CLIENT_SECRET')
|
28
|
+
url = client.authorize_url('http://www.example.com/oauth_callback')
|
29
|
+
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
|
30
|
+
end
|
31
|
+
|
32
|
+
should "create a proper OAuth2 authorization url with a state parameter" do
|
33
|
+
client = Bitly::V3::OAuth.new('CLIENT_ID', 'CLIENT_SECRET')
|
34
|
+
url = client.authorize_url('http://www.example.com/oauth_callback', 'some_state')
|
35
|
+
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
|
36
|
+
end
|
25
37
|
end
|
26
38
|
context "using the bitly client" do
|
27
39
|
setup do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bitly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.10.
|
4
|
+
version: 0.10.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2015-01-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: multi_json
|
@@ -145,6 +145,22 @@ dependencies:
|
|
145
145
|
- - ! '>='
|
146
146
|
- !ruby/object:Gem::Version
|
147
147
|
version: '0'
|
148
|
+
- !ruby/object:Gem::Dependency
|
149
|
+
name: activesupport
|
150
|
+
requirement: !ruby/object:Gem::Requirement
|
151
|
+
none: false
|
152
|
+
requirements:
|
153
|
+
- - ~>
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
version: '3.2'
|
156
|
+
type: :development
|
157
|
+
prerelease: false
|
158
|
+
version_requirements: !ruby/object:Gem::Requirement
|
159
|
+
none: false
|
160
|
+
requirements:
|
161
|
+
- - ~>
|
162
|
+
- !ruby/object:Gem::Version
|
163
|
+
version: '3.2'
|
148
164
|
description: Use the bit.ly API to shorten or expand URLs
|
149
165
|
email: philnash@gmail.com
|
150
166
|
executables: []
|
@@ -174,6 +190,7 @@ files:
|
|
174
190
|
- Manifest
|
175
191
|
- README.md
|
176
192
|
- Rakefile
|
193
|
+
- bitly.gemspec
|
177
194
|
- lib/bitly.rb
|
178
195
|
- lib/bitly/client.rb
|
179
196
|
- lib/bitly/config.rb
|
@@ -204,7 +221,6 @@ files:
|
|
204
221
|
- test/fixtures/google_stats.json
|
205
222
|
- test/fixtures/shorten_error.json
|
206
223
|
- test/test_helper.rb
|
207
|
-
- bitly.gemspec
|
208
224
|
homepage: http://github.com/philnash/bitly
|
209
225
|
licenses: []
|
210
226
|
post_install_message:
|