url_shorty 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 89cbc4dccdf950f2821a1924b53471f1432182f295d610d6fce3ade277f4a3c3
4
+ data.tar.gz: 745852055b7873d5705745833dcd3e17a747c8dc4ebca4d2b98c0f94f12f8c97
5
+ SHA512:
6
+ metadata.gz: 3cf7ed0087e287f3299f9fd59c508309e82633bef03c3d74e73a64585df631163f4c6a3302532bd33339fbe693d63722cc837922f0306518f7479c5f2b65b66b
7
+ data.tar.gz: 3df8316345e1df345deae69252b8951f5ac01b3d04fc12e03bafe2ee1cc8f679f52192dc1583ab97d6f49ff8c6679b86db3b8bc893eaed1d7bdf7c496bcccecd
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.0
5
+ before_install: gem install bundler -v 1.15.3
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at TODO: Write your email address. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+
6
+ # Specify your gem's dependencies in url_shorty.gemspec
7
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 TODO: Write your name
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,120 @@
1
+ # UrlShorty
2
+
3
+ UrlShorty is ruby gem to simplify URL shortening using Google URL shortener.
4
+ You can refer the gem Documentation [here](http://www.rubydoc.info/gems/url_shorty/0.0.6)
5
+
6
+ Using this you can,
7
+ - Shorten a Long URL
8
+ - Expand a Shortened URL
9
+ - Get Analytics details of a Shortened URL.
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'url_shorty'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install url_shorty
26
+
27
+ ## Usage
28
+ ## Get Google URL Shortener API Key:
29
+ Refer [Google URL Shortener](https://developers.google.com/url-shortener/v1/getting_started) Getting Started page to create a API key for google url Shortener service.
30
+
31
+ ## Setting up API key:
32
+
33
+ ```ruby
34
+ UrlShorty.api_key("<Your API KEY>")
35
+ ```
36
+ ## Shorten URL:
37
+ ```ruby
38
+ UrlShorty.shorten_url("<Long URL>")
39
+ ```
40
+
41
+ **Example:**
42
+
43
+ ```ruby
44
+ UrlShorty.shorten_url("https://github.com/Balaji-Ramasubramanian/UrlShorty")
45
+ #=>"https://goo.gl/XojnVs"
46
+ ```
47
+
48
+ ## Expand URL:
49
+ ```ruby
50
+ UrlShorty.expand_url("<Shorten URL>")
51
+ ```
52
+
53
+ **Example:**
54
+ ```ruby
55
+ UrlShorty.expand_url("https://goo.gl/XojnVs")
56
+ #=> "https://github.com/Balaji-Ramasubramanian/UrlShorty"
57
+ ```
58
+
59
+ ## Get Analytics:
60
+ To get summary of the analytics for the shortened URL,
61
+ ```ruby
62
+ UrlShorty.get_analytics("<shorten URL>")
63
+ ```
64
+ #### Basics Info:
65
+
66
+ - kind
67
+ - id
68
+ - longUrl
69
+ - status
70
+ - created
71
+
72
+ **Example:**
73
+ ```ruby
74
+ url_analytics_data = UrlShorty.get_analytics("https://goo.gl/XojnVs")
75
+ url_analytics_data.kind
76
+ #=> "urlshortener#url"
77
+ url_analytics_data.id
78
+ #=> "https://goo.gl/XojnVs"
79
+ url_analytics_data.longUrl
80
+ #=> "https://github.com/Balaji-Ramasubramanian/UrlShorty"
81
+ url_analytics_data.created
82
+ #=> "2017-11-26T07:26:32.556+00:00"
83
+
84
+ ```
85
+ #### Usage Info:
86
+ Available Scopes:
87
+ - allTime
88
+ - month
89
+ - week
90
+ - twoHours
91
+
92
+
93
+ Available information:
94
+ - shortUrlClicks
95
+ - longUrlClicks
96
+ - referers
97
+ - countries
98
+ - browsers
99
+ - platforms
100
+
101
+
102
+ **Example**
103
+ ```ruby
104
+ url_analytics_data = UrlShorty.get_analytics("https://goo.gl/SeRtHU")
105
+ url_analytics_data.analytics.allTime.shortUrlClicks
106
+ #=> "88"
107
+ url_analytics_data.analytics.allTime.referers[0].count
108
+ #=>"73"
109
+ url_analytics_data.analytics.month.browsers[1].id
110
+ #=>"Chrome"
111
+ url_analytics_data.analytics.twoHours.platforms[2].id
112
+ #=>"Macintosh"
113
+ ```
114
+
115
+
116
+ ## License
117
+
118
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
119
+
120
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "url_shorty"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,72 @@
1
+ require "url_shorty/version"
2
+ require "url_shorty/utils"
3
+ require "url_shorty/analytics"
4
+ require 'net/http'
5
+ require 'uri'
6
+ require 'json'
7
+ require 'httparty'
8
+ require 'Openssl'
9
+
10
+ # @author Balaji
11
+ module UrlShorty
12
+ # @param api_key [String] Google URL Shortener API KEY
13
+ # @return [nil]
14
+ # This method will set-up the Google URL shortener API key for your project.
15
+ # If you don't have any API key, { Click here }[https://developers.google.com/url-shortener/v1/getting_started] to create one for your project.
16
+ # Example:
17
+ #
18
+ # UrlShorty.api_key("<API KEY>")
19
+ #
20
+ def self.api_key (api_key)
21
+ @api_key = api_key
22
+ end
23
+
24
+ # @param long_url [String] A url value that has to be shortened
25
+ # @return [String] A string representing the shortened URL
26
+ # This method will shorten the provided long URL into a short URL using the Google URL shortener service.
27
+ # Example:
28
+ #
29
+ # UrlShorty.shorten_url(""https://github.com/Balaji-Ramasubramanian/UrlShorty")
30
+ # => "https://goo.gl/XojnVs"
31
+ #
32
+ def self.shorten_url(long_url)
33
+ uri = URI.parse( BASE_URL + @api_key )
34
+ header = {'Content-Type': 'application/json'}
35
+ parameter = {"longUrl": "#{long_url}"}
36
+ http = Net::HTTP.new(uri.host, uri.port)
37
+ http.use_ssl = true
38
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
39
+ request = Net::HTTP::Post.new(uri.request_uri, header)
40
+ request.body = parameter.to_json
41
+ response = http.request(request)
42
+ data = JSON.parse(response.body)
43
+ if data["id"] != nil then
44
+ return data["id"]
45
+ else
46
+ puts data
47
+ return data["error"]["errors"][0]["reason"]
48
+ end
49
+ end
50
+
51
+ # @param shorten_url [String] A url value that has to be expanded
52
+ # @return [String] A string representing the expanded URL
53
+ # This method will expand the shortened URL into a long URL
54
+ # Example:
55
+ #
56
+ # UrlShorty.expand_url("https://goo.gl/XojnVs")
57
+ # => "https://github.com/Balaji-Ramasubramanian/UrlShorty"
58
+ #
59
+ def self.expand_url(shorten_url)
60
+ url = BASE_URL + @api_key + SHORT_URL + shorten_url
61
+ response = ""
62
+ response = HTTParty.get(url)
63
+ parsed = JSON.parse(response.body)
64
+ long_url = parsed['longUrl']
65
+ puts long_url
66
+ return long_url
67
+ end
68
+
69
+
70
+
71
+ end
72
+
@@ -0,0 +1,61 @@
1
+ require_relative 'utils'
2
+ module UrlShorty
3
+ # @param shorten_url [String] A String represents Shortened URL
4
+ # @return parsed_json_obj [Object] A Object that contains the analytics data of the Shortened URL
5
+ # To get analytics data for Shortened url
6
+ # The basic information about the Shortened URL are,
7
+ #
8
+ # - kind
9
+ # - id
10
+ # - longUrl
11
+ # - status
12
+ # - created
13
+ #
14
+ # Example:
15
+ #
16
+ # url_analytics_data = UrlShorty.get_analytics("https://goo.gl/XojnVs")
17
+ # url_analytics_data.kind
18
+ # => "urlshortener#url"
19
+ # url_analytics_data.id
20
+ # => "https://goo.gl/XojnVs"
21
+ # url_analytics_data.longUrl
22
+ # => "https://github.com/Balaji-Ramasubramanian/UrlShorty"
23
+ # url_analytics_data.created
24
+ # => "2017-11-26T07:26:32.556+00:00"
25
+ #
26
+ # The Available Scopes are,
27
+ #
28
+ # - allTime
29
+ # - month
30
+ # - week
31
+ # - twoHours
32
+ #
33
+ # The Available information
34
+ # - shortUrlClicks
35
+ # - longUrlClicks
36
+ # - referers
37
+ # - countries
38
+ # - browsers
39
+ # - platforms
40
+ #
41
+ # Examples:
42
+ #
43
+ # url_analytics_data = UrlShorty.get_analytics("https://goo.gl/SeRtHU")
44
+ # url_analytics_data.analytics.allTime.shortUrlClicks
45
+ # => "88"
46
+ # url_analytics_data.analytics.allTime.referers[0].count
47
+ # =>"73"
48
+ # url_analytics_data.analytics.month.browsers[1].id
49
+ # =>"Chrome"
50
+ # url_analytics_data.analytics.twoHours.platforms[2].id
51
+ # =>"Macintosh"
52
+ #
53
+ def self.get_analytics (shorten_url)
54
+ url = BASE_URL + @api_key + SHORT_URL + shorten_url + PROJECTION
55
+ response = ""
56
+ response = HTTParty.get(url)
57
+ parsed_json_obj = JSON.parse(response.body, object_class: OpenStruct)
58
+ return parsed_json_obj
59
+ end
60
+
61
+ end
@@ -0,0 +1,5 @@
1
+ module UrlShorty
2
+ BASE_URL = "https://www.googleapis.com/urlshortener/v1/url?key="
3
+ SHORT_URL = "&shortUrl="
4
+ PROJECTION = "&projection=FULL"
5
+ end
@@ -0,0 +1,3 @@
1
+ module UrlShorty
2
+ VERSION = "0.0.12"
3
+ end
@@ -0,0 +1,41 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "url_shorty/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "url_shorty"
8
+ spec.version = UrlShorty::VERSION
9
+ spec.authors = ["Balaji"]
10
+ spec.email = ["balaji030698@gmail.com"]
11
+
12
+ spec.summary = %q{This is a google url shortener tool for ruby users.}
13
+ spec.description = %q{By using this gem we can able to shorten a URL
14
+ and also able to expand the Short URLs.}
15
+ spec.homepage = "https://github.com/balaji12345/UrlShorty"
16
+ spec.license = "MIT"
17
+ spec.files = ['lib/url_shorty/analytics.rb',
18
+ 'lib/url_shorty/utils.rb',
19
+ 'lib/url_shorty/version.rb']
20
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
21
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
22
+ if spec.respond_to?(:metadata)
23
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
24
+ else
25
+ raise "RubyGems 2.0 or newer is required to protect against " \
26
+ "public gem pushes."
27
+ end
28
+
29
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
30
+ f.match(%r{^(test|spec|features)/})
31
+ end
32
+ spec.bindir = "exe"
33
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
34
+ spec.require_paths = ["lib"]
35
+
36
+ spec.add_development_dependency "bundler", "~> 1.15"
37
+ spec.add_development_dependency "rake", "~> 10.0"
38
+ spec.add_development_dependency "rspec", "~> 3.2"
39
+ spec.add_runtime_dependency "json", "~> 2.0.2"
40
+ spec.add_runtime_dependency "httparty", "~> 0.15.6"
41
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: url_shorty
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.12
5
+ platform: ruby
6
+ authors:
7
+ - Balaji
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-11-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: json
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.0.2
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.0.2
69
+ - !ruby/object:Gem::Dependency
70
+ name: httparty
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.15.6
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.15.6
83
+ description: |-
84
+ By using this gem we can able to shorten a URL
85
+ and also able to expand the Short URLs.
86
+ email:
87
+ - balaji030698@gmail.com
88
+ executables: []
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - ".gitignore"
93
+ - ".rspec"
94
+ - ".travis.yml"
95
+ - CODE_OF_CONDUCT.md
96
+ - Gemfile
97
+ - LICENSE.txt
98
+ - README.md
99
+ - Rakefile
100
+ - bin/console
101
+ - bin/setup
102
+ - lib/url_shorty.rb
103
+ - lib/url_shorty/analytics.rb
104
+ - lib/url_shorty/utils.rb
105
+ - lib/url_shorty/version.rb
106
+ - url_shorty.gemspec
107
+ homepage: https://github.com/balaji12345/UrlShorty
108
+ licenses:
109
+ - MIT
110
+ metadata:
111
+ allowed_push_host: https://rubygems.org
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 2.7.2
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: This is a google url shortener tool for ruby users.
132
+ test_files: []