google_url_shortner 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.redcar/tags ADDED
@@ -0,0 +1 @@
1
+ 1294830035
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "http://rubygems.org"
2
+
3
+ group :development do
4
+ gem "rspec", "~> 2.3.0"
5
+ gem "bundler", "~> 1.0.0"
6
+ gem "jeweler", "~> 1.5.2"
7
+ gem "rcov", ">= 0"
8
+ gem "fakeweb", "~> 1.3.0"
9
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,30 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.2)
5
+ fakeweb (1.3.0)
6
+ git (1.2.5)
7
+ jeweler (1.5.2)
8
+ bundler (~> 1.0.0)
9
+ git (>= 1.2.5)
10
+ rake
11
+ rake (0.8.7)
12
+ rcov (0.9.9)
13
+ rspec (2.3.0)
14
+ rspec-core (~> 2.3.0)
15
+ rspec-expectations (~> 2.3.0)
16
+ rspec-mocks (~> 2.3.0)
17
+ rspec-core (2.3.1)
18
+ rspec-expectations (2.3.0)
19
+ diff-lcs (~> 1.1.2)
20
+ rspec-mocks (2.3.0)
21
+
22
+ PLATFORMS
23
+ ruby
24
+
25
+ DEPENDENCIES
26
+ bundler (~> 1.0.0)
27
+ fakeweb (~> 1.3.0)
28
+ jeweler (~> 1.5.2)
29
+ rcov
30
+ rspec (~> 2.3.0)
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2010 Zigotto®. http://www.zigotto.com.br
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,17 @@
1
+ == google_url_shortner
2
+
3
+ Client Ruby pour accèder à l'API Google URL Shortener.
4
+
5
+ == Installation
6
+
7
+ gem install google_url_shortner
8
+
9
+ == Utilisation
10
+
11
+ require "google_url_shortner"
12
+
13
+ client = Google::Shortner.new("http://www.google.com")
14
+
15
+ puts client.short_url
16
+
17
+ ==
data/Rakefile ADDED
@@ -0,0 +1,50 @@
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 = "google_url_shortner"
16
+ gem.homepage = "http://github.com/hkairi/google_url_shortner"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{Client Ruby pour accèder à l'API Google URL Shortener.}
19
+ gem.description = %Q{Client Ruby pour accèder à l'API Google URL Shortener.}
20
+ gem.email = "hassanemoustapha@gmail.com"
21
+ gem.authors = ["Hassane Moustapha"]
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_dependency "httparty", ">= 0.6.1"
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ spec.rspec_opts = %w(-fp --color)
33
+ end
34
+
35
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
36
+ spec.pattern = 'spec/**/*_spec.rb'
37
+ spec.rcov = true
38
+ end
39
+
40
+ task :default => :spec
41
+
42
+ require 'rake/rdoctask'
43
+ Rake::RDocTask.new do |rdoc|
44
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
45
+
46
+ rdoc.rdoc_dir = 'rdoc'
47
+ rdoc.title = "google_url_shortner #{version}"
48
+ rdoc.rdoc_files.include('README*')
49
+ rdoc.rdoc_files.include('lib/**/*.rb')
50
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
@@ -0,0 +1,73 @@
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{google_url_shortner}
8
+ s.version = "0.1.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Hassane Moustapha"]
12
+ s.date = %q{2011-01-12}
13
+ s.description = %q{Client Ruby pour accèder à l'API Google URL Shortener.}
14
+ s.email = %q{hassanemoustapha@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "README.rdoc"
17
+ ]
18
+ s.files = [
19
+ "Gemfile",
20
+ "Gemfile.lock",
21
+ "MIT-LICENSE",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "googl.gemspec",
26
+ "lib/google_url_shortner.rb",
27
+ "lib/google/expander.rb",
28
+ "lib/google/request.rb",
29
+ "lib/google/shortner.rb",
30
+ "spec/expand_spec.rb",
31
+ "spec/fixtures/expand.json",
32
+ "spec/fixtures/shorten.json",
33
+ "spec/shorten_spec.rb",
34
+ "spec/spec_helper.rb"
35
+ ]
36
+ s.homepage = %q{http://github.com/hkairi/google_url_shortner}
37
+ s.licenses = ["MIT"]
38
+ s.require_paths = ["lib"]
39
+ s.rubygems_version = %q{1.4.2}
40
+ s.summary = %q{Client Ruby pour accèder à l'API Google URL Shortener.}
41
+ s.test_files = [
42
+ "spec/expand_spec.rb",
43
+ "spec/shorten_spec.rb",
44
+ "spec/spec_helper.rb"
45
+ ]
46
+
47
+ if s.respond_to? :specification_version then
48
+ s.specification_version = 3
49
+
50
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
51
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
52
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
53
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
54
+ s.add_development_dependency(%q<rcov>, [">= 0"])
55
+ s.add_development_dependency(%q<fakeweb>, ["~> 1.3.0"])
56
+ s.add_runtime_dependency(%q<httparty>, [">= 0.6.1"])
57
+ else
58
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
59
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
60
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
61
+ s.add_dependency(%q<rcov>, [">= 0"])
62
+ s.add_dependency(%q<fakeweb>, ["~> 1.3.0"])
63
+ s.add_dependency(%q<httparty>, [">= 0.6.1"])
64
+ end
65
+ else
66
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
67
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
68
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
69
+ s.add_dependency(%q<rcov>, [">= 0"])
70
+ s.add_dependency(%q<fakeweb>, ["~> 1.3.0"])
71
+ s.add_dependency(%q<httparty>, [">= 0.6.1"])
72
+ end
73
+ end
@@ -0,0 +1,18 @@
1
+ module Google
2
+
3
+ class Expander
4
+
5
+ attr_accessor :long_url
6
+
7
+ def initialize(short_url)
8
+ rep = Request.get("/urlshortener/v1/url?shortUrl=#{short_url}")
9
+ if rep.code == 200
10
+ self.long_url = rep['longUrl']
11
+ else
12
+ rep.response
13
+ end
14
+ end
15
+
16
+ end
17
+
18
+ end
@@ -0,0 +1,6 @@
1
+ class Request
2
+ include HTTParty
3
+ base_uri 'https://www.googleapis.com'
4
+ headers 'Content-Type' => 'application/json'
5
+ headers "Content-length" => "0"
6
+ end
@@ -0,0 +1,20 @@
1
+ module Google
2
+
3
+ class Shortner
4
+
5
+ attr_accessor :short_url, :long_url
6
+
7
+ def initialize(long_url)
8
+ options = {"longUrl" => long_url}.inspect
9
+ resp = Request.post('/urlshortener/v1/url', :body => options)
10
+ if resp.code == 200
11
+ self.short_url = resp['id']
12
+ self.long_url = resp['longUrl']
13
+ else
14
+ resp.response
15
+ end
16
+ end
17
+
18
+ end
19
+
20
+ end
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'httparty'
3
+
4
+ require 'google/request'
5
+ require 'google/shortner'
6
+ require 'google/expander'
7
+
8
+ module Google
9
+
10
+ def self.shorten(url)
11
+ Google::Shortner.new(url)
12
+ end
13
+
14
+ def self.expand(url)
15
+ Google::Expander.new(url)
16
+ end
17
+
18
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe Googl::Expand do
4
+
5
+ before :each do
6
+ fake_urls
7
+ end
8
+
9
+ context "when expand any goo.gl short URL" do
10
+
11
+ it { Googl.should respond_to(:expand) }
12
+
13
+ subject { Googl.expand('http://goo.gl/7lob') }
14
+
15
+ describe "#long_url" do
16
+ it "should return a long url" do
17
+ subject.long_url.should == 'http://jlopes.zigotto.com.br/'
18
+ end
19
+ end
20
+
21
+ end
22
+
23
+
24
+ end
@@ -0,0 +1,18 @@
1
+ HTTP/1.1 200 OK
2
+ ETag: "EEZ1AD443JkEgW3KJFaymzTd26A/wKW1RiLjLbyUh3AbmrhLHKj0R24"
3
+ Expires: Tue, 11 Jan 2011 21:49:04 GMT
4
+ Date: Tue, 11 Jan 2011 21:44:04 GMT
5
+ Cache-Control: public, max-age=300, must-revalidate, no-transform
6
+ Content-Type: application/json; charset=UTF-8
7
+ X-Content-Type-Options: nosniff
8
+ X-Frame-Options: SAMEORIGIN
9
+ X-XSS-Protection: 1; mode=block
10
+ Server: GSE
11
+ Transfer-Encoding: chunked
12
+
13
+ {
14
+ "kind": "urlshortener#url",
15
+ "id": "http://goo.gl/7lob",
16
+ "longUrl": "http://jlopes.zigotto.com.br/",
17
+ "status": "OK"
18
+ }
@@ -0,0 +1,18 @@
1
+ HTTP/1.1 200 OK
2
+ ETag: "EEZ1AD443JkEgW3KJFaymzTd26A/1axClUUG_6eCdLbWHvqnOKYu85E"
3
+ Cache-Control: no-cache, no-store, max-age=0, must-revalidate
4
+ Pragma: no-cache
5
+ Expires: Fri, 01 Jan 1990 00:00:00 GMT
6
+ Date: Tue, 11 Jan 2011 21:26:33 GMT
7
+ Content-Type: application/json; charset=UTF-8
8
+ X-Content-Type-Options: nosniff
9
+ X-Frame-Options: SAMEORIGIN
10
+ X-XSS-Protection: 1; mode=block
11
+ Server: GSE
12
+ Transfer-Encoding: chunked
13
+
14
+ {
15
+ "kind": "urlshortener#url",
16
+ "id": "http://goo.gl/ump4S",
17
+ "longUrl": "http://www.zigotto.com/"
18
+ }
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe Googl::Shorten do
4
+
5
+ before :each do
6
+ fake_urls
7
+ end
8
+
9
+ context "when request new short url" do
10
+
11
+ it { Googl.should respond_to(:shorten) }
12
+
13
+ subject { Googl.shorten('http://www.zigotto.com') }
14
+
15
+ describe "#short_url" do
16
+ it "should return a short URL" do
17
+ subject.short_url.should == 'http://goo.gl/ump4S'
18
+ end
19
+ end
20
+
21
+ describe "#long_url" do
22
+ it "should return a long url" do
23
+ subject.long_url.should == 'http://www.zigotto.com/'
24
+ end
25
+ end
26
+
27
+ end
28
+
29
+ end
@@ -0,0 +1,27 @@
1
+ require "rubygems"
2
+ require "rspec"
3
+ require 'fakeweb'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__)))
6
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
7
+
8
+ require 'googl'
9
+
10
+ def load_fixture(name)
11
+ File.join(File.expand_path(File.dirname(__FILE__)), '/fixtures', name)
12
+ end
13
+
14
+ def fake_urls
15
+
16
+ FakeWeb.allow_net_connect = false
17
+
18
+ # Shorten
19
+ url = "https://www.googleapis.com/urlshortener/v1/url"
20
+ options = {"longUrl" => "http://www.zigotto.com"}.inspect
21
+ FakeWeb.register_uri(:post, url, :response => load_fixture('shorten.json'), :body => options)
22
+
23
+ # Expand
24
+ url = "https://www.googleapis.com/urlshortener/v1/url?shortUrl=http://goo.gl/7lob"
25
+ FakeWeb.register_uri(:get, url, :response => load_fixture('expand.json'))
26
+
27
+ end
metadata ADDED
@@ -0,0 +1,178 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: google_url_shortner
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Hassane Moustapha
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-01-12 00:00:00 +00:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ version_requirements: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ hash: 3
28
+ segments:
29
+ - 2
30
+ - 3
31
+ - 0
32
+ version: 2.3.0
33
+ requirement: *id001
34
+ prerelease: false
35
+ name: rspec
36
+ type: :development
37
+ - !ruby/object:Gem::Dependency
38
+ version_requirements: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ hash: 23
44
+ segments:
45
+ - 1
46
+ - 0
47
+ - 0
48
+ version: 1.0.0
49
+ requirement: *id002
50
+ prerelease: false
51
+ name: bundler
52
+ type: :development
53
+ - !ruby/object:Gem::Dependency
54
+ version_requirements: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ hash: 7
60
+ segments:
61
+ - 1
62
+ - 5
63
+ - 2
64
+ version: 1.5.2
65
+ requirement: *id003
66
+ prerelease: false
67
+ name: jeweler
68
+ type: :development
69
+ - !ruby/object:Gem::Dependency
70
+ version_requirements: &id004 !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ requirement: *id004
80
+ prerelease: false
81
+ name: rcov
82
+ type: :development
83
+ - !ruby/object:Gem::Dependency
84
+ version_requirements: &id005 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ hash: 27
90
+ segments:
91
+ - 1
92
+ - 3
93
+ - 0
94
+ version: 1.3.0
95
+ requirement: *id005
96
+ prerelease: false
97
+ name: fakeweb
98
+ type: :development
99
+ - !ruby/object:Gem::Dependency
100
+ version_requirements: &id006 !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ hash: 5
106
+ segments:
107
+ - 0
108
+ - 6
109
+ - 1
110
+ version: 0.6.1
111
+ requirement: *id006
112
+ prerelease: false
113
+ name: httparty
114
+ type: :runtime
115
+ description: "Client Ruby pour acc\xC3\xA8der \xC3\xA0 l'API Google URL Shortener."
116
+ email: hassanemoustapha@gmail.com
117
+ executables: []
118
+
119
+ extensions: []
120
+
121
+ extra_rdoc_files:
122
+ - README.rdoc
123
+ files:
124
+ - .redcar/tags
125
+ - Gemfile
126
+ - Gemfile.lock
127
+ - MIT-LICENSE
128
+ - README.rdoc
129
+ - Rakefile
130
+ - VERSION
131
+ - google_url_shortner.gemspec
132
+ - lib/google/expander.rb
133
+ - lib/google/request.rb
134
+ - lib/google/shortner.rb
135
+ - lib/google_url_shortner.rb
136
+ - spec/expand_spec.rb
137
+ - spec/fixtures/expand.json
138
+ - spec/fixtures/shorten.json
139
+ - spec/shorten_spec.rb
140
+ - spec/spec_helper.rb
141
+ has_rdoc: true
142
+ homepage: http://github.com/hkairi/google_url_shortner
143
+ licenses:
144
+ - MIT
145
+ post_install_message:
146
+ rdoc_options: []
147
+
148
+ require_paths:
149
+ - lib
150
+ required_ruby_version: !ruby/object:Gem::Requirement
151
+ none: false
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ hash: 3
156
+ segments:
157
+ - 0
158
+ version: "0"
159
+ required_rubygems_version: !ruby/object:Gem::Requirement
160
+ none: false
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ hash: 3
165
+ segments:
166
+ - 0
167
+ version: "0"
168
+ requirements: []
169
+
170
+ rubyforge_project:
171
+ rubygems_version: 1.4.1
172
+ signing_key:
173
+ specification_version: 3
174
+ summary: "Client Ruby pour acc\xC3\xA8der \xC3\xA0 l'API Google URL Shortener."
175
+ test_files:
176
+ - spec/expand_spec.rb
177
+ - spec/shorten_spec.rb
178
+ - spec/spec_helper.rb