shortybit 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5f06ca59c9e086ac5eca1f1a8806c13ad33a7cec
4
+ data.tar.gz: 77861d0214498823350e46aa12ee2477d2332fcb
5
+ SHA512:
6
+ metadata.gz: e00468372ddff7c96a8637bb81443cbab12161756174c9606663b3abdbf7489a79107ca2ffdea9febae3a4e687a778fe9b2a171f171f49aca8947fd0782d6ada
7
+ data.tar.gz: 2add83cb4c190a286e4a584e3594f4ecde78c9cefd941c284af046040a637402da43859fa21bffea23c168605becde72cda259a00e33e762e0ff9b416c6b7bf7
@@ -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
+ # Ignore application configuration
12
+ /config/application.yml
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.5
5
+ before_install: gem install bundler -v 1.13.6
@@ -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 lani.berry13@gmail.com. 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,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in shortybit.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Lani1321
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,122 @@
1
+ # Shortybit
2
+
3
+ Ruby Library for accessing Bitly's REST API
4
+
5
+ To use this gem, you need a bit.ly access token. To register go to [bitly.com](https://bitly.com/a/sign_up?utm_content=site-free-button&utm_source=organic&utm_medium=website&utm_campaign=null&utm_cta=site-free-button).
6
+ If you already have a bit.ly account:
7
+ - Navigate to the collapsable hamburger menu(your account) at the top right corner of the page
8
+ - Click on 'Settings'
9
+ - Click on 'Advanced Settings'
10
+ - Click on 'API Support' or 'OAuth'
11
+ - If you clicked on 'API support' then click on 'Generic Access Tokens' in blue
12
+ - If you clicked on 'OAuth' then click on 'Generic Access Token'
13
+ - Put in your password then click the orange 'Generate Token' button at the bottom
14
+
15
+ ## Installation
16
+
17
+ Add this line to your application's Gemfile:
18
+
19
+ ```ruby
20
+ gem 'shortybit'
21
+ ```
22
+
23
+ And then execute:
24
+
25
+ $ bundle
26
+
27
+ Or install it yourself as:
28
+
29
+ $ gem install shortybit
30
+
31
+ ## Usage
32
+
33
+ Create a client using your access token as follows:
34
+ ```
35
+ # Create a client
36
+ client = Shortybit::Client.new('your_bitly_access_token')
37
+
38
+ # Result
39
+ #<Shortybit::Client:0x007fee034de178 @access_token="your_bitly_access_token">
40
+
41
+ ```
42
+
43
+ You can now use that client to expose the data from the API:
44
+ ```
45
+ # Get the entries from your link history in reverse chronological order
46
+ client.link_history(client) #=> Returns a hash of the specific user link history data from Bitly
47
+
48
+ # Result
49
+ {
50
+ "has_link_deeplinks": false,
51
+ "archived": false,
52
+ "user_ts": 1522824170,
53
+ "title": "reddit: the front page of the internet",
54
+ "created_at": 1522824170,
55
+ "tags": [],
56
+ "modified_at": 1522824170,
57
+ "campaign_ids": [],
58
+ "private": true,
59
+ "aggregate_link": "http://bit.ly/grRCQh",
60
+ "long_url": "https://www.reddit.com/",
61
+ "client_id": "a5e8cebb233c5d07e5c553e917dffb92fec5264d",
62
+ "link": "http://bit.ly/2uNgpk4",
63
+ "is_domain_deeplink": false,
64
+ "encoding_user": {
65
+ "login": "o_k9q7gj1kj",
66
+ "display_name": "Lani Berry",
67
+ "full_name": "Lani Berry"
68
+ }
69
+ },
70
+ {
71
+ "has_link_deeplinks": false,
72
+ "archived": false,
73
+ "user_ts": 1522816641,
74
+ "title": "Google",
75
+ "created_at": 1522816641,
76
+ "tags": [],
77
+ "modified_at": 1522816641,
78
+ "campaign_ids": [],
79
+ "private": true,
80
+ "aggregate_link": "http://bit.ly/2V6CFi",
81
+ "long_url": "http://www.google.com/",
82
+ "client_id": "",
83
+ "link": "http://bit.ly/2Gvv58L",
84
+ "is_domain_deeplink": false,
85
+ "encoding_user": {
86
+ "login": "o_k9q7gj1kj",
87
+ "display_name": "Lani Berry",
88
+ "full_name": "Lani Berry"
89
+ }
90
+ }
91
+ ```
92
+
93
+ ```
94
+ # Get amount of clicks for a specific link
95
+ client.get_clicks("http://bit.ly/2GQBVJn") #=> Returns a Fixnum
96
+
97
+ # Result
98
+ 2
99
+ ```
100
+
101
+ ```
102
+ # Save a long URL as a Bitlink in a user's history. Also returns a short URL for that link.
103
+ client.link_save(client, "https://www.reddit.com/") #=> Returns a hash with the original URL and short URL
104
+
105
+ # Result
106
+ {
107
+ "link"=>"http://bit.ly/2uNgpk4",
108
+ "aggregate_link"=>"http://bit.ly/grRCQh",
109
+ "long_url"=>"https://www.reddit.com/",
110
+ "new_link"=>1, "user_hash"=>"2uNgpk4"
111
+ }
112
+ ```
113
+ ## Tests
114
+
115
+ Tests can be run with this command:
116
+ $bundle exec ruby test/shortybit/client_test.rb
117
+
118
+ ## License
119
+
120
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
121
+
122
+ # shortybit
@@ -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 "shortybit"
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
@@ -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,2 @@
1
+ require "shortybit/version"
2
+ require_relative "shortybit/client"
@@ -0,0 +1,40 @@
1
+ require 'faraday'
2
+ require 'json'
3
+
4
+ BASE_URL = "https://api-ssl.bitly.com"
5
+ END_POINT = { link_save: '/v3/user/link_save', link_history: '/v3/user/link_history', clicks: '/v3/link/clicks' }
6
+
7
+ module Shortybit
8
+ class Client
9
+ attr_accessor :access_token
10
+
11
+ def initialize(access_token)
12
+ @access_token = access_token
13
+ end
14
+
15
+ # Returns number of clicks for bitlink
16
+ # bit_link is expected to be the shortened url
17
+ # Pass in client to get access token and interpolate in response
18
+ def get_clicks(client, bit_link)
19
+ response = Faraday.get("#{BASE_URL}#{END_POINT[:clicks]}?access_token=#{client.access_token}&link=#{bit_link}")
20
+
21
+ # Parse JSON
22
+ parsed_response = JSON.parse(response.body)
23
+ clicks = parsed_response["data"]["link_clicks"]
24
+ end
25
+
26
+ # Returns hash of link history
27
+ def link_history(client)
28
+ response = Faraday.get("#{BASE_URL}#{END_POINT[:link_history]}?access_token=#{client.access_token}")
29
+ parsed_response = JSON.parse(response.body)
30
+ links = parsed_response["data"]["link_history"]
31
+ end
32
+
33
+ # Returns hash of the saved link
34
+ def link_save(client, long_url)
35
+ response = Faraday.get("#{BASE_URL}#{END_POINT[:link_save]}?access_token=#{client.access_token}&longUrl=#{long_url}")
36
+ parsed_response = JSON.parse(response.body)
37
+ saved_link = parsed_response["data"]["link_save"]
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,3 @@
1
+ module Shortybit
2
+ VERSION = "0.1.3"
3
+ end
Binary file
Binary file
Binary file
@@ -0,0 +1,42 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'shortybit/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "shortybit"
8
+ spec.version = Shortybit::VERSION
9
+ spec.authors = ["Lani Berry"]
10
+ spec.email = ["lani.berry13@gmail.com"]
11
+
12
+ spec.summary = %q{Gem to wrap Bitly API.}
13
+ spec.description = %q{Ruby library for accessing Bitly API.}
14
+ spec.homepage = "https://github.com/Lani1321/shortybit"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.13"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "minitest"
36
+ spec.add_development_dependency "vcr"
37
+ spec.add_development_dependency "webmock"
38
+
39
+ spec.add_dependency "faraday"
40
+ spec.add_dependency "json"
41
+ spec.add_dependency "figaro"
42
+ end
metadata ADDED
@@ -0,0 +1,173 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shortybit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - Lani Berry
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-04-04 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.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
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: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: vcr
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: faraday
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: json
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: figaro
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Ruby library for accessing Bitly API.
126
+ email:
127
+ - lani.berry13@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".travis.yml"
134
+ - CODE_OF_CONDUCT.md
135
+ - Gemfile
136
+ - LICENSE.txt
137
+ - README.md
138
+ - Rakefile
139
+ - bin/console
140
+ - bin/setup
141
+ - lib/shortybit.rb
142
+ - lib/shortybit/client.rb
143
+ - lib/shortybit/version.rb
144
+ - shortybit-0.1.0.gem
145
+ - shortybit-0.1.1.gem
146
+ - shortybit-0.1.2.gem
147
+ - shortybit.gemspec
148
+ homepage: https://github.com/Lani1321/shortybit
149
+ licenses:
150
+ - MIT
151
+ metadata:
152
+ allowed_push_host: https://rubygems.org
153
+ post_install_message:
154
+ rdoc_options: []
155
+ require_paths:
156
+ - lib
157
+ required_ruby_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ required_rubygems_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ requirements: []
168
+ rubyforge_project:
169
+ rubygems_version: 2.4.8
170
+ signing_key:
171
+ specification_version: 4
172
+ summary: Gem to wrap Bitly API.
173
+ test_files: []