goo-gl 0.0.1

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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/goo-gl.rb +25 -0
  3. metadata +58 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fe4bd83897cddbef2be801af8e88e5849b57e00e
4
+ data.tar.gz: 55018b3dd7c685c1644db568780a68c5c6e1ed8d
5
+ SHA512:
6
+ metadata.gz: 7f957cbf721f1a5e173bfa21e9b52442fe607bbeaf9cad1ec0fd8bf773bbf264f2a80f33e6b70cd07fa8b09a3779dd85042d1b77c4874faed580b75cc9e5a510
7
+ data.tar.gz: 22729aab5c74545a31d4e49027ab68b47b337300acff17b3aa6eabe224c390492cbef7d7775fbe6fa12022246c97d6f68f74c379cc6487c4f2cb14bc7410c6e8
data/lib/goo-gl.rb ADDED
@@ -0,0 +1,25 @@
1
+ require 'net/http'
2
+ require 'openssl'
3
+ require 'json'
4
+
5
+ class GooglApi
6
+ attr_accessor :api_key
7
+
8
+ @@uri = URI('https://www.googleapis.com/urlshortener/v1/url')
9
+ @@http = Net::HTTP.new(@@uri.host, @@uri.port)
10
+ @@http.use_ssl = true
11
+ @@http.verify_mode = OpenSSL::SSL::VERIFY_NONE
12
+
13
+ def initialize(api_key)
14
+ self.api_key = api_key
15
+ end
16
+
17
+ def shorten(long_url)
18
+ req = Net::HTTP::Post.new(URI('https://www.googleapis.com/urlshortener/v1/url') + "?key=#{self.api_key}")
19
+ req.body = {longUrl: long_url}.to_json
20
+ req.content_type = 'application/json'
21
+
22
+ response = @@http.request(req).body
23
+ JSON.parse(response)['id']
24
+ end
25
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: goo-gl
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Vlad Zaetc
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ description: A really tiny Google Shortener API gem without dependencies
28
+ email: vladzaets@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - lib/goo-gl.rb
34
+ homepage: http://github.com/vladzaets/goo-gl
35
+ licenses:
36
+ - MIT
37
+ metadata: {}
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ requirements: []
53
+ rubyforge_project:
54
+ rubygems_version: 2.5.1
55
+ signing_key:
56
+ specification_version: 4
57
+ summary: Google Shortener API gem
58
+ test_files: []