googl-api 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,30 +2,30 @@
2
2
 
3
3
  A very simple Ruby wrapper for the Google Url Shortener.
4
4
 
5
- service - http://goo.gl/
6
- api docs - http://code.google.com/apis/urlshortener/index.html
5
+ * service - http://goo.gl/
6
+ * api docs - http://code.google.com/apis/urlshortener/index.html
7
7
 
8
8
  == INSTALLATION:
9
9
 
10
- gem install googl-api
10
+ gem install googl-api
11
11
 
12
12
  == USAGE:
13
13
 
14
14
  Create a googl client using your API key:
15
15
 
16
- googl = GooglApi.new(api_key)
16
+ googl = GooglApi.new(api_key)
17
17
 
18
18
  Then use the client to shorten, extend or review the analytics for a URL.
19
19
 
20
- googl.shorten('http://www.google.com')
21
- googl.expand('http://goo.gl/fbsS')
22
- googl.analytics('http://goo.gl/fbsS') or googl.analytics('http://goo.gl/fbsS', 'FULL')
20
+ googl.shorten('http://www.google.com')
21
+ googl.expand('http://goo.gl/fbsS')
22
+ googl.analytics('http://goo.gl/fbsS') or googl.analytics('http://goo.gl/fbsS', 'FULL')
23
23
 
24
24
  These methods will return a response object containing the short/long url and other values provide by the API
25
25
 
26
- TODO: fix api key usage (broken in api?)
27
- TODO: implement analytics object
28
- TODO: write tests
26
+ * TODO: fix api key usage (broken in api?)
27
+ * TODO: implement analytics object
28
+ * TODO: write tests
29
29
 
30
30
  == ACKNOWLEDGEMENTS
31
31
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
@@ -4,8 +4,8 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{googl}
8
- s.version = "0.0.0"
7
+ s.name = %q{googl-api}
8
+ s.version = "0.2.0"
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"]
@@ -24,15 +24,15 @@ Gem::Specification.new do |s|
24
24
  "README.rdoc",
25
25
  "Rakefile",
26
26
  "VERSION",
27
- "googl.gemspec",
27
+ "googl-api.gemspec",
28
28
  "init.rb",
29
- "lib/googl.rb",
30
- "lib/googl/client.rb",
31
- "lib/googl/response.rb",
29
+ "lib/googl-api.rb",
30
+ "lib/googl-api/client.rb",
31
+ "lib/googl-api/response.rb",
32
32
  "test/helper.rb",
33
33
  "test/test_googl.rb"
34
34
  ]
35
- s.homepage = %q{http://github.com/johnallen3d/googl}
35
+ s.homepage = %q{http://github.com/johnallen3d/googl-api}
36
36
  s.licenses = ["MIT"]
37
37
  s.require_paths = ["lib"]
38
38
  s.rubygems_version = %q{1.3.7}
@@ -51,20 +51,20 @@ Gem::Specification.new do |s|
51
51
  s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
52
52
  s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
53
53
  s.add_development_dependency(%q<rcov>, [">= 0"])
54
- s.add_runtime_dependency(%q<httparty>, [">= 0"])
54
+ s.add_runtime_dependency(%q<httparty>, [">= 0.6.1"])
55
55
  else
56
56
  s.add_dependency(%q<shoulda>, [">= 0"])
57
57
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
58
58
  s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
59
59
  s.add_dependency(%q<rcov>, [">= 0"])
60
- s.add_dependency(%q<httparty>, [">= 0"])
60
+ s.add_dependency(%q<httparty>, [">= 0.6.1"])
61
61
  end
62
62
  else
63
63
  s.add_dependency(%q<shoulda>, [">= 0"])
64
64
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
65
65
  s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
66
66
  s.add_dependency(%q<rcov>, [">= 0"])
67
- s.add_dependency(%q<httparty>, [">= 0"])
67
+ s.add_dependency(%q<httparty>, [">= 0.6.1"])
68
68
  end
69
69
  end
70
70
 
@@ -19,20 +19,35 @@ module GooglApi
19
19
  end
20
20
 
21
21
  def shorten(url)
22
- GooglApi::Response.new(self.class.post('/url', :body => "{ \"longUrl\" => \"#{url}\" }").parsed_response)
23
- # GooglApi::Response.new(self.class.post('/url', :query => @api_key, :body => "{ \"longUrl\" => \"#{url}\" }").parsed_response)
22
+ load_respose(self.class.post('/url', :body => "{ \"longUrl\" => \"#{url}\" }"))
23
+ # api key not working at this time
24
+ # load_respose(self.class.post('/url', :query => @api_key, :body => "{ \"longUrl\" => \"#{url}\" }"))
24
25
  end
25
26
 
26
27
  def expand(url)
27
- GooglApi::Response.new(self.class.get('/url', :query => { :shortUrl => url }).parsed_response)
28
+ load_respose(self.class.get('/url', :query => { :shortUrl => url }))
28
29
  # api key not working at this time
29
- # GooglApi::Response.new(self.class.get('/url', :query => @api_key.merge({ :shortUrl => url })).parsed_response)
30
+ # load_respose(self.class.get('/url', :query => @api_key.merge({ :shortUrl => url })))
30
31
  end
31
32
 
32
33
  def analytics(url, projection = "FULL")
33
- GooglApi::Response.new(self.class.get('/url', :query => { :shortUrl => url, :projection => projection }).parsed_response)
34
+ load_respose(self.class.get('/url', :query => { :shortUrl => url, :projection => projection }))
34
35
  # api key not working at this time
35
- # GooglApi::Response.new(self.class.get('/url', :query => @api_key.merge({ :shortUrl => url, :projection => projection })).parsed_response)
36
+ # load_respose(self.class.get('/url', :query => @api_key.merge({ :shortUrl => url, :projection => projection })))
37
+ end
38
+ private
39
+ def load_respose(resp)
40
+ raise GooglError.new(resp.message, resp.code) if resp.code != 200
41
+ GooglApi::Response.new(resp.parsed_response)
42
+ end
43
+ end
44
+
45
+ class GooglError < StandardError
46
+ attr_reader :code
47
+ alias :msg :message
48
+ def initialize(msg, code)
49
+ @code = code
50
+ super("#{msg} - '#{code}'")
36
51
  end
37
52
  end
38
53
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
7
+ - 2
8
8
  - 0
9
- version: 0.1.0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - John Allen
@@ -105,7 +105,7 @@ files:
105
105
  - README.rdoc
106
106
  - Rakefile
107
107
  - VERSION
108
- - googl.gemspec
108
+ - googl-api.gemspec
109
109
  - init.rb
110
110
  - lib/googl-api.rb
111
111
  - lib/googl-api/client.rb
@@ -126,7 +126,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
126
126
  requirements:
127
127
  - - ">="
128
128
  - !ruby/object:Gem::Version
129
- hash: 1139673323044054768
129
+ hash: -1516370935058131756
130
130
  segments:
131
131
  - 0
132
132
  version: "0"