bitly 0.5.3 → 0.5.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 +6 -0
- data/Manifest +9 -6
- data/bitly.gemspec +6 -6
- data/lib/bitly/v3.rb +3 -0
- data/lib/bitly/v3/client.rb +36 -1
- data/lib/bitly/v3/country.rb +13 -0
- data/lib/bitly/v3/day.rb +13 -0
- data/lib/bitly/v3/referrer.rb +13 -0
- data/lib/bitly/v3/url.rb +55 -0
- data/lib/bitly/version.rb +1 -1
- metadata +28 -13
data/History.txt
CHANGED
data/Manifest
CHANGED
@@ -1,18 +1,21 @@
|
|
1
|
-
bitly.gemspec
|
2
1
|
History.txt
|
2
|
+
Manifest
|
3
|
+
README.txt
|
4
|
+
Rakefile
|
5
|
+
bitly.gemspec
|
6
|
+
lib/bitly.rb
|
3
7
|
lib/bitly/client.rb
|
4
8
|
lib/bitly/url.rb
|
5
9
|
lib/bitly/utils.rb
|
10
|
+
lib/bitly/v3.rb
|
6
11
|
lib/bitly/v3/bitly.rb
|
7
12
|
lib/bitly/v3/client.rb
|
13
|
+
lib/bitly/v3/country.rb
|
14
|
+
lib/bitly/v3/day.rb
|
8
15
|
lib/bitly/v3/missing_url.rb
|
16
|
+
lib/bitly/v3/referrer.rb
|
9
17
|
lib/bitly/v3/url.rb
|
10
|
-
lib/bitly/v3.rb
|
11
18
|
lib/bitly/version.rb
|
12
|
-
lib/bitly.rb
|
13
|
-
Manifest
|
14
|
-
Rakefile
|
15
|
-
README.txt
|
16
19
|
test/bitly/test_client.rb
|
17
20
|
test/bitly/test_url.rb
|
18
21
|
test/bitly/test_utils.rb
|
data/bitly.gemspec
CHANGED
@@ -2,20 +2,20 @@
|
|
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.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 = %q{2010-
|
9
|
+
s.date = %q{2010-12-01}
|
10
10
|
s.description = %q{Use the bit.ly API to shorten or expand URLs}
|
11
11
|
s.email = %q{philnash@gmail.com}
|
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/
|
13
|
-
s.files = ["bitly.gemspec", "
|
12
|
+
s.extra_rdoc_files = ["README.txt", "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/referrer.rb", "lib/bitly/v3/url.rb", "lib/bitly/version.rb"]
|
13
|
+
s.files = ["History.txt", "Manifest", "README.txt", "Rakefile", "bitly.gemspec", "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/referrer.rb", "lib/bitly/v3/url.rb", "lib/bitly/version.rb", "test/bitly/test_client.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 = %q{http://github.com/philnash/bitly}
|
15
15
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Bitly", "--main", "README.txt"]
|
16
16
|
s.require_paths = ["lib"]
|
17
17
|
s.rubyforge_project = %q{bitly}
|
18
|
-
s.rubygems_version = %q{1.3.
|
18
|
+
s.rubygems_version = %q{1.3.7}
|
19
19
|
s.summary = %q{Use the bit.ly API to shorten or expand URLs}
|
20
20
|
s.test_files = ["test/bitly/test_client.rb", "test/bitly/test_url.rb", "test/bitly/test_utils.rb", "test/test_helper.rb"]
|
21
21
|
|
@@ -23,7 +23,7 @@ Gem::Specification.new do |s|
|
|
23
23
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
24
24
|
s.specification_version = 3
|
25
25
|
|
26
|
-
if Gem::Version.new(Gem::
|
26
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
27
27
|
s.add_runtime_dependency(%q<crack>, [">= 0.1.4"])
|
28
28
|
s.add_runtime_dependency(%q<httparty>, [">= 0.5.2"])
|
29
29
|
else
|
data/lib/bitly/v3.rb
CHANGED
data/lib/bitly/v3/client.rb
CHANGED
@@ -83,6 +83,30 @@ module Bitly
|
|
83
83
|
end
|
84
84
|
return results.length > 1 ? results : results[0]
|
85
85
|
end
|
86
|
+
|
87
|
+
# Expands either a short link or hash and gets the referrer data for that link
|
88
|
+
#
|
89
|
+
# This method does not take an array as an input
|
90
|
+
def referrers(input)
|
91
|
+
get_single_method('referrers', input)
|
92
|
+
end
|
93
|
+
|
94
|
+
# Expands either a short link or hash and gets the country data for that link
|
95
|
+
#
|
96
|
+
# This method does not take an array as an input
|
97
|
+
def countries(input)
|
98
|
+
get_single_method('countries', input)
|
99
|
+
end
|
100
|
+
|
101
|
+
# Takes a short url, hash or array of either and gets the clicks by minute of each of the last hour
|
102
|
+
def clicks_by_minute(input)
|
103
|
+
get_method(:clicks_by_minute, input)
|
104
|
+
end
|
105
|
+
|
106
|
+
# Takes a short url, hash or array of either and gets the clicks by day
|
107
|
+
def clicks_by_day(input)
|
108
|
+
get_method(:clicks_by_day, input)
|
109
|
+
end
|
86
110
|
|
87
111
|
private
|
88
112
|
|
@@ -100,6 +124,18 @@ module Bitly
|
|
100
124
|
def is_a_short_url?(input)
|
101
125
|
input.match(/^http:\/\//)
|
102
126
|
end
|
127
|
+
|
128
|
+
def get_single_method(method, input)
|
129
|
+
raise ArgumentError.new("This method only takes a hash or url input") unless input.is_a? String
|
130
|
+
if is_a_short_url?(input)
|
131
|
+
query = "shortUrl=#{CGI.escape(input)}"
|
132
|
+
else
|
133
|
+
query = "hash=#{CGI.escape(input)}"
|
134
|
+
end
|
135
|
+
query = "/#{method}?" + query
|
136
|
+
response = get(query)
|
137
|
+
return Bitly::V3::Url.new(self,response['data'])
|
138
|
+
end
|
103
139
|
|
104
140
|
def get_method(method, input)
|
105
141
|
input = [input] if input.is_a? String
|
@@ -127,7 +163,6 @@ module Bitly
|
|
127
163
|
end
|
128
164
|
return results.length > 1 ? results : results[0]
|
129
165
|
end
|
130
|
-
|
131
166
|
end
|
132
167
|
end
|
133
168
|
end
|
data/lib/bitly/v3/day.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
module Bitly
|
2
|
+
module V3
|
3
|
+
# Day objects are created by the clicks_by_day method of a url
|
4
|
+
class Day
|
5
|
+
attr_reader :clicks, :day_start
|
6
|
+
|
7
|
+
def initialize(opts)
|
8
|
+
@clicks = opts['clicks']
|
9
|
+
@day_start = Time.at(opts['day_start']) if opts['day_start']
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Bitly
|
2
|
+
module V3
|
3
|
+
class Referrer
|
4
|
+
attr_reader :clicks, :referrer, :referrer_app, :url
|
5
|
+
|
6
|
+
def initialize(opts)
|
7
|
+
['clicks', 'referrer', 'referrer_app', 'url'].each do |attribute|
|
8
|
+
instance_variable_set("@#{attribute}".to_sym, opts[attribute])
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/bitly/v3/url.rb
CHANGED
@@ -18,6 +18,19 @@ module Bitly
|
|
18
18
|
@global_clicks = opts['global_clicks']
|
19
19
|
@title = opts['title']
|
20
20
|
@created_by = opts['created_by']
|
21
|
+
@referrers = opts['referrers'].inject([]) do |results, referrer|
|
22
|
+
results << Bitly::V3::Referrer.new(referrer)
|
23
|
+
end if opts['referrers']
|
24
|
+
@countries = opts['countries'].inject([]) do |results, country|
|
25
|
+
results << Bitly::V3::Country.new(country)
|
26
|
+
end if opts['countries']
|
27
|
+
if opts['clicks'] && opts['clicks'][0].is_a?(Hash)
|
28
|
+
@clicks_by_day = opts['clicks'].inject([]) do |results, day|
|
29
|
+
results << Bitly::V3::Day.new(day)
|
30
|
+
end
|
31
|
+
else
|
32
|
+
@clicks_by_minute = opts['clicks']
|
33
|
+
end
|
21
34
|
end
|
22
35
|
@short_url = "http://bit.ly/#{@user_hash}" unless @short_url
|
23
36
|
end
|
@@ -59,6 +72,38 @@ module Bitly
|
|
59
72
|
@created_by
|
60
73
|
end
|
61
74
|
|
75
|
+
# If the url already has referrer data, return it.
|
76
|
+
# IF there is no referrer or <tt>:force => true</tt> is passed,
|
77
|
+
# updates the referrers and returns them
|
78
|
+
def referrers(opts={})
|
79
|
+
update_referrers if @referrers.nil? || opts[:force]
|
80
|
+
@referrers
|
81
|
+
end
|
82
|
+
|
83
|
+
# If the url already has country data, return it.
|
84
|
+
# IF there is no country or <tt>:force => true</tt> is passed,
|
85
|
+
# updates the countries and returns them
|
86
|
+
def countries(opts={})
|
87
|
+
update_countries if @countries.nil? || opts[:force]
|
88
|
+
@countries
|
89
|
+
end
|
90
|
+
|
91
|
+
def clicks_by_minute(opts={})
|
92
|
+
if @clicks_by_minute.nil? || opts[:force]
|
93
|
+
full_url = @client.clicks_by_minute(@user_hash || @short_url)
|
94
|
+
@clicks_by_minute = full_url.clicks_by_minute
|
95
|
+
end
|
96
|
+
@clicks_by_minute
|
97
|
+
end
|
98
|
+
|
99
|
+
def clicks_by_day(opts={})
|
100
|
+
if @clicks_by_day.nil? || opts[:force]
|
101
|
+
full_url = @client.clicks_by_day(@user_hash || @short_url)
|
102
|
+
@clicks_by_day = full_url.clicks_by_day
|
103
|
+
end
|
104
|
+
@clicks_by_day
|
105
|
+
end
|
106
|
+
|
62
107
|
private
|
63
108
|
|
64
109
|
def update_clicks_data
|
@@ -72,6 +117,16 @@ module Bitly
|
|
72
117
|
@created_by = full_url.created_by
|
73
118
|
@title = full_url.title
|
74
119
|
end
|
120
|
+
|
121
|
+
def update_referrers
|
122
|
+
full_url = @client.referrers(@user_hash || @short_url)
|
123
|
+
@referrers = full_url.referrers
|
124
|
+
end
|
125
|
+
|
126
|
+
def update_countries
|
127
|
+
full_url = @client.countries(@user_hash || @short_url)
|
128
|
+
@countries = full_url.countries
|
129
|
+
end
|
75
130
|
end
|
76
131
|
end
|
77
132
|
end
|
data/lib/bitly/version.rb
CHANGED
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bitly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 3
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 5
|
8
|
-
-
|
9
|
-
version: 0.5.
|
9
|
+
- 4
|
10
|
+
version: 0.5.4
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Phil Nash
|
@@ -14,16 +15,18 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-
|
18
|
+
date: 2010-12-01 00:00:00 +00:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
22
|
name: crack
|
22
23
|
prerelease: false
|
23
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
24
26
|
requirements:
|
25
27
|
- - ">="
|
26
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 19
|
27
30
|
segments:
|
28
31
|
- 0
|
29
32
|
- 1
|
@@ -35,9 +38,11 @@ dependencies:
|
|
35
38
|
name: httparty
|
36
39
|
prerelease: false
|
37
40
|
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
38
42
|
requirements:
|
39
43
|
- - ">="
|
40
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 15
|
41
46
|
segments:
|
42
47
|
- 0
|
43
48
|
- 5
|
@@ -52,33 +57,39 @@ executables: []
|
|
52
57
|
extensions: []
|
53
58
|
|
54
59
|
extra_rdoc_files:
|
60
|
+
- README.txt
|
61
|
+
- lib/bitly.rb
|
55
62
|
- lib/bitly/client.rb
|
56
63
|
- lib/bitly/url.rb
|
57
64
|
- lib/bitly/utils.rb
|
65
|
+
- lib/bitly/v3.rb
|
58
66
|
- lib/bitly/v3/bitly.rb
|
59
67
|
- lib/bitly/v3/client.rb
|
68
|
+
- lib/bitly/v3/country.rb
|
69
|
+
- lib/bitly/v3/day.rb
|
60
70
|
- lib/bitly/v3/missing_url.rb
|
71
|
+
- lib/bitly/v3/referrer.rb
|
61
72
|
- lib/bitly/v3/url.rb
|
62
|
-
- lib/bitly/v3.rb
|
63
73
|
- lib/bitly/version.rb
|
64
|
-
- lib/bitly.rb
|
65
|
-
- README.txt
|
66
74
|
files:
|
67
|
-
- bitly.gemspec
|
68
75
|
- History.txt
|
76
|
+
- Manifest
|
77
|
+
- README.txt
|
78
|
+
- Rakefile
|
79
|
+
- bitly.gemspec
|
80
|
+
- lib/bitly.rb
|
69
81
|
- lib/bitly/client.rb
|
70
82
|
- lib/bitly/url.rb
|
71
83
|
- lib/bitly/utils.rb
|
84
|
+
- lib/bitly/v3.rb
|
72
85
|
- lib/bitly/v3/bitly.rb
|
73
86
|
- lib/bitly/v3/client.rb
|
87
|
+
- lib/bitly/v3/country.rb
|
88
|
+
- lib/bitly/v3/day.rb
|
74
89
|
- lib/bitly/v3/missing_url.rb
|
90
|
+
- lib/bitly/v3/referrer.rb
|
75
91
|
- lib/bitly/v3/url.rb
|
76
|
-
- lib/bitly/v3.rb
|
77
92
|
- lib/bitly/version.rb
|
78
|
-
- lib/bitly.rb
|
79
|
-
- Manifest
|
80
|
-
- Rakefile
|
81
|
-
- README.txt
|
82
93
|
- test/bitly/test_client.rb
|
83
94
|
- test/bitly/test_url.rb
|
84
95
|
- test/bitly/test_utils.rb
|
@@ -106,16 +117,20 @@ rdoc_options:
|
|
106
117
|
require_paths:
|
107
118
|
- lib
|
108
119
|
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
none: false
|
109
121
|
requirements:
|
110
122
|
- - ">="
|
111
123
|
- !ruby/object:Gem::Version
|
124
|
+
hash: 3
|
112
125
|
segments:
|
113
126
|
- 0
|
114
127
|
version: "0"
|
115
128
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
116
130
|
requirements:
|
117
131
|
- - ">="
|
118
132
|
- !ruby/object:Gem::Version
|
133
|
+
hash: 11
|
119
134
|
segments:
|
120
135
|
- 1
|
121
136
|
- 2
|
@@ -123,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
138
|
requirements: []
|
124
139
|
|
125
140
|
rubyforge_project: bitly
|
126
|
-
rubygems_version: 1.3.
|
141
|
+
rubygems_version: 1.3.7
|
127
142
|
signing_key:
|
128
143
|
specification_version: 3
|
129
144
|
summary: Use the bit.ly API to shorten or expand URLs
|