philnash-bitly 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,10 @@
1
+ === 0.1.2 / 2009-04-12
2
+
3
+ * 1 minor enhancement
4
+
5
+ * Allows to add a keyword for shortening urls
6
+
7
+
1
8
  === 0.1.1 / 2009-01-26
2
9
 
3
10
  * 1 bug fix
data/README.txt CHANGED
@@ -15,6 +15,7 @@ bitly = Bitly.new(username, api_key)
15
15
  You can then use that client to shorten or expand urls or return more information or statistics as so:
16
16
 
17
17
  bitly.shorten('http://www.google.com')
18
+ bitly.shorten('http://www.google.com', 'keyword') # returns a shortened url using the given keyword
18
19
  bitly.expand('wQaT')
19
20
  bitly.info('http://bit.ly/wQaT')
20
21
  bitly.stats('http://bit.ly/wQaT')
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.1"
5
+ s.version = "0.1.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{2009-01-26}
9
+ s.date = %q{2009-03-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
@@ -22,9 +22,9 @@ module Bitly
22
22
  @api_key = api_key
23
23
  end
24
24
 
25
- def shorten(input)
25
+ def shorten(input, keyword=nil)
26
26
  if input.is_a? String
27
- request = create_url "shorten", :longUrl => input
27
+ request = create_url "shorten", :longUrl => input, :keyword => keyword
28
28
  result = get_result(request)
29
29
  result = {:long_url => input}.merge result[input]
30
30
  Bitly::Url.new(@login,@api_key,result)
data/lib/bitly/url.rb CHANGED
@@ -7,6 +7,9 @@ module Bitly
7
7
 
8
8
  def initialize(login,api_key,obj=nil)
9
9
  unless obj.nil?
10
+
11
+ raise BitlyError.new(obj['errorMessage'],obj['errorCode'],'expand') if obj['statusCode'] == "ERROR"
12
+
10
13
  instance_variablise(obj, VARIABLES)
11
14
  @info = obj[:info] if obj[:info]
12
15
  @stats = obj[:stats] if obj[:stats]
data/lib/bitly/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Bitly
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
data/test/test_bitly.rb CHANGED
@@ -38,4 +38,23 @@ class TestBitly < Test::Unit::TestCase
38
38
  assert_equal url2.short_url, "http://bit.ly/wQaT"
39
39
  assert_equal url2.long_url, "http://google.com/"
40
40
  end
41
- end
41
+
42
+ def test_returns_keyword_url
43
+ #kind of ghetto test but we need it to be different every time
44
+ require 'digest/sha1'
45
+ keyword = Digest::SHA1.hexdigest(DateTime.now.to_s)
46
+
47
+ url = @bitly.shorten("http://google.com", keyword)
48
+ assert_equal url.short_keyword_url, "http://bit.ly/#{keyword}"
49
+ end
50
+
51
+ def test_returns_error_on_existing_keyword
52
+ keyword = 'apple'
53
+ assert_raise BitlyError do
54
+ @bitly.shorten("http://apple.com/itunes", keyword)
55
+ end
56
+ end
57
+
58
+
59
+
60
+ end
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.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Phil Nash
@@ -9,11 +9,12 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-26 00:00:00 -08:00
12
+ date: 2009-03-13 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json
17
+ type: :runtime
17
18
  version_requirement:
18
19
  version_requirements: !ruby/object:Gem::Requirement
19
20
  requirements: