googl-api 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.3
1
+ 0.2.4
data/googl-api.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{googl-api}
8
- s.version = "0.2.3"
8
+ s.version = "0.2.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["John Allen"]
12
- s.date = %q{2011-01-11}
12
+ s.date = %q{2011-01-13}
13
13
  s.description = %q{A very simple ruby wrapper for the goo.gl URL Shortening service}
14
14
  s.email = %q{john@threedogconsulting.com}
15
15
  s.extra_rdoc_files = [
@@ -4,7 +4,7 @@ module GooglApi
4
4
  API_URL = 'https://www.googleapis.com/urlshortener/'
5
5
  API_VERSION = 'v1'
6
6
 
7
- def self.new(api_key)
7
+ def self.new(api_key = nil)
8
8
  Client.new(api_key)
9
9
  end
10
10
 
@@ -14,29 +14,23 @@ module GooglApi
14
14
  base_uri "#{API_URL}#{API_VERSION}"
15
15
  headers 'Content-Type' => 'application/json; charset=utf-8'
16
16
 
17
- def initialize(api_key)
18
- @api_key = { :key => api_key }
17
+ def initialize(api_key = nil)
18
+ @api_key = { :key => api_key } unless api_key.blank?
19
19
  end
20
20
 
21
21
  def shorten(url)
22
22
  raise ArgumentError.new("A URL to shorten is required") if url.blank?
23
- load_respose(self.class.post('/url', :body => "{ \"longUrl\" => \"#{url}\" }"))
24
- # api key not working at this time
25
- # load_respose(self.class.post('/url', :query => @api_key, :body => "{ \"longUrl\" => \"#{url}\" }"))
23
+ load_respose(self.class.post('/url', :query => @api_key, :body => "{ \"longUrl\" => \"#{url}\" }"))
26
24
  end
27
25
 
28
26
  def expand(url)
29
27
  raise ArgumentError.new("A URL to expand is required") if url.blank?
30
- load_respose(self.class.get('/url', :query => { :shortUrl => url }))
31
- # api key not working at this time
32
- # load_respose(self.class.get('/url', :query => @api_key.merge({ :shortUrl => url })))
28
+ load_respose(self.class.get('/url', :query => @api_key.merge({ :shortUrl => url })))
33
29
  end
34
30
 
35
31
  def analytics(url, projection = "FULL")
36
32
  raise ArgumentError.new("A URL to check analytics on is required") if url.blank?
37
- load_respose(self.class.get('/url', :query => { :shortUrl => url, :projection => projection }))
38
- # api key not working at this time
39
- # load_respose(self.class.get('/url', :query => @api_key.merge({ :shortUrl => url, :projection => projection })))
33
+ load_respose(self.class.get('/url', :query => @api_key.merge({ :shortUrl => url, :projection => projection })))
40
34
  end
41
35
  private
42
36
  def load_respose(resp)
@@ -21,6 +21,9 @@ module GooglApi
21
21
  def long_url
22
22
  self.longUrl
23
23
  end
24
-
24
+
25
+ def qr_code
26
+ "#{short_url}.qr" unless short_url.blank?
27
+ end
25
28
  end
26
29
  end
data/test/helper.rb CHANGED
@@ -13,11 +13,11 @@ require 'shoulda'
13
13
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
14
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib', 'googl-api'))
15
15
  $LOAD_PATH.unshift(File.dirname(__FILE__))
16
- require 'httparty'
17
16
  require 'googl-api'
18
17
 
19
18
  class Test::Unit::TestCase
20
19
  def api_key
21
- 'test_key'
20
+ # 'test_key'
21
+ 'AIzaSyDIENPX6ZJoRFIS4Ix-ev5fOjRh8pNME9Y'
22
22
  end
23
23
  end
data/test/test_googl.rb CHANGED
@@ -26,6 +26,9 @@ class TestGoogl < Test::Unit::TestCase
26
26
  should "save the long url" do
27
27
  assert_equal "http://ruby-lang.org/", @url.long_url
28
28
  end
29
+ should "provide a qr code url" do
30
+ assert_equal "http://goo.gl/p2Jpa.qr", @url.qr_code
31
+ end
29
32
  end
30
33
  context "no links" do
31
34
  should "raise an ArgumentError" do
@@ -79,4 +82,20 @@ class TestGoogl < Test::Unit::TestCase
79
82
  end
80
83
  end
81
84
  end
85
+ context "using the googl-api client without api key" do
86
+ setup do
87
+ @client = GooglApi.new
88
+ end
89
+
90
+ context "shortening" do
91
+ context "a single link" do
92
+ setup do
93
+ @url = @client.shorten('http://ruby-lang.org/')
94
+ end
95
+ should "return a GooglApi::Response" do
96
+ assert_kind_of GooglApi::Response, @url
97
+ end
98
+ end
99
+ end
100
+ end
82
101
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 3
9
- version: 0.2.3
8
+ - 4
9
+ version: 0.2.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - John Allen
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-01-11 00:00:00 -05:00
17
+ date: 2011-01-13 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -126,7 +126,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
126
126
  requirements:
127
127
  - - ">="
128
128
  - !ruby/object:Gem::Version
129
- hash: 322120871034844753
129
+ hash: -2555399239044821738
130
130
  segments:
131
131
  - 0
132
132
  version: "0"