bitly 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,9 @@
1
+ === 0.4.0 / 2009-12-19
2
+
3
+ * 1 major enhancement
4
+
5
+ * support for j.mp urls
6
+
1
7
  === 0.3.2 / 2009-11-15
2
8
 
3
9
  * 1 bug fix
data/README.txt CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  == DESCRIPTION:
4
4
 
5
- A Ruby API for bit.ly
5
+ A Ruby API for http://bit.ly (and now http://j.mp)
6
6
 
7
7
  http://code.google.com/p/bitly-api/wiki/ApiDocumentation
8
8
 
@@ -32,6 +32,8 @@ u = bitly.shorten('http://www.google.com') #=> Bitly::Url
32
32
 
33
33
  u.long_url #=> "http://www.google.com"
34
34
  u.short_url #=> "http://bit.ly/Ywd1"
35
+ u.bitly_url #=> "http://bit.ly/Ywd1"
36
+ u.jmp_url #=> "http://j.mp/Ywd1"
35
37
  u.user_hash #=> "Ywd1"
36
38
  u.hash #=> "2V6CFi"
37
39
  u.info #=> a ruby hash of the JSON returned from the API
data/Rakefile CHANGED
@@ -1,12 +1,8 @@
1
- # -*- ruby -*-
2
-
3
1
  require 'rubygems'
4
2
  require 'rake'
5
3
  require 'echoe'
6
4
  require './lib/bitly.rb'
7
5
 
8
- # modified by coryosborn to remove native JSON dependency
9
-
10
6
  Echoe.new('bitly', Bitly::VERSION) do |p|
11
7
  p.description = "Use the bit.ly API to shorten or expand URLs"
12
8
  p.url = "http://github.com/philnash/bitly"
@@ -14,6 +10,4 @@ Echoe.new('bitly', Bitly::VERSION) do |p|
14
10
  p.email = "philnash@gmail.com"
15
11
  p.extra_deps = [['crack', '>= 0.1.1']]
16
12
  p.development_dependencies = []
17
- end
18
-
19
- # vim: syntax=Ruby
13
+ end
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{bitly}
5
- s.version = "0.3.2"
5
+ s.version = "0.4.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 = %q{2009-11-15}
9
+ s.date = %q{2009-12-19}
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"]
@@ -40,7 +40,7 @@ module Bitly
40
40
 
41
41
  def expand(input)
42
42
  if input.is_a? String
43
- if input.include? "bit.ly/"
43
+ if input.include?('bit.ly/') || input.include?('j.mp/')
44
44
  hash = create_hash_from_url(input)
45
45
  request = create_url "expand", :hash => hash
46
46
  result = get_result(request)
@@ -117,34 +117,4 @@ class BitlyError < StandardError
117
117
  @code = code
118
118
  super("#{msg} - '#{code}'")
119
119
  end
120
- end
121
-
122
-
123
- # How it should work
124
- # ==================
125
- # bitly = Bitly::Base.new('philnash','R_7776acc394294b2b0ad2c261a91c483d')
126
- # bitly.shorten("http://www.google.com")
127
- # #=> Bitly::Url
128
- # bitly.shorten(["http://www.google.com","http://cnn.com"])
129
- # #=> [Bitly::Url,Bitly::Url]
130
- #
131
- # bitly.expand("http://bit.ly/wIRm")
132
- # #=> Bitly::Url
133
- # bitly.expand("wIRm")
134
- # #=> Bitly::Url
135
- # bitly.expand(["wIRm","sdfsd"])
136
- # #=> [Bitly::Url,Bitly::Url]
137
- #
138
- # bitly.info("http://bit.ly/wIRm") || bitly.info("wIRm")
139
- # #=> b = Bitly::Url
140
- # #=> b.info #=> hash of data back from info
141
- # bitly.info(['wIRm','qsads'])
142
- # #=> [Bitly::Url, Bitly::Url]
143
- # also, with any url = Bitly::Url
144
- # url.info #=> hash of info data
145
-
146
- # bitly.stats("http://bit.ly/wIRm") || bitly.stats("wIRm")
147
- # #=> b = Bitly::Url
148
- # #=> b.stats #=> hash of stats
149
- # also, any url = Bitly::Url
150
- # url.stats #=> hash of stats
120
+ end
@@ -92,6 +92,13 @@ module Bitly
92
92
  end
93
93
  end
94
94
 
95
+ def bitly_url
96
+ @short_url.nil? ? nil : @short_url.gsub(/j\.mp/,'bit.ly')
97
+ end
98
+
99
+ def jmp_url
100
+ @short_url.nil? ? nil : @short_url.gsub(/bit\.ly/,'j.mp')
101
+ end
95
102
  end
96
103
 
97
104
  end
@@ -11,7 +11,7 @@ module Bitly
11
11
  end
12
12
 
13
13
  def create_hash_from_url(url)
14
- url.gsub(/^.*bit.ly\//,'')
14
+ url.gsub(/^.*(bit\.ly|j\.mp)\//,'')
15
15
  end
16
16
 
17
17
  def attr_define(k,v)
@@ -1,3 +1,3 @@
1
1
  module Bitly
2
- VERSION = '0.3.2'
2
+ VERSION = '0.4.0'
3
3
  end
@@ -23,6 +23,10 @@ class TestClient < Test::Unit::TestCase
23
23
  end
24
24
  should "return a short bitly url" do
25
25
  assert_equal "http://bit.ly/15DlK", @url.short_url
26
+ assert_equal "http://bit.ly/15DlK", @url.bitly_url
27
+ end
28
+ should "return a short jmp url" do
29
+ assert_equal "http://j.mp/15DlK", @url.jmp_url
26
30
  end
27
31
  should "save the long url" do
28
32
  assert_equal "http://cnn.com", @url.long_url
@@ -73,7 +77,7 @@ class TestClient < Test::Unit::TestCase
73
77
  assert_equal "http://bit.ly/31IqMl", @url.short_url
74
78
  end
75
79
  end
76
- context "a short url" do
80
+ context "a short bitly url" do
77
81
  setup do
78
82
  stub_get(/^http:\/\/api.bit.ly\/expand\?.*hash=31IqMl.*$/,"expand_cnn.json")
79
83
  @url = @bitly.expand("http://bit.ly/31IqMl")
@@ -87,8 +91,32 @@ class TestClient < Test::Unit::TestCase
87
91
  should "save the hash" do
88
92
  assert_equal "31IqMl", @url.hash
89
93
  end
90
- should "save the short url" do
91
- assert_equal "http://bit.ly/31IqMl", @url.short_url
94
+ should "save the bitly url" do
95
+ assert_equal "http://bit.ly/31IqMl", @url.bitly_url
96
+ end
97
+ should "save a jmp url" do
98
+ assert_equal "http://j.mp/31IqMl", @url.jmp_url
99
+ end
100
+ end
101
+ context "a short jmp url" do
102
+ setup do
103
+ stub_get(/^http:\/\/api.bit.ly\/expand\?.*hash=31IqMl.*$/,"expand_cnn.json")
104
+ @url = @bitly.expand("http://j.mp/31IqMl")
105
+ end
106
+ should "return a Bitly::Url" do
107
+ assert_kind_of Bitly::Url, @url
108
+ end
109
+ should "return the expanded url" do
110
+ assert_equal "http://cnn.com/", @url.long_url
111
+ end
112
+ should "save the hash" do
113
+ assert_equal "31IqMl", @url.hash
114
+ end
115
+ should "save the bitly url" do
116
+ assert_equal "http://bit.ly/31IqMl", @url.bitly_url
117
+ end
118
+ should "save a jmp url" do
119
+ assert_equal "http://j.mp/31IqMl", @url.jmp_url
92
120
  end
93
121
  end
94
122
  context "multiple hashes" do
@@ -22,6 +22,11 @@ class TestUrl < Test::Unit::TestCase
22
22
  should "return a short url" do
23
23
  assert_equal "http://bit.ly/15DlK", @url.shorten
24
24
  end
25
+ should "create bitly and jmp urls" do
26
+ @url.shorten
27
+ assert_equal "http://bit.ly/15DlK", @url.bitly_url
28
+ assert_equal "http://j.mp/15DlK", @url.jmp_url
29
+ end
25
30
  end
26
31
  context "with no long url" do
27
32
  setup do
@@ -8,9 +8,12 @@ class TestUtils < Test::Unit::TestCase
8
8
  should "underscore a word" do
9
9
  assert_equal "hello_world", underscore("HelloWorld")
10
10
  end
11
- should "create a hash from a short url" do
11
+ should "create a hash from a bitly url" do
12
12
  assert_equal "hello", create_hash_from_url("http://bit.ly/hello")
13
13
  end
14
+ should "create a hash from a jmp url" do
15
+ assert_equal "hello", create_hash_from_url("http://j.mp/hello")
16
+ end
14
17
  end
15
18
 
16
19
  context "class utils" do
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.3.2
4
+ version: 0.4.0
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-11-15 00:00:00 +00:00
12
+ date: 2009-12-19 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency