googl-api 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +20 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +48 -0
- data/Rakefile +54 -0
- data/VERSION +1 -0
- data/googl.gemspec +70 -0
- data/init.rb +1 -0
- data/lib/googl-api.rb +2 -0
- data/lib/googl-api/client.rb +38 -0
- data/lib/googl-api/response.rb +26 -0
- data/test/helper.rb +18 -0
- data/test/test_googl.rb +7 -0
- metadata +150 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "shoulda", ">= 0"
|
10
|
+
gem "bundler", "~> 1.0.0"
|
11
|
+
gem "jeweler", "~> 1.5.2"
|
12
|
+
gem "rcov", ">= 0"
|
13
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
git (1.2.5)
|
5
|
+
jeweler (1.5.2)
|
6
|
+
bundler (~> 1.0.0)
|
7
|
+
git (>= 1.2.5)
|
8
|
+
rake
|
9
|
+
rake (0.8.7)
|
10
|
+
rcov (0.9.9)
|
11
|
+
shoulda (2.11.3)
|
12
|
+
|
13
|
+
PLATFORMS
|
14
|
+
ruby
|
15
|
+
|
16
|
+
DEPENDENCIES
|
17
|
+
bundler (~> 1.0.0)
|
18
|
+
jeweler (~> 1.5.2)
|
19
|
+
rcov
|
20
|
+
shoulda
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 John Allen
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
= googl-api
|
2
|
+
|
3
|
+
A very simple Ruby wrapper for the Google Url Shortener.
|
4
|
+
|
5
|
+
service - http://goo.gl/
|
6
|
+
api docs - http://code.google.com/apis/urlshortener/index.html
|
7
|
+
|
8
|
+
== INSTALLATION:
|
9
|
+
|
10
|
+
gem install googl-api
|
11
|
+
|
12
|
+
== USAGE:
|
13
|
+
|
14
|
+
Create a googl client using your API key:
|
15
|
+
|
16
|
+
googl = GooglApi.new(api_key)
|
17
|
+
|
18
|
+
Then use the client to shorten, extend or review the analytics for a URL.
|
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')
|
23
|
+
|
24
|
+
These methods will return a response object containing the short/long url and other values provide by the API
|
25
|
+
|
26
|
+
TODO: fix api key usage (broken in api?)
|
27
|
+
TODO: implement analytics object
|
28
|
+
TODO: write tests
|
29
|
+
|
30
|
+
== ACKNOWLEDGEMENTS
|
31
|
+
|
32
|
+
Code heavily inspired/influenced by philnash's bitly gem https://github.com/philnash/bitly
|
33
|
+
|
34
|
+
== Contributing to googl-api
|
35
|
+
|
36
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
37
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
38
|
+
* Fork the project
|
39
|
+
* Start a feature/bugfix branch
|
40
|
+
* Commit and push until you are happy with your contribution
|
41
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
42
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
43
|
+
|
44
|
+
== Copyright
|
45
|
+
|
46
|
+
Copyright (c) 2011 John Allen. See LICENSE.txt for
|
47
|
+
further details.
|
48
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "googl-api"
|
16
|
+
gem.homepage = "http://github.com/johnallen3d/googl-api"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{A ruby wrapper for the goo.gl URL Shortner}
|
19
|
+
gem.description = %Q{A very simple ruby wrapper for the goo.gl URL Shortening service}
|
20
|
+
gem.email = "john@threedogconsulting.com"
|
21
|
+
gem.authors = ["John Allen"]
|
22
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
25
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
|
+
gem.add_dependency "httparty", ">= 0.6.1"
|
27
|
+
end
|
28
|
+
Jeweler::RubygemsDotOrgTasks.new
|
29
|
+
|
30
|
+
require 'rake/testtask'
|
31
|
+
Rake::TestTask.new(:test) do |test|
|
32
|
+
test.libs << 'lib' << 'test'
|
33
|
+
test.pattern = 'test/**/test_*.rb'
|
34
|
+
test.verbose = true
|
35
|
+
end
|
36
|
+
|
37
|
+
require 'rcov/rcovtask'
|
38
|
+
Rcov::RcovTask.new do |test|
|
39
|
+
test.libs << 'test'
|
40
|
+
test.pattern = 'test/**/test_*.rb'
|
41
|
+
test.verbose = true
|
42
|
+
end
|
43
|
+
|
44
|
+
task :default => :test
|
45
|
+
|
46
|
+
require 'rake/rdoctask'
|
47
|
+
Rake::RDocTask.new do |rdoc|
|
48
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
49
|
+
|
50
|
+
rdoc.rdoc_dir = 'rdoc'
|
51
|
+
rdoc.title = "googl-api #{version}"
|
52
|
+
rdoc.rdoc_files.include('README*')
|
53
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
54
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/googl.gemspec
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{googl}
|
8
|
+
s.version = "0.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["John Allen"]
|
12
|
+
s.date = %q{2011-01-11}
|
13
|
+
s.description = %q{A very simple ruby wrapper for the goo.gl URL Shortening service}
|
14
|
+
s.email = %q{john@threedogconsulting.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"Gemfile",
|
22
|
+
"Gemfile.lock",
|
23
|
+
"LICENSE.txt",
|
24
|
+
"README.rdoc",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"googl.gemspec",
|
28
|
+
"init.rb",
|
29
|
+
"lib/googl.rb",
|
30
|
+
"lib/googl/client.rb",
|
31
|
+
"lib/googl/response.rb",
|
32
|
+
"test/helper.rb",
|
33
|
+
"test/test_googl.rb"
|
34
|
+
]
|
35
|
+
s.homepage = %q{http://github.com/johnallen3d/googl}
|
36
|
+
s.licenses = ["MIT"]
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
s.rubygems_version = %q{1.3.7}
|
39
|
+
s.summary = %q{A ruby wrapper for the goo.gl URL Shortner}
|
40
|
+
s.test_files = [
|
41
|
+
"test/helper.rb",
|
42
|
+
"test/test_googl.rb"
|
43
|
+
]
|
44
|
+
|
45
|
+
if s.respond_to? :specification_version then
|
46
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
47
|
+
s.specification_version = 3
|
48
|
+
|
49
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
50
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
51
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
52
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
53
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
54
|
+
s.add_runtime_dependency(%q<httparty>, [">= 0"])
|
55
|
+
else
|
56
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
57
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
58
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
59
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
60
|
+
s.add_dependency(%q<httparty>, [">= 0"])
|
61
|
+
end
|
62
|
+
else
|
63
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
64
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
65
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
66
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
67
|
+
s.add_dependency(%q<httparty>, [">= 0"])
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'googl-api'
|
data/lib/googl-api.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
|
3
|
+
module GooglApi
|
4
|
+
API_URL = 'https://www.googleapis.com/urlshortener/'
|
5
|
+
API_VERSION = 'v1'
|
6
|
+
|
7
|
+
def self.new(api_key)
|
8
|
+
Client.new(api_key)
|
9
|
+
end
|
10
|
+
|
11
|
+
class Client
|
12
|
+
include HTTParty
|
13
|
+
|
14
|
+
base_uri "#{API_URL}#{API_VERSION}"
|
15
|
+
headers 'Content-Type' => 'application/json; charset=utf-8'
|
16
|
+
|
17
|
+
def initialize(api_key)
|
18
|
+
@api_key = { :key => api_key }
|
19
|
+
end
|
20
|
+
|
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)
|
24
|
+
end
|
25
|
+
|
26
|
+
def expand(url)
|
27
|
+
GooglApi::Response.new(self.class.get('/url', :query => { :shortUrl => url }).parsed_response)
|
28
|
+
# api key not working at this time
|
29
|
+
# GooglApi::Response.new(self.class.get('/url', :query => @api_key.merge({ :shortUrl => url })).parsed_response)
|
30
|
+
end
|
31
|
+
|
32
|
+
def analytics(url, projection = "FULL")
|
33
|
+
GooglApi::Response.new(self.class.get('/url', :query => { :shortUrl => url, :projection => projection }).parsed_response)
|
34
|
+
# 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
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module GooglApi
|
2
|
+
class Response
|
3
|
+
attr_accessor :kind, :id, :longUrl, :status, :created, :analytics, :raw
|
4
|
+
|
5
|
+
def initialize args
|
6
|
+
# load valuse passed in hash
|
7
|
+
args.each do |k,v|
|
8
|
+
instance_variable_set("@#{k}", v) unless v.nil?
|
9
|
+
end
|
10
|
+
|
11
|
+
# retain the hash for further inspection
|
12
|
+
self.raw = args
|
13
|
+
end
|
14
|
+
|
15
|
+
# provide helper method for short url (returned as id)
|
16
|
+
def short_url
|
17
|
+
self.id
|
18
|
+
end
|
19
|
+
|
20
|
+
# proive ruby like method for longUrl
|
21
|
+
def long_url
|
22
|
+
self.longUrl
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'googl'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
data/test/test_googl.rb
ADDED
metadata
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: googl-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- John Allen
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-01-11 00:00:00 -05:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: shoulda
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
type: :development
|
31
|
+
prerelease: false
|
32
|
+
version_requirements: *id001
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: bundler
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
segments:
|
41
|
+
- 1
|
42
|
+
- 0
|
43
|
+
- 0
|
44
|
+
version: 1.0.0
|
45
|
+
type: :development
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: jeweler
|
50
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 1
|
57
|
+
- 5
|
58
|
+
- 2
|
59
|
+
version: 1.5.2
|
60
|
+
type: :development
|
61
|
+
prerelease: false
|
62
|
+
version_requirements: *id003
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: rcov
|
65
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
segments:
|
71
|
+
- 0
|
72
|
+
version: "0"
|
73
|
+
type: :development
|
74
|
+
prerelease: false
|
75
|
+
version_requirements: *id004
|
76
|
+
- !ruby/object:Gem::Dependency
|
77
|
+
name: httparty
|
78
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
segments:
|
84
|
+
- 0
|
85
|
+
- 6
|
86
|
+
- 1
|
87
|
+
version: 0.6.1
|
88
|
+
type: :runtime
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *id005
|
91
|
+
description: A very simple ruby wrapper for the goo.gl URL Shortening service
|
92
|
+
email: john@threedogconsulting.com
|
93
|
+
executables: []
|
94
|
+
|
95
|
+
extensions: []
|
96
|
+
|
97
|
+
extra_rdoc_files:
|
98
|
+
- LICENSE.txt
|
99
|
+
- README.rdoc
|
100
|
+
files:
|
101
|
+
- .document
|
102
|
+
- Gemfile
|
103
|
+
- Gemfile.lock
|
104
|
+
- LICENSE.txt
|
105
|
+
- README.rdoc
|
106
|
+
- Rakefile
|
107
|
+
- VERSION
|
108
|
+
- googl.gemspec
|
109
|
+
- init.rb
|
110
|
+
- lib/googl-api.rb
|
111
|
+
- lib/googl-api/client.rb
|
112
|
+
- lib/googl-api/response.rb
|
113
|
+
- test/helper.rb
|
114
|
+
- test/test_googl.rb
|
115
|
+
has_rdoc: true
|
116
|
+
homepage: http://github.com/johnallen3d/googl-api
|
117
|
+
licenses:
|
118
|
+
- MIT
|
119
|
+
post_install_message:
|
120
|
+
rdoc_options: []
|
121
|
+
|
122
|
+
require_paths:
|
123
|
+
- lib
|
124
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
125
|
+
none: false
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
hash: 1139673323044054768
|
130
|
+
segments:
|
131
|
+
- 0
|
132
|
+
version: "0"
|
133
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
|
+
none: false
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
segments:
|
139
|
+
- 0
|
140
|
+
version: "0"
|
141
|
+
requirements: []
|
142
|
+
|
143
|
+
rubyforge_project:
|
144
|
+
rubygems_version: 1.3.7
|
145
|
+
signing_key:
|
146
|
+
specification_version: 3
|
147
|
+
summary: A ruby wrapper for the goo.gl URL Shortner
|
148
|
+
test_files:
|
149
|
+
- test/helper.rb
|
150
|
+
- test/test_googl.rb
|