bitly 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,9 @@
1
+ === 0.5.3 / 2010-07-30
2
+
3
+ * 1 minor enhancement
4
+
5
+ * Added the info call to the version 3 API
6
+
1
7
  === 0.5.2 / 2010-07-18
2
8
 
3
9
  * 1 minor enhancement
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.2"
5
+ s.version = "0.5.3"
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-07-18}
9
+ s.date = %q{2010-07-30}
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"]
@@ -54,6 +54,11 @@ module Bitly
54
54
  get_method(:clicks, input)
55
55
  end
56
56
 
57
+ # Like expand, but gets the title of the page and who created it
58
+ def info(input)
59
+ get_method(:info, input)
60
+ end
61
+
57
62
  # Looks up the short url and global hash of a url or array of urls
58
63
  #
59
64
  # Returns the results in the order they were entered
@@ -107,15 +112,16 @@ module Bitly
107
112
  end
108
113
  query = "/#{method}?" + query.join('&')
109
114
  response = get(query)
110
- results = response['data'][method.to_s].inject do |results, url|
115
+ results = response['data'][method.to_s].inject([]) do |results, url|
116
+ result_index = input.index(url['short_url'] || url['hash']) || input.index(url['global_hash'])
111
117
  if url['error'].nil?
112
118
  # builds the results array in the same order as the input
113
- results[input.index(url['short_url'] || url['hash'])] = Bitly::V3::Url.new(self, url)
119
+ results[result_index] = Bitly::V3::Url.new(self, url)
114
120
  # remove the key from the original array, in case the same hash/url was entered twice
115
- input[input.index(url['short_url'] || url['hash'])] = nil
121
+ input[result_index] = nil
116
122
  else
117
- results[input.index(url['short_url'] || url['hash'])] = Bitly::V3::MissingUrl.new(url)
118
- input[input.index(url['short_url'] || url['hash'])] = nil
123
+ results[result_index] = Bitly::V3::MissingUrl.new(url)
124
+ input[result_index] = nil
119
125
  end
120
126
  results
121
127
  end
data/lib/bitly/v3/url.rb CHANGED
@@ -16,6 +16,8 @@ module Bitly
16
16
  @new_hash = (opts['new_hash'] == 1)
17
17
  @user_clicks = opts['user_clicks']
18
18
  @global_clicks = opts['global_clicks']
19
+ @title = opts['title']
20
+ @created_by = opts['created_by']
19
21
  end
20
22
  @short_url = "http://bit.ly/#{@user_hash}" unless @short_url
21
23
  end
@@ -40,6 +42,22 @@ module Bitly
40
42
  update_clicks_data if @global_clicks.nil? || opts[:force]
41
43
  @global_clicks
42
44
  end
45
+
46
+ # If the url already has the title, return it.
47
+ # IF there is no title or <tt>:force => true</tt> is passed,
48
+ # updates the info and returns the title
49
+ def title(opts={})
50
+ update_info if @title.nil? || opts[:force]
51
+ @title
52
+ end
53
+
54
+ # If the url already has the creator, return it.
55
+ # IF there is no creator or <tt>:force => true</tt> is passed,
56
+ # updates the info and returns the creator
57
+ def created_by(opts={})
58
+ update_info if @created_by.nil? || opts[:force]
59
+ @created_by
60
+ end
43
61
 
44
62
  private
45
63
 
@@ -48,6 +66,12 @@ module Bitly
48
66
  @global_clicks = full_url.global_clicks
49
67
  @user_clicks = full_url.user_clicks
50
68
  end
69
+
70
+ def update_info
71
+ full_url = @client.info(@user_hash || @short_url)
72
+ @created_by = full_url.created_by
73
+ @title = full_url.title
74
+ end
51
75
  end
52
76
  end
53
77
  end
data/lib/bitly/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Bitly
2
- VERSION = '0.5.2'
2
+ VERSION = '0.5.3'
3
3
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 5
8
- - 2
9
- version: 0.5.2
8
+ - 3
9
+ version: 0.5.3
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-07-18 00:00:00 +01:00
17
+ date: 2010-07-30 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency