bitly 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +12 -0
- data/bitly.gemspec +2 -2
- data/lib/bitly/v3/client.rb +28 -4
- data/lib/bitly/v3/missing_url.rb +2 -1
- data/lib/bitly/v3/url.rb +1 -1
- data/lib/bitly/version.rb +1 -1
- metadata +3 -3
data/History.txt
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
=== 0.5.2 / 2010-07-18
|
2
|
+
|
3
|
+
* 1 minor enhancement
|
4
|
+
|
5
|
+
* Added the lookup call to the version 3 API.
|
6
|
+
|
7
|
+
=== 0.5.1 / 2010-05-26
|
8
|
+
|
9
|
+
* 1 bug fix
|
10
|
+
|
11
|
+
* When expanding a short url with the v3 module, user hash and short url weren't being set properly
|
12
|
+
|
1
13
|
=== 0.5.0 / 2010-05-12
|
2
14
|
|
3
15
|
* Loads of major enhancements
|
data/bitly.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{bitly}
|
5
|
-
s.version = "0.5.
|
5
|
+
s.version = "0.5.2"
|
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 = %q{2010-
|
9
|
+
s.date = %q{2010-07-18}
|
10
10
|
s.description = %q{Use the bit.ly API to shorten or expand URLs}
|
11
11
|
s.email = %q{philnash@gmail.com}
|
12
12
|
s.extra_rdoc_files = ["lib/bitly/client.rb", "lib/bitly/url.rb", "lib/bitly/utils.rb", "lib/bitly/v3/bitly.rb", "lib/bitly/v3/client.rb", "lib/bitly/v3/missing_url.rb", "lib/bitly/v3/url.rb", "lib/bitly/v3.rb", "lib/bitly/version.rb", "lib/bitly.rb", "README.txt"]
|
data/lib/bitly/v3/client.rb
CHANGED
@@ -53,6 +53,31 @@ module Bitly
|
|
53
53
|
def clicks(input)
|
54
54
|
get_method(:clicks, input)
|
55
55
|
end
|
56
|
+
|
57
|
+
# Looks up the short url and global hash of a url or array of urls
|
58
|
+
#
|
59
|
+
# Returns the results in the order they were entered
|
60
|
+
def lookup(input)
|
61
|
+
input = [input] if input.is_a?(String)
|
62
|
+
query = input.inject([]) { |query, i| query << "url=#{CGI.escape(i)}" }
|
63
|
+
query = "/lookup?" + query.join('&')
|
64
|
+
response = get(query)
|
65
|
+
results = response['data']['lookup'].inject([]) do |results, url|
|
66
|
+
url['long_url'] = url['url']
|
67
|
+
url['url'] = nil
|
68
|
+
if url['error'].nil?
|
69
|
+
# builds the results array in the same order as the input
|
70
|
+
results[input.index(url['long_url'])] = Bitly::V3::Url.new(self, url)
|
71
|
+
# remove the key from the original array, in case the same hash/url was entered twice
|
72
|
+
input[input.index(url['long_url'])] = nil
|
73
|
+
else
|
74
|
+
results[input.index(url['long_url'])] = Bitly::V3::MissingUrl.new(url)
|
75
|
+
input[input.index(url['long_url'])] = nil
|
76
|
+
end
|
77
|
+
results
|
78
|
+
end
|
79
|
+
return results.length > 1 ? results : results[0]
|
80
|
+
end
|
56
81
|
|
57
82
|
private
|
58
83
|
|
@@ -73,8 +98,7 @@ module Bitly
|
|
73
98
|
|
74
99
|
def get_method(method, input)
|
75
100
|
input = [input] if input.is_a? String
|
76
|
-
query = []
|
77
|
-
input.each do |i|
|
101
|
+
query = input.inject([]) do |query,i|
|
78
102
|
if is_a_short_url?(i)
|
79
103
|
query << "shortUrl=#{CGI.escape(i)}"
|
80
104
|
else
|
@@ -83,8 +107,7 @@ module Bitly
|
|
83
107
|
end
|
84
108
|
query = "/#{method}?" + query.join('&')
|
85
109
|
response = get(query)
|
86
|
-
results = []
|
87
|
-
response['data'][method.to_s].each do |url|
|
110
|
+
results = response['data'][method.to_s].inject do |results, url|
|
88
111
|
if url['error'].nil?
|
89
112
|
# builds the results array in the same order as the input
|
90
113
|
results[input.index(url['short_url'] || url['hash'])] = Bitly::V3::Url.new(self, url)
|
@@ -94,6 +117,7 @@ module Bitly
|
|
94
117
|
results[input.index(url['short_url'] || url['hash'])] = Bitly::V3::MissingUrl.new(url)
|
95
118
|
input[input.index(url['short_url'] || url['hash'])] = nil
|
96
119
|
end
|
120
|
+
results
|
97
121
|
end
|
98
122
|
return results.length > 1 ? results : results[0]
|
99
123
|
end
|
data/lib/bitly/v3/missing_url.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
module Bitly
|
2
2
|
module V3
|
3
3
|
class MissingUrl
|
4
|
-
attr_accessor :short_url, :user_hash, :error
|
4
|
+
attr_accessor :short_url, :user_hash, :long_url, :error
|
5
5
|
def initialize(opts={})
|
6
6
|
if opts
|
7
7
|
@short_url = opts['short_url']
|
8
8
|
@user_hash = opts['hash']
|
9
|
+
@long_url = opts['long_url']
|
9
10
|
@error = opts['error']
|
10
11
|
end
|
11
12
|
end
|
data/lib/bitly/v3/url.rb
CHANGED
@@ -9,7 +9,7 @@ module Bitly
|
|
9
9
|
def initialize(client, opts={})
|
10
10
|
@client = client
|
11
11
|
if opts
|
12
|
-
@short_url = opts['url']
|
12
|
+
@short_url = opts['url'] || opts['short_url']
|
13
13
|
@long_url = opts['long_url']
|
14
14
|
@user_hash = opts['hash'] || opts['user_hash']
|
15
15
|
@global_hash = opts['global_hash']
|
data/lib/bitly/version.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 5
|
8
|
-
-
|
9
|
-
version: 0.5.
|
8
|
+
- 2
|
9
|
+
version: 0.5.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Phil Nash
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-07-18 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|