googl 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile ADDED
@@ -0,0 +1,48 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/rdoctask'
4
+ require 'rake/gempackagetask'
5
+
6
+ require 'rspec/core/rake_task'
7
+
8
+ RSpec::Core::RakeTask.new :spec do |t|
9
+ t.rspec_opts = %w(-fp --color)
10
+ end
11
+
12
+ Rake::RDocTask.new(:rdoc) do |rdoc|
13
+ rdoc.rdoc_dir = 'rdoc'
14
+ rdoc.title = 'googl'
15
+ rdoc.options << '--line-numbers' << '--inline-source'
16
+ rdoc.rdoc_files.include('README.rdoc')
17
+ rdoc.rdoc_files.include('lib/**/*.rb')
18
+ end
19
+
20
+ spec = Gem::Specification.new do |s|
21
+ s.name = "googl"
22
+ s.version = "0.0.1"
23
+ s.summary = "Wrapper for Google URL Shortener API"
24
+ s.description = "Small library for Google URL Shortener API"
25
+ s.files = FileList['lib/**/*', '[A-Z]*'].to_a
26
+ s.author = "Jésus Lopes"
27
+ s.email = "jlopes@zigotto.com"
28
+ s.homepage = "http://zigotto.com"
29
+ s.add_dependency('httparty', '>= 0.6.1')
30
+ s.add_development_dependency "rspec", ">= 2.0.0"
31
+ s.add_development_dependency "fakeweb"
32
+ end
33
+
34
+ Rake::GemPackageTask.new(spec) do |pkg|
35
+ pkg.gem_spec = spec
36
+ end
37
+
38
+ desc "Install the gem #{spec.name}-#{spec.version}.gem"
39
+ task :install do
40
+ system("gem install pkg/#{spec.name}-#{spec.version}.gem --no-ri --no-rdoc")
41
+ end
42
+
43
+ desc "Create a gemspec file"
44
+ task :make_spec do
45
+ File.open("#{spec.name}.gemspec", "w") do |file|
46
+ file.puts spec.to_ruby
47
+ end
48
+ end
@@ -0,0 +1,18 @@
1
+ module Googl
2
+
3
+ class Expand
4
+
5
+ attr_accessor :long_url
6
+
7
+ def initialize(short_url)
8
+ resp = Request.get("/urlshortener/v1/url?shortUrl=#{short_url}")
9
+ if resp.code == 200
10
+ self.long_url = resp['longUrl']
11
+ else
12
+ resp.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 Googl
2
+
3
+ class Shorten
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
data/lib/googl.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+ require 'httparty'
3
+
4
+ require 'googl/request'
5
+ require 'googl/shorten'
6
+ require 'googl/expand'
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: googl
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - "J\xC3\xA9sus Lopes"
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-01-11 00:00:00 -02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: httparty
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 5
30
+ segments:
31
+ - 0
32
+ - 6
33
+ - 1
34
+ version: 0.6.1
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: rspec
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 15
46
+ segments:
47
+ - 2
48
+ - 0
49
+ - 0
50
+ version: 2.0.0
51
+ type: :development
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: fakeweb
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 3
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ type: :development
66
+ version_requirements: *id003
67
+ description: Small library for Google URL Shortener API
68
+ email: jlopes@zigotto.com
69
+ executables: []
70
+
71
+ extensions: []
72
+
73
+ extra_rdoc_files: []
74
+
75
+ files:
76
+ - lib/googl/expand.rb
77
+ - lib/googl/request.rb
78
+ - lib/googl/shorten.rb
79
+ - lib/googl.rb
80
+ - Rakefile
81
+ has_rdoc: true
82
+ homepage: http://zigotto.com
83
+ licenses: []
84
+
85
+ post_install_message:
86
+ rdoc_options: []
87
+
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ hash: 3
96
+ segments:
97
+ - 0
98
+ version: "0"
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ hash: 3
105
+ segments:
106
+ - 0
107
+ version: "0"
108
+ requirements: []
109
+
110
+ rubyforge_project:
111
+ rubygems_version: 1.3.7
112
+ signing_key:
113
+ specification_version: 3
114
+ summary: Wrapper for Google URL Shortener API
115
+ test_files: []
116
+