shot_api_gem 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2fa238ed7e1c6e14edcd0eb04430b706830ece0b
4
+ data.tar.gz: cdd5db22f9e847b53edb93b147e5c645a0184236
5
+ SHA512:
6
+ metadata.gz: aea81b0eb06b08f5c817da251db18c451fd7b4d0051f2688714ea34be23fec7451e49afa940512d66da60c1e2df39abb9c3443cfac95c4544978b85dff819449
7
+ data.tar.gz: 4db8e4864bee4b1f3e48fc089b100e60678efb9b0f16e8fdb905ebabadcbce79286ec138397a69b3546af1a899948a6882c4d031c44f15a41597b734b0473056
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ before_install: gem install bundler -v 1.11.2
5
+
6
+ addons:
7
+ code_climate:
8
+ repo_token: cd5e01f67a9e9db56a3c218e1722e2e250b39cfb4abd287fd883b58186e3bef9
9
+
10
+ after_script: CODECLIMATE_REPO_TOKEN=cd5e01f67a9e9db56a3c218e1722e2e250b39cfb4abd287fd883b58186e3bef9 bundle exec codeclimate-test-reporter
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at michael.ogala@andela.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in shot_api_gem.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Michael Ogala
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.
data/README.md ADDED
@@ -0,0 +1,91 @@
1
+ [![Code Climate](https://codeclimate.com/github/andela-mogala/shot_api_gem/badges/gpa.svg)](https://codeclimate.com/github/andela-mogala/shot_api_gem) [![Build Status](https://travis-ci.org/andela-mogala/shot_api_gem.svg?branch=master)](https://travis-ci.org/andela-mogala/shot_api_gem)
2
+
3
+ # ShotApiGem
4
+
5
+ Shot api gem was built out of a desire to make interactions with the [turbo-url](turbo-url.herokuapp.com) api a hassle free process. It does the job of communicating with the api and returns ruby objects that you can use directly in your code.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'shot_api_gem'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install shot_api_gem
22
+
23
+ ## Usage
24
+ This gem is intended for use directly with your ruby code. The entry point to all interactions with the turbo-url api is from the ShotApiGem::Consumer class.
25
+ This class accepts an api key when creating an instance.
26
+
27
+ ### Getting an API key.
28
+ * Create an account on [turbo-url](turbo-url.herokuapp.com) if you don't already have one
29
+ * Visit your dashboard and find the `Generate API Key` button.
30
+ * Clicking on this button generates an api key.
31
+ * You can now copy this key and use it with the gem
32
+
33
+ ### Making requests
34
+ Start by creating an instance of Consumer class
35
+
36
+ ```ruby
37
+ resource = ShotApiGem::Consumer.new(api_key)
38
+ ```
39
+
40
+ You can now call methods like
41
+
42
+ ```ruby
43
+ resource.fetch_all
44
+ ```
45
+ This returns an array of links that you have created with your account.
46
+
47
+ ```ruby
48
+ resource.fetch(1)
49
+ ```
50
+ Returns the link with `{ id: 1 }`
51
+
52
+ ```ruby
53
+ resource.create({ url: 'somelink.com', slug: 'slk' })
54
+ ```
55
+ creates a new link and returns the created link as an object
56
+
57
+ ```ruby
58
+ resource.update(1, { url: 'anotherlink.com', slug: 'anlk' })
59
+ ```
60
+ updates the link with `{ id: 1 }` and returns the updated link as an object
61
+
62
+ ```ruby
63
+ resource.delete(1)
64
+ ```
65
+ deletes the link with `{ id: 1 }` but doesn't return any content
66
+
67
+ A typical Link object has the following properties:
68
+ * id
69
+ * url
70
+ * slug
71
+ * active
72
+ * clicks
73
+ * title
74
+ * date_created
75
+ * date_updated
76
+
77
+ ## Development
78
+
79
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
80
+
81
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
82
+
83
+ ## Contributing
84
+
85
+ Bug reports and pull requests are welcome on GitHub at https://github.com/andela-mogala/shot_api_gem. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
86
+
87
+
88
+ ## License
89
+
90
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
91
+
data/Rakefile ADDED
@@ -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
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "shot_api_gem"
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
data/bin/setup ADDED
@@ -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,6 @@
1
+ require "shot_api_gem/version"
2
+ require 'shot_api_gem/link'
3
+ require 'shot_api_gem/consumer'
4
+
5
+ module ShotApiGem
6
+ end
@@ -0,0 +1,55 @@
1
+ require 'rest-client'
2
+ require 'json'
3
+
4
+ module ShotApiGem
5
+ class Consumer
6
+ attr_reader :header, :base_url, :local_base_url
7
+
8
+ def initialize(api_key)
9
+ @header = { authorization: api_key }
10
+ @base_url = 'http://turbo-url.herokuapp.com/api/v1/links'
11
+ @local_base_url = 'http://localhost:3000/api/v1/links'
12
+ end
13
+
14
+ def fetch_all
15
+ response = RestClient.get(base_url, header)
16
+ json_response(response.body)[:links].map do |link|
17
+ Link.new(link)
18
+ end
19
+ end
20
+
21
+ def fetch(id)
22
+ response = RestClient.get(base_url << "/#{id}", header)
23
+ Link.new(json_response(response.body))
24
+ end
25
+
26
+ def create(options)
27
+ response = RestClient.post(
28
+ base_url,
29
+ { given_url: options[:url], slug: options[:slug] },
30
+ header
31
+ )
32
+ Link.new(json_response(response.body))
33
+ end
34
+
35
+ def update(id, options)
36
+ response = RestClient.patch(
37
+ base_url << "/#{id}",
38
+ { given_url: options[:url], slug: options[:slug], active: options[:active] },
39
+ header
40
+ )
41
+ Link.new(json_response(response.body))
42
+ end
43
+
44
+ def delete(id)
45
+ response = RestClient.delete(base_url << "/#{id}", header)
46
+ response.code
47
+ end
48
+
49
+ private
50
+
51
+ def json_response(body)
52
+ JSON.parse(body, symbolize_names: true)
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,25 @@
1
+ module ShotApiGem
2
+ class Link
3
+ attr_reader(
4
+ :id,
5
+ :url,
6
+ :slug,
7
+ :active,
8
+ :clicks,
9
+ :title,
10
+ :date_created,
11
+ :date_updated
12
+ )
13
+
14
+ def initialize(params)
15
+ @id = params[:id]
16
+ @url = params[:url]
17
+ @slug = params[:slug]
18
+ @active = params[:active]
19
+ @clicks = params[:clicks]
20
+ @title = params[:title]
21
+ @date_created = params[:date_created]
22
+ @date_updated = params[:date_updated]
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module ShotApiGem
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'shot_api_gem/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "shot_api_gem"
8
+ spec.version = ShotApiGem::VERSION
9
+ spec.authors = ["Michael Ogala"]
10
+ spec.email = ["michael.ogala@andela.com"]
11
+
12
+ spec.summary = %q{Pull data from turbo-url api}
13
+ spec.description = %q{Interacts with the exposed api of turbo-url }
14
+ spec.homepage = "https://github.com/andela-mogala/shot_api_gem"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.11"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
+ spec.add_development_dependency 'shoulda-matchers', '~> 3.1', '>= 3.1.1'
26
+ spec.add_development_dependency 'faker', '~> 1.6', '>= 1.6.6'
27
+ spec.add_development_dependency "codeclimate-test-reporter", "~> 1.0.0"
28
+ spec.add_development_dependency 'simplecov', '~> 0.12.0'
29
+ spec.add_dependency 'rest-client', '~> 2.0'
30
+ end
metadata ADDED
@@ -0,0 +1,183 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shot_api_gem
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Michael Ogala
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-11-07 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.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
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.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: shoulda-matchers
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.1'
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 3.1.1
65
+ type: :development
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - "~>"
70
+ - !ruby/object:Gem::Version
71
+ version: '3.1'
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 3.1.1
75
+ - !ruby/object:Gem::Dependency
76
+ name: faker
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '1.6'
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: 1.6.6
85
+ type: :development
86
+ prerelease: false
87
+ version_requirements: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - "~>"
90
+ - !ruby/object:Gem::Version
91
+ version: '1.6'
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: 1.6.6
95
+ - !ruby/object:Gem::Dependency
96
+ name: codeclimate-test-reporter
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - "~>"
100
+ - !ruby/object:Gem::Version
101
+ version: 1.0.0
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - "~>"
107
+ - !ruby/object:Gem::Version
108
+ version: 1.0.0
109
+ - !ruby/object:Gem::Dependency
110
+ name: simplecov
111
+ requirement: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - "~>"
114
+ - !ruby/object:Gem::Version
115
+ version: 0.12.0
116
+ type: :development
117
+ prerelease: false
118
+ version_requirements: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - "~>"
121
+ - !ruby/object:Gem::Version
122
+ version: 0.12.0
123
+ - !ruby/object:Gem::Dependency
124
+ name: rest-client
125
+ requirement: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - "~>"
128
+ - !ruby/object:Gem::Version
129
+ version: '2.0'
130
+ type: :runtime
131
+ prerelease: false
132
+ version_requirements: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - "~>"
135
+ - !ruby/object:Gem::Version
136
+ version: '2.0'
137
+ description: 'Interacts with the exposed api of turbo-url '
138
+ email:
139
+ - michael.ogala@andela.com
140
+ executables: []
141
+ extensions: []
142
+ extra_rdoc_files: []
143
+ files:
144
+ - ".gitignore"
145
+ - ".rspec"
146
+ - ".travis.yml"
147
+ - CODE_OF_CONDUCT.md
148
+ - Gemfile
149
+ - LICENSE.txt
150
+ - README.md
151
+ - Rakefile
152
+ - bin/console
153
+ - bin/setup
154
+ - lib/shot_api_gem.rb
155
+ - lib/shot_api_gem/consumer.rb
156
+ - lib/shot_api_gem/link.rb
157
+ - lib/shot_api_gem/version.rb
158
+ - shot_api_gem.gemspec
159
+ homepage: https://github.com/andela-mogala/shot_api_gem
160
+ licenses:
161
+ - MIT
162
+ metadata: {}
163
+ post_install_message:
164
+ rdoc_options: []
165
+ require_paths:
166
+ - lib
167
+ required_ruby_version: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - ">="
170
+ - !ruby/object:Gem::Version
171
+ version: '0'
172
+ required_rubygems_version: !ruby/object:Gem::Requirement
173
+ requirements:
174
+ - - ">="
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
177
+ requirements: []
178
+ rubyforge_project:
179
+ rubygems_version: 2.6.7
180
+ signing_key:
181
+ specification_version: 4
182
+ summary: Pull data from turbo-url api
183
+ test_files: []