philnash-bitly 0.1.2 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,10 +1,15 @@
1
- === 0.1.2 / 2009-04-12
1
+ === 0.1.4 / 2009-04-13
2
+
3
+ * 1 bug fix
4
+
5
+ * Urls with parameters were choking, changed to using CGI.
6
+
7
+ === 0.1.2 / 2009-03-12
2
8
 
3
9
  * 1 minor enhancement
4
10
 
5
11
  * Allows to add a keyword for shortening urls
6
12
 
7
-
8
13
  === 0.1.1 / 2009-01-26
9
14
 
10
15
  * 1 bug fix
data/Manifest ADDED
@@ -0,0 +1,11 @@
1
+ bitly.gemspec
2
+ History.txt
3
+ lib/bitly/client.rb
4
+ lib/bitly/url.rb
5
+ lib/bitly/utils.rb
6
+ lib/bitly/version.rb
7
+ lib/bitly.rb
8
+ Manifest
9
+ Rakefile
10
+ README.txt
11
+ test/test_bitly.rb
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.1.2"
5
+ s.version = "0.1.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{2009-03-13}
9
+ s.date = %q{2009-04-13}
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/version.rb", "lib/bitly.rb", "README.txt"]
data/lib/bitly/client.rb CHANGED
@@ -6,8 +6,6 @@ require 'json'
6
6
  module Bitly
7
7
  API_URL = 'http://api.bit.ly/'
8
8
  API_VERSION = '2.0.1'
9
- # login = 'philnash'
10
- # api_key = 'R_7776acc394294b2b0ad2c261a91c483d'
11
9
 
12
10
  def self.new(login, api_key)
13
11
  Bitly::Client.new(login,api_key)
@@ -30,7 +28,7 @@ module Bitly
30
28
  Bitly::Url.new(@login,@api_key,result)
31
29
  elsif input.is_a? Array
32
30
  request = create_url "shorten"
33
- request.query << "&" + input.map { |long_url| "longUrl=#{URI.encode(long_url)}" }.join("&") unless input.nil?
31
+ request.query << "&" + input.map { |long_url| "longUrl=#{CGI.escape(long_url)}" }.join("&") unless input.nil?
34
32
  result = get_result(request)
35
33
  input.map do |long_url|
36
34
  new_url = {:long_url => long_url}.merge result[long_url]
data/lib/bitly/utils.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'cgi'
2
+
1
3
  module Bitly
2
4
  module Utils
3
5
  private
@@ -31,8 +33,8 @@ module Bitly
31
33
  args = args.merge({:login => @login, :apiKey => @api_key, :version => API_VERSION})
32
34
  url = URI.join(API_URL,resource)
33
35
  long_urls = args.delete(:long_urls)
34
- url.query = args.map { |k,v| "%s=%s" % [URI.encode(k.to_s), URI.encode(v.to_s)] }.join("&")
35
- url.query << "&" + long_urls.map { |long_url| "longUrl=#{URI.encode(long_url)}" }.join("&") unless long_urls.nil?
36
+ url.query = args.map { |k,v| "%s=%s" % [CGI.escape(k.to_s), CGI.escape(v.to_s)] }.join("&")
37
+ url.query << "&" + long_urls.map { |long_url| "longUrl=#{CGI.escape(long_url)}" }.join("&") unless long_urls.nil?
36
38
  url
37
39
  end
38
40
 
data/lib/bitly/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Bitly
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.4'
3
3
  end
data/test/test_bitly.rb CHANGED
@@ -12,31 +12,35 @@ class TestBitly < Test::Unit::TestCase
12
12
  # not a good test, but it makes sure things are working for now.
13
13
  def test_returns_short_url
14
14
  url = @bitly.shorten("http://google.com")
15
- assert_equal url.class, Bitly::Url
16
- assert_equal url.long_url, "http://google.com"
17
- assert_equal url.short_url, "http://bit.ly/wQaT"
15
+ assert_kind_of Bitly::Url, url
16
+ assert_equal "http://google.com", url.long_url
17
+ assert_equal "http://bit.ly/wQaT", url.short_url
18
18
  urls = @bitly.shorten(["http://google.com","http://cnn.com"])
19
- assert_equal urls[0].long_url, "http://google.com"
20
- assert_equal urls[0].short_url, "http://bit.ly/wQaT"
19
+ assert_equal "http://google.com", urls[0].long_url
20
+ assert_equal "http://bit.ly/wQaT", urls[0].short_url
21
+ url = @bitly.shorten("http://www.google.com/search?hl=en&q=url&btnG=Google+Search&aq=f&oq=")
22
+ assert_kind_of Bitly::Url, url
23
+ assert_equal "http://www.google.com/search?hl=en&q=url&btnG=Google+Search&aq=f&oq=", url.long_url
24
+ assert_equal "http://bit.ly/NqK6i", url.short_url
21
25
  end
22
26
 
23
27
  def test_returns_a_long_url
24
28
  urls = @bitly.expand(["2bYgqR","1RmnUT"])
25
- assert_equal urls[0].class, Bitly::Url
26
- assert_equal urls[0].long_url, "http://cnn.com"
27
- assert_equal urls[0].hash, "2bYgqR"
28
- assert_equal urls[1].long_url, "http://google.com"
29
- assert_equal urls[1].hash, "1RmnUT"
29
+ assert_kind_of Bitly::Url, urls[0]
30
+ assert_equal "http://cnn.com", urls[0].long_url
31
+ assert_equal "2bYgqR", urls[0].hash
32
+ assert_equal "http://google.com", urls[1].long_url
33
+ assert_equal "1RmnUT", urls[1].hash
30
34
  url = @bitly.expand("http://bit.ly/wQaT")
31
- assert_equal url.class, Bitly::Url
32
- assert_equal url.short_url, "http://bit.ly/wQaT"
33
- assert_equal url.long_url, "http://google.com/"
34
- assert_equal url.hash, "wQaT"
35
+ assert_kind_of Bitly::Url, url
36
+ assert_equal "http://bit.ly/wQaT", url.short_url
37
+ assert_equal "http://google.com/", url.long_url
38
+ assert_equal "wQaT", url.hash
35
39
  url2 = @bitly.expand("wQaT")
36
- assert_equal url2.class, Bitly::Url
37
- assert_equal url2.hash, "wQaT"
38
- assert_equal url2.short_url, "http://bit.ly/wQaT"
39
- assert_equal url2.long_url, "http://google.com/"
40
+ assert_kind_of Bitly::Url, url2
41
+ assert_equal "wQaT", url2.hash
42
+ assert_equal "http://bit.ly/wQaT", url2.short_url
43
+ assert_equal "http://google.com/", url2.long_url
40
44
  end
41
45
 
42
46
  def test_returns_keyword_url
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: philnash-bitly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Phil Nash
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-13 00:00:00 -07:00
12
+ date: 2009-04-13 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency