bitly 0.8.1 → 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.
- data/Gemfile +3 -0
- data/History.txt +27 -0
- data/Manifest +3 -1
- data/README.md +14 -0
- data/Rakefile +10 -4
- data/bitly.gemspec +23 -8
- data/lib/bitly.rb +3 -4
- data/lib/bitly/client.rb +25 -13
- data/lib/bitly/config.rb +26 -0
- data/lib/bitly/utils.rb +3 -3
- data/lib/bitly/v3/client.rb +17 -3
- data/lib/bitly/v3/url.rb +8 -1
- data/lib/bitly/v3/user.rb +5 -5
- data/lib/bitly/version.rb +2 -2
- data/test/bitly/test_client.rb +13 -2
- data/test/bitly/test_config.rb +28 -0
- data/test/test_helper.rb +2 -2
- metadata +72 -12
data/Gemfile
ADDED
data/History.txt
CHANGED
@@ -1,3 +1,30 @@
|
|
1
|
+
=== 0.9.0 / 2013-4-28
|
2
|
+
|
3
|
+
* 2 major updates
|
4
|
+
|
5
|
+
* Replaces Crack with MultiJson (issue #34)
|
6
|
+
* Adds timeout to v3 client calls (issue #27)
|
7
|
+
|
8
|
+
* 5 minor updates
|
9
|
+
|
10
|
+
* Adds qrcode_url method to Bitly::V3::Url class (issue #21)
|
11
|
+
* Ability to configure Bitly with a configure block (issue #16)
|
12
|
+
* Stops gem messing with the load path (issue #32)
|
13
|
+
* Adds development dependencies to Rakefile/gemspec (issue #33)
|
14
|
+
* Change Bitly::V3::User file to use ASCII quotes (issue #39)
|
15
|
+
|
16
|
+
=== 0.8.1 / 2013-15-01
|
17
|
+
|
18
|
+
* 1 major update
|
19
|
+
|
20
|
+
* bumps httparty and crack dependencies due to security vulnerability
|
21
|
+
|
22
|
+
=== 0.8.0
|
23
|
+
|
24
|
+
* 1 major update
|
25
|
+
|
26
|
+
* Updates OAuth2 dependency again
|
27
|
+
|
1
28
|
=== 0.7.0 / 2011-1-8
|
2
29
|
|
3
30
|
* 1 major bug fix
|
data/Manifest
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
+
Gemfile
|
1
2
|
History.txt
|
2
3
|
Manifest
|
3
4
|
README.md
|
4
5
|
Rakefile
|
5
|
-
bitly.gemspec
|
6
6
|
lib/bitly.rb
|
7
7
|
lib/bitly/client.rb
|
8
|
+
lib/bitly/config.rb
|
8
9
|
lib/bitly/url.rb
|
9
10
|
lib/bitly/utils.rb
|
10
11
|
lib/bitly/v3.rb
|
@@ -20,6 +21,7 @@ lib/bitly/v3/url.rb
|
|
20
21
|
lib/bitly/v3/user.rb
|
21
22
|
lib/bitly/version.rb
|
22
23
|
test/bitly/test_client.rb
|
24
|
+
test/bitly/test_config.rb
|
23
25
|
test/bitly/test_url.rb
|
24
26
|
test/bitly/test_utils.rb
|
25
27
|
test/fixtures/cnn.json
|
data/README.md
CHANGED
@@ -61,6 +61,20 @@ All four functions return a ``Bitly::Url`` object (or an array of ``Bitly::Url``
|
|
61
61
|
|
62
62
|
Please see the Bit.ly API documentation [http://api.bit.ly](http://api.bit.ly) for details on the V3 API.
|
63
63
|
|
64
|
+
### Configure bitly through initializer
|
65
|
+
|
66
|
+
If you want to configure bitly through an initializer (e.g. `config/initializers/bitly.rb`), do the following:
|
67
|
+
|
68
|
+
Bitly.configure do |config|
|
69
|
+
config.api_version = 3
|
70
|
+
config.login = "Bitly_Username"
|
71
|
+
config.api_key = "API_KEY"
|
72
|
+
end
|
73
|
+
|
74
|
+
Instead of using `Bitly.new(username, api_key)` to get the client, use `Bitly.client`:
|
75
|
+
|
76
|
+
client = Bitly.client
|
77
|
+
|
64
78
|
## LICENSE:
|
65
79
|
|
66
80
|
> (The MIT License)
|
data/Rakefile
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'rake'
|
3
3
|
require 'echoe'
|
4
|
-
require './lib/bitly
|
4
|
+
require './lib/bitly/version'
|
5
5
|
|
6
6
|
Echoe.new('bitly', Bitly::VERSION) do |p|
|
7
7
|
p.description = "Use the bit.ly API to shorten or expand URLs"
|
@@ -9,9 +9,15 @@ Echoe.new('bitly', Bitly::VERSION) do |p|
|
|
9
9
|
p.author = "Phil Nash"
|
10
10
|
p.email = "philnash@gmail.com"
|
11
11
|
p.extra_deps = [
|
12
|
-
['
|
12
|
+
['multi_json', '~> 1.3'],
|
13
13
|
['httparty', '>= 0.7.6'],
|
14
14
|
['oauth2', '>= 0.5.0', '< 0.9']
|
15
15
|
]
|
16
|
-
p.development_dependencies = [
|
17
|
-
|
16
|
+
p.development_dependencies = [
|
17
|
+
['echoe'],
|
18
|
+
['rake'],
|
19
|
+
['shoulda'],
|
20
|
+
['flexmock'],
|
21
|
+
['fakeweb']
|
22
|
+
]
|
23
|
+
end
|
data/bitly.gemspec
CHANGED
@@ -2,38 +2,53 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "bitly"
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "0.9.0"
|
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 = "2013-
|
9
|
+
s.date = "2013-04-28"
|
10
10
|
s.description = "Use the bit.ly API to shorten or expand URLs"
|
11
11
|
s.email = "philnash@gmail.com"
|
12
|
-
s.extra_rdoc_files = ["README.md", "lib/bitly.rb", "lib/bitly/client.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 = ["History.txt", "Manifest", "README.md", "Rakefile", "bitly.
|
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", "bitly.gemspec"]
|
14
14
|
s.homepage = "http://github.com/philnash/bitly"
|
15
15
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Bitly", "--main", "README.md"]
|
16
16
|
s.require_paths = ["lib"]
|
17
17
|
s.rubyforge_project = "bitly"
|
18
18
|
s.rubygems_version = "1.8.11"
|
19
19
|
s.summary = "Use the bit.ly API to shorten or expand URLs"
|
20
|
-
s.test_files = ["test/bitly/test_client.rb", "test/bitly/test_url.rb", "test/bitly/test_utils.rb", "test/test_helper.rb"]
|
20
|
+
s.test_files = ["test/bitly/test_client.rb", "test/bitly/test_config.rb", "test/bitly/test_url.rb", "test/bitly/test_utils.rb", "test/test_helper.rb"]
|
21
21
|
|
22
22
|
if s.respond_to? :specification_version then
|
23
23
|
s.specification_version = 3
|
24
24
|
|
25
25
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
26
|
-
s.add_runtime_dependency(%q<
|
26
|
+
s.add_runtime_dependency(%q<multi_json>, ["~> 1.3"])
|
27
27
|
s.add_runtime_dependency(%q<httparty>, [">= 0.7.6"])
|
28
28
|
s.add_runtime_dependency(%q<oauth2>, ["< 0.9", ">= 0.5.0"])
|
29
|
+
s.add_development_dependency(%q<echoe>, [">= 0"])
|
30
|
+
s.add_development_dependency(%q<rake>, [">= 0"])
|
31
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
32
|
+
s.add_development_dependency(%q<flexmock>, [">= 0"])
|
33
|
+
s.add_development_dependency(%q<fakeweb>, [">= 0"])
|
29
34
|
else
|
30
|
-
s.add_dependency(%q<
|
35
|
+
s.add_dependency(%q<multi_json>, ["~> 1.3"])
|
31
36
|
s.add_dependency(%q<httparty>, [">= 0.7.6"])
|
32
37
|
s.add_dependency(%q<oauth2>, ["< 0.9", ">= 0.5.0"])
|
38
|
+
s.add_dependency(%q<echoe>, [">= 0"])
|
39
|
+
s.add_dependency(%q<rake>, [">= 0"])
|
40
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
41
|
+
s.add_dependency(%q<flexmock>, [">= 0"])
|
42
|
+
s.add_dependency(%q<fakeweb>, [">= 0"])
|
33
43
|
end
|
34
44
|
else
|
35
|
-
s.add_dependency(%q<
|
45
|
+
s.add_dependency(%q<multi_json>, ["~> 1.3"])
|
36
46
|
s.add_dependency(%q<httparty>, [">= 0.7.6"])
|
37
47
|
s.add_dependency(%q<oauth2>, ["< 0.9", ">= 0.5.0"])
|
48
|
+
s.add_dependency(%q<echoe>, [">= 0"])
|
49
|
+
s.add_dependency(%q<rake>, [">= 0"])
|
50
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
51
|
+
s.add_dependency(%q<flexmock>, [">= 0"])
|
52
|
+
s.add_dependency(%q<fakeweb>, [">= 0"])
|
38
53
|
end
|
39
54
|
end
|
data/lib/bitly.rb
CHANGED
data/lib/bitly/client.rb
CHANGED
@@ -3,29 +3,41 @@ require 'net/http'
|
|
3
3
|
require 'uri'
|
4
4
|
|
5
5
|
module Bitly
|
6
|
+
extend Config
|
6
7
|
API_URL = 'http://api.bit.ly/'
|
7
8
|
API_VERSION = '2.0.1'
|
8
9
|
|
9
|
-
def self.new(login, api_key)
|
10
|
+
def self.new(login, api_key, timeout=nil)
|
10
11
|
if @version == 3
|
11
|
-
Bitly::V3::Client.new(login, api_key)
|
12
|
+
Bitly::V3::Client.new(login, api_key, timeout)
|
12
13
|
else
|
13
14
|
Bitly::Client.new(login,api_key)
|
14
15
|
end
|
15
16
|
end
|
16
|
-
|
17
|
+
|
17
18
|
def self.use_api_version_3
|
18
19
|
@version = 3
|
19
20
|
end
|
20
|
-
|
21
|
+
|
21
22
|
def self.use_api_version_2
|
22
23
|
@version = 2
|
23
24
|
end
|
24
25
|
|
26
|
+
# get and initialize a client if configured using Config
|
27
|
+
def self.client
|
28
|
+
# api_verison, login, and api_key are set in Config
|
29
|
+
if api_version == 3
|
30
|
+
Bitly::V3::Client.new(login, api_key, timeout)
|
31
|
+
else
|
32
|
+
Bitly::Client.new(login, api_key)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
25
36
|
class Client
|
26
|
-
|
37
|
+
|
27
38
|
include Bitly::Utils
|
28
|
-
|
39
|
+
attr_accessor *Config::OPTION_KEYS
|
40
|
+
|
29
41
|
def initialize(login,api_key)
|
30
42
|
warn "[DEPRECATION] The bit.ly version 2 API has been superceded by version 3 and will be removed. See the README for details"
|
31
43
|
@login = login
|
@@ -50,7 +62,7 @@ module Bitly
|
|
50
62
|
raise ArgumentError.new("Shorten requires either a url or an array of urls")
|
51
63
|
end
|
52
64
|
end
|
53
|
-
|
65
|
+
|
54
66
|
def expand(input)
|
55
67
|
if input.is_a? String
|
56
68
|
if input.include?('bit.ly/') || input.include?('j.mp/')
|
@@ -63,7 +75,7 @@ module Bitly
|
|
63
75
|
result = get_result(request)
|
64
76
|
result = { :hash => input, :short_url => "http://bit.ly/#{input}" }.merge result[input]
|
65
77
|
end
|
66
|
-
Bitly::Url.new(@login,@api_key,result)
|
78
|
+
Bitly::Url.new(@login,@api_key,result)
|
67
79
|
elsif input.is_a? Array
|
68
80
|
request = create_url "expand", :hash => input.join(',')
|
69
81
|
result = get_result(request)
|
@@ -75,7 +87,7 @@ module Bitly
|
|
75
87
|
raise ArgumentError('Expand requires either a short url, a hash or an array of hashes')
|
76
88
|
end
|
77
89
|
end
|
78
|
-
|
90
|
+
|
79
91
|
def info(input)
|
80
92
|
if input.is_a? String
|
81
93
|
if input.include? "bit.ly/"
|
@@ -100,7 +112,7 @@ module Bitly
|
|
100
112
|
raise ArgumentError.new('Info requires either a short url, a hash or an array of hashes')
|
101
113
|
end
|
102
114
|
end
|
103
|
-
|
115
|
+
|
104
116
|
def stats(input)
|
105
117
|
if input.is_a? String
|
106
118
|
if input.include? "bit.ly/"
|
@@ -118,9 +130,9 @@ module Bitly
|
|
118
130
|
raise ArgumentError.new("Stats requires either a short url or a hash")
|
119
131
|
end
|
120
132
|
end
|
121
|
-
|
133
|
+
|
122
134
|
end
|
123
|
-
|
135
|
+
|
124
136
|
end
|
125
137
|
|
126
138
|
class BitlyError < StandardError
|
@@ -130,4 +142,4 @@ class BitlyError < StandardError
|
|
130
142
|
@code = code
|
131
143
|
super("#{msg} - '#{code}'")
|
132
144
|
end
|
133
|
-
end
|
145
|
+
end
|
data/lib/bitly/config.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
module Bitly
|
2
|
+
module Config
|
3
|
+
|
4
|
+
# bitly client options
|
5
|
+
OPTION_KEYS = [
|
6
|
+
:login,
|
7
|
+
:api_key,
|
8
|
+
:api_version,
|
9
|
+
:timeout
|
10
|
+
]
|
11
|
+
|
12
|
+
attr_accessor *OPTION_KEYS
|
13
|
+
|
14
|
+
def configure
|
15
|
+
yield self
|
16
|
+
self
|
17
|
+
end
|
18
|
+
|
19
|
+
def options
|
20
|
+
options = {}
|
21
|
+
OPTION_KEYS.each{|key| options[key] = send(key)}
|
22
|
+
options
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
data/lib/bitly/utils.rb
CHANGED
@@ -45,8 +45,8 @@ module Bitly
|
|
45
45
|
begin
|
46
46
|
json = Net::HTTP.get(request)
|
47
47
|
# puts json.inspect
|
48
|
-
result =
|
49
|
-
rescue
|
48
|
+
result = MultiJson.load(json)
|
49
|
+
rescue MultiJson::DecodeError
|
50
50
|
result = {'errorMessage' => 'JSON Parse Error(Bit.ly messed up)', 'errorCode' => 69, 'statusCode' => 'ERROR'}
|
51
51
|
end
|
52
52
|
if result['statusCode'] == "OK"
|
@@ -57,4 +57,4 @@ module Bitly
|
|
57
57
|
end
|
58
58
|
|
59
59
|
end
|
60
|
-
end
|
60
|
+
end
|
data/lib/bitly/v3/client.rb
CHANGED
@@ -7,9 +7,11 @@ module Bitly
|
|
7
7
|
include HTTParty
|
8
8
|
base_uri 'http://api.bit.ly/v3/'
|
9
9
|
|
10
|
-
# Requires a login and api key. Get yours from your account page at
|
11
|
-
|
10
|
+
# Requires a login and api key. Get yours from your account page at https://bitly.com/a/your_api_key
|
11
|
+
# Visit your account at http://bit.ly/a/account
|
12
|
+
def initialize(login, api_key, timeout=nil)
|
12
13
|
@default_query_opts = { :login => login, :apiKey => api_key }
|
14
|
+
self.timeout = timeout
|
13
15
|
end
|
14
16
|
|
15
17
|
# Validates a login and api key
|
@@ -109,6 +111,10 @@ module Bitly
|
|
109
111
|
get_method(:clicks_by_day, input, opts)
|
110
112
|
end
|
111
113
|
|
114
|
+
def timeout=(timeout=nil)
|
115
|
+
self.class.default_timeout(timeout) if timeout
|
116
|
+
end
|
117
|
+
|
112
118
|
private
|
113
119
|
|
114
120
|
def arrayize(arg)
|
@@ -122,7 +128,13 @@ module Bitly
|
|
122
128
|
def get(method, opts={})
|
123
129
|
opts[:query] ||= {}
|
124
130
|
opts[:query].merge!(@default_query_opts)
|
125
|
-
|
131
|
+
|
132
|
+
begin
|
133
|
+
response = self.class.get(method, opts)
|
134
|
+
rescue Timeout::Error
|
135
|
+
raise BitlyTimeout.new("Bitly didn't respond in time", "504")
|
136
|
+
end
|
137
|
+
|
126
138
|
if response['status_code'] == 200
|
127
139
|
return response
|
128
140
|
else
|
@@ -178,3 +190,5 @@ module Bitly
|
|
178
190
|
end
|
179
191
|
end
|
180
192
|
end
|
193
|
+
|
194
|
+
class BitlyTimeout < BitlyError; end
|
data/lib/bitly/v3/url.rb
CHANGED
@@ -114,6 +114,13 @@ module Bitly
|
|
114
114
|
@clicks_by_day
|
115
115
|
end
|
116
116
|
|
117
|
+
# QR code is automatically created and can be incorporated
|
118
|
+
# into mobile applications.
|
119
|
+
def qrcode_url(opts={})
|
120
|
+
qrcode = opts.has_key?(:s) ? ".qrcode?s=#{opts[:s]}" : ".qrcode"
|
121
|
+
@short_url + qrcode
|
122
|
+
end
|
123
|
+
|
117
124
|
private
|
118
125
|
|
119
126
|
def update_clicks_data
|
@@ -140,4 +147,4 @@ module Bitly
|
|
140
147
|
end
|
141
148
|
end
|
142
149
|
end
|
143
|
-
end
|
150
|
+
end
|
data/lib/bitly/v3/user.rb
CHANGED
@@ -27,7 +27,7 @@ module Bitly
|
|
27
27
|
end
|
28
28
|
|
29
29
|
# OAuth 2 endpoint that provides a list of top referrers (up to 500 per
|
30
|
-
# day) for a given user
|
30
|
+
# day) for a given user's bit.ly links, and the number of clicks per referrer.
|
31
31
|
#
|
32
32
|
# http://code.google.com/p/bitly-api/wiki/ApiDocumentation#/v3/user/referrers
|
33
33
|
def referrers(opts={})
|
@@ -38,7 +38,7 @@ module Bitly
|
|
38
38
|
end
|
39
39
|
|
40
40
|
# OAuth 2 endpoint that provides a list of countries from which clicks
|
41
|
-
# on a given user
|
41
|
+
# on a given user's bit.ly links are originating, and the number of clicks per country.
|
42
42
|
#
|
43
43
|
# http://code.google.com/p/bitly-api/wiki/ApiDocumentation#/v3/user/countries
|
44
44
|
def countries(opts={})
|
@@ -48,7 +48,7 @@ module Bitly
|
|
48
48
|
@countries
|
49
49
|
end
|
50
50
|
|
51
|
-
# OAuth 2 endpoint that provides a given user
|
51
|
+
# OAuth 2 endpoint that provides a given user's 100 most popular links
|
52
52
|
# based on click traffic in the past hour, and the number of clicks per link.
|
53
53
|
#
|
54
54
|
# http://code.google.com/p/bitly-api/wiki/ApiDocumentation#/v3/user/realtime_links
|
@@ -65,7 +65,7 @@ module Bitly
|
|
65
65
|
@realtime_links
|
66
66
|
end
|
67
67
|
|
68
|
-
# OAuth 2 endpoint that provides the total clicks per day on a user
|
68
|
+
# OAuth 2 endpoint that provides the total clicks per day on a user's bit.ly links.
|
69
69
|
#
|
70
70
|
# http://code.google.com/p/bitly-api/wiki/ApiDocumentation#/v3/user/clicks
|
71
71
|
def clicks(opts={})
|
@@ -84,7 +84,7 @@ module Bitly
|
|
84
84
|
@client ||= Bitly::V3::Client.new(login, api_key)
|
85
85
|
end
|
86
86
|
|
87
|
-
# OAuth 2 endpoint that OAuth 2 endpoint that provides a given user
|
87
|
+
# OAuth 2 endpoint that OAuth 2 endpoint that provides a given user's link
|
88
88
|
# shortening history, in reverse chronological order (most recent to least
|
89
89
|
# recent).
|
90
90
|
def link_history(opts={})
|
data/lib/bitly/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module Bitly
|
2
|
-
VERSION = '0.
|
3
|
-
end
|
2
|
+
VERSION = '0.9.0'
|
3
|
+
end
|
data/test/bitly/test_client.rb
CHANGED
@@ -6,12 +6,23 @@ class TestClient < Test::Unit::TestCase
|
|
6
6
|
b = Bitly.new(login, api_key)
|
7
7
|
assert_equal Bitly::Client, b.class
|
8
8
|
end
|
9
|
+
|
10
|
+
should "create a new bitly client and configure with a block" do
|
11
|
+
Bitly.configure do |config|
|
12
|
+
config.api_key = api_key
|
13
|
+
config.login = login
|
14
|
+
end
|
15
|
+
b = Bitly.client
|
16
|
+
assert_kind_of Bitly::Client, b
|
17
|
+
assert_equal api_key, b.api_key
|
18
|
+
assert_equal login, login
|
19
|
+
end
|
9
20
|
end
|
10
21
|
context "using the bitly client" do
|
11
22
|
setup do
|
12
23
|
@bitly = Bitly.new(login, api_key)
|
13
24
|
end
|
14
|
-
|
25
|
+
|
15
26
|
context "shortening" do
|
16
27
|
context "a single link" do
|
17
28
|
setup do
|
@@ -212,4 +223,4 @@ class TestClient < Test::Unit::TestCase
|
|
212
223
|
end
|
213
224
|
end
|
214
225
|
end
|
215
|
-
end
|
226
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'test_helper.rb')
|
2
|
+
|
3
|
+
class TestConfig < Test::Unit::TestCase
|
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/test_helper.rb
CHANGED
@@ -17,7 +17,7 @@ end
|
|
17
17
|
def stub_get(url, filename, status=nil)
|
18
18
|
options = {:body => fixture_file(filename)}
|
19
19
|
options.merge!({:status => status}) unless status.nil?
|
20
|
-
|
20
|
+
|
21
21
|
FakeWeb.register_uri(:get, url, options)
|
22
22
|
end
|
23
23
|
|
@@ -32,4 +32,4 @@ class Test::Unit::TestCase
|
|
32
32
|
def teardown
|
33
33
|
FakeWeb.clean_registry
|
34
34
|
end
|
35
|
-
end
|
35
|
+
end
|
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.
|
4
|
+
version: 0.9.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,22 +9,22 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-04-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
16
|
-
requirement: &
|
15
|
+
name: multi_json
|
16
|
+
requirement: &70227825351380 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
21
|
+
version: '1.3'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70227825351380
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: httparty
|
27
|
-
requirement: &
|
27
|
+
requirement: &70227825350880 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 0.7.6
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70227825350880
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: oauth2
|
38
|
-
requirement: &
|
38
|
+
requirement: &70227825350180 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -46,7 +46,62 @@ dependencies:
|
|
46
46
|
version: '0.9'
|
47
47
|
type: :runtime
|
48
48
|
prerelease: false
|
49
|
-
version_requirements: *
|
49
|
+
version_requirements: *70227825350180
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: echoe
|
52
|
+
requirement: &70227825349200 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
type: :development
|
59
|
+
prerelease: false
|
60
|
+
version_requirements: *70227825349200
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rake
|
63
|
+
requirement: &70227825348580 !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
type: :development
|
70
|
+
prerelease: false
|
71
|
+
version_requirements: *70227825348580
|
72
|
+
- !ruby/object:Gem::Dependency
|
73
|
+
name: shoulda
|
74
|
+
requirement: &70227825347860 !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ! '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
type: :development
|
81
|
+
prerelease: false
|
82
|
+
version_requirements: *70227825347860
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: flexmock
|
85
|
+
requirement: &70227825347240 !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ! '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: *70227825347240
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: fakeweb
|
96
|
+
requirement: &70227825346600 !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: *70227825346600
|
50
105
|
description: Use the bit.ly API to shorten or expand URLs
|
51
106
|
email: philnash@gmail.com
|
52
107
|
executables: []
|
@@ -55,6 +110,7 @@ extra_rdoc_files:
|
|
55
110
|
- README.md
|
56
111
|
- lib/bitly.rb
|
57
112
|
- lib/bitly/client.rb
|
113
|
+
- lib/bitly/config.rb
|
58
114
|
- lib/bitly/url.rb
|
59
115
|
- lib/bitly/utils.rb
|
60
116
|
- lib/bitly/v3.rb
|
@@ -70,13 +126,14 @@ extra_rdoc_files:
|
|
70
126
|
- lib/bitly/v3/user.rb
|
71
127
|
- lib/bitly/version.rb
|
72
128
|
files:
|
129
|
+
- Gemfile
|
73
130
|
- History.txt
|
74
131
|
- Manifest
|
75
132
|
- README.md
|
76
133
|
- Rakefile
|
77
|
-
- bitly.gemspec
|
78
134
|
- lib/bitly.rb
|
79
135
|
- lib/bitly/client.rb
|
136
|
+
- lib/bitly/config.rb
|
80
137
|
- lib/bitly/url.rb
|
81
138
|
- lib/bitly/utils.rb
|
82
139
|
- lib/bitly/v3.rb
|
@@ -92,6 +149,7 @@ files:
|
|
92
149
|
- lib/bitly/v3/user.rb
|
93
150
|
- lib/bitly/version.rb
|
94
151
|
- test/bitly/test_client.rb
|
152
|
+
- test/bitly/test_config.rb
|
95
153
|
- test/bitly/test_url.rb
|
96
154
|
- test/bitly/test_utils.rb
|
97
155
|
- test/fixtures/cnn.json
|
@@ -103,6 +161,7 @@ files:
|
|
103
161
|
- test/fixtures/google_stats.json
|
104
162
|
- test/fixtures/shorten_error.json
|
105
163
|
- test/test_helper.rb
|
164
|
+
- bitly.gemspec
|
106
165
|
homepage: http://github.com/philnash/bitly
|
107
166
|
licenses: []
|
108
167
|
post_install_message:
|
@@ -135,6 +194,7 @@ specification_version: 3
|
|
135
194
|
summary: Use the bit.ly API to shorten or expand URLs
|
136
195
|
test_files:
|
137
196
|
- test/bitly/test_client.rb
|
197
|
+
- test/bitly/test_config.rb
|
138
198
|
- test/bitly/test_url.rb
|
139
199
|
- test/bitly/test_utils.rb
|
140
200
|
- test/test_helper.rb
|