upkey-helios-client 1.0.0

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: 4895a1201f1ef7f74064e41e59d454d7a8e7107a
4
+ data.tar.gz: ac512531b79f1c8ef9372818808d9b0b623c43a3
5
+ SHA512:
6
+ metadata.gz: abeb94ba2f32fa3617abdd15ab4ec8c83cd03fdde5f4f65ce6da9430de8aa0f6de63a935aadcdd6babb6c584df5ceefd5f71f398f3179c9088e67b1528adab74
7
+ data.tar.gz: aa624f27206911c729f91f492e7e1dc1342e5f8ebd2d4fa229a97b42368f1cd503329349e7cd194a5083a3189a763d9dda5384365bab7772544efa6e2d439f75
@@ -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.2.4
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 elliott.a.young@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,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in upkey-helios-client.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 ElliottAYoung
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,118 @@
1
+ # Upkey::Helios::Client
2
+
3
+ This gem is the interface for the Upkey::Helios API, allowing Users to easily access the desired information.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'upkey-helios-client'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install upkey-helios-client
20
+
21
+ ## Usage
22
+
23
+ To use the app you must first set up your Client for this gem:
24
+
25
+ ```ruby
26
+ client = Upkey::Helios::Client.new({
27
+ access_key: ACCESS_KEY,
28
+ helios_url: HELIOS_URL
29
+ })
30
+ ```
31
+
32
+ This will spin up a client with the necessary credentials and information needed to find and communicate with the Helios API. After this has been set up you can begin using the API by passing path information and parameters as necessary. Details on this are found below.
33
+
34
+ ### Basic Routes
35
+
36
+ The gem will determine the API endpoint you are trying to access by what path information you pass in the array. For example, to reach `/api/students` you would pass `[{ students: nil }]` as the `path_info` - and for `/api/students/1` you would pass `[{ students: 1 }]`.
37
+
38
+ Examples on the multiple approaches for all REST verbs are included below:
39
+
40
+ ```ruby
41
+ # Get Multiple
42
+ client.get([{ students: 1 }])
43
+
44
+ # Get Single
45
+ client.get([{ students: 1 }])
46
+
47
+ # Post New
48
+ client.post([{ students: 1 }], student_params)
49
+
50
+ # Patch/Put Single
51
+ client.patch([{ students: 1 }], student_params)
52
+ OR
53
+ client.put([{ students: 1 }], student_params)
54
+
55
+ # Delete Single
56
+ client.delete([{ students: 1 }])
57
+
58
+ ```
59
+
60
+ ### Nested Routes
61
+
62
+ Nested routes work exactly like basic routes, only the `path_info` Array should contain information for all relevant parent information. For example with the route `/api/students/1/attributes` you will have the following:
63
+
64
+ ```ruby
65
+ # Get Multiple
66
+ client.get([{ students: 1 }, { attributes: nil }])
67
+
68
+ # Get Single
69
+ client.get([{ students: 1 }, { attributes: 1 }])
70
+
71
+ # Post New
72
+ client.post([{ students: 1 }, { attributes: nil }], attribute_params)
73
+
74
+ # Patch/Put Single
75
+ client.patch([{ students: 1 }, { attributes: 1 }], attribute_params)
76
+ OR
77
+ client.put([{ students: 1 }, { attributes: 1 }], attribute_params)
78
+
79
+ # Delete Single
80
+ client.delete([{ students: 1 }, { attributes: 1 }])
81
+
82
+ ```
83
+
84
+ In this example `{ students: 1 }` passes the `student_id` param and `{ attributes: 1 }` passes the general `id` param.
85
+
86
+ ### Response
87
+
88
+ The beauty of this gem really comes down to the general, uniform response it will give from the API. It passes these responses in `Upkey::Helios::Response` objects that have the following properties:
89
+
90
+ ```ruby
91
+ # For /api/students/1/attributes
92
+
93
+ <Upkey::Helios::Response
94
+ @contents: [Array of Attribute Objects],
95
+ @raw_headers: { Header Information Hash },
96
+ @status: Status Code Integer
97
+ >
98
+ ```
99
+
100
+ You can then access parsed information by simply calling `response.contents`, `response.status` and `response.raw_headers` accordingly.
101
+
102
+ ## Development
103
+
104
+ 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.
105
+
106
+ 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).
107
+
108
+ ## Contributing
109
+
110
+ Bug reports and pull requests are welcome on GitHub at https://github.com/beupkey/upkey-helios-client. 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.
111
+
112
+ ## License
113
+
114
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
115
+
116
+ ## Code of Conduct
117
+
118
+ Everyone interacting in the Upkey::Helios::Client project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/beupkey/upkey-helios-client/blob/master/CODE_OF_CONDUCT.md).
@@ -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 "upkey/helios/client"
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,6 @@
1
+ require "upkey/helios/version"
2
+
3
+ module Upkey
4
+ module Helios
5
+ end
6
+ end
@@ -0,0 +1,21 @@
1
+ module Upkey
2
+ module Helios
3
+ module Accessor
4
+ def self.query(client, method, path_info, params = {})
5
+ @client = client
6
+ path = Upkey::Helios::Builder.path(path_info)
7
+
8
+ access_helios(method, path, params)
9
+ end
10
+
11
+ class << self
12
+ private
13
+
14
+ def access_helios(method, path, params)
15
+ client_params = params.merge({ access_key: @client.access_key })
16
+ @client.conn.send(method.to_s, *[path, client_params])
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,19 @@
1
+ module Upkey
2
+ module Helios
3
+ module Builder
4
+ def self.path(path_info_array)
5
+ path_str = "/api"
6
+
7
+ path_info_array.each do |section|
8
+ if section.values[0].nil?
9
+ path_str += "/#{section.keys[0]}"
10
+ else
11
+ path_str += "/#{section.keys[0]}/#{section.values[0]}"
12
+ end
13
+ end
14
+
15
+ path_str
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,42 @@
1
+ require 'upkey/helios/accessor'
2
+ require 'upkey/helios/builder'
3
+ require 'upkey/helios/responder'
4
+ require 'upkey/helios/response'
5
+
6
+ require 'upkey/helios/errors/missing_argument_error'
7
+ require 'upkey/helios/errors/helios_response_error'
8
+
9
+ require 'faraday'
10
+
11
+ module Upkey
12
+ module Helios
13
+ class Client
14
+ attr_reader :access_key, :helios_url, :conn
15
+
16
+ def initialize(args = {})
17
+ raise MissingArgumentError unless args[:access_key] && args[:helios_url]
18
+
19
+ @access_key = args[:access_key]
20
+ @helios_url = args[:helios_url]
21
+ @conn = set_up_faraday
22
+ end
23
+
24
+ def method_missing(*args)
25
+ args[2].nil? ? (params = {}) : (params = args[2])
26
+ response = Upkey::Helios::Accessor.query(self, args[0], args[1], params)
27
+
28
+ Upkey::Helios::Responder.parse(response)
29
+ end
30
+
31
+ private
32
+
33
+ def set_up_faraday
34
+ Faraday.new(:url => "#{@helios_url}") do |faraday|
35
+ faraday.request :url_encoded
36
+ faraday.response :logger
37
+ faraday.adapter Faraday.default_adapter
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,9 @@
1
+ module Upkey
2
+ module Helios
3
+ class HeliosResponseError < StandardError
4
+ def initialize(msg = "An error has occurred on Helios. Please check the Helios logs for more Details.")
5
+ super
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Upkey
2
+ module Helios
3
+ class MissingArgumentError < ArgumentError
4
+ def initialize(msg = "Missing Arguments for Upkey::Helios::Client. Required Arguments: [access_key, helios_url]")
5
+ super
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,18 @@
1
+ module Upkey
2
+ module Helios
3
+ module Responder
4
+ def self.parse(response)
5
+ case response.status
6
+ when 404, 401, 200, 204
7
+ Upkey::Helios::Response.new({
8
+ status: response.status,
9
+ contents: response.body,
10
+ headers: response.headers
11
+ })
12
+ else
13
+ raise HeliosResponseError
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,28 @@
1
+ require 'json'
2
+
3
+ module Upkey
4
+ module Helios
5
+ class Response
6
+ attr_reader :raw_headers, :contents, :status
7
+
8
+ def initialize(args = {})
9
+ @status = args[:status]
10
+ @raw_headers = args[:headers]
11
+ @contents = parsed_contents(args[:contents], args[:error])
12
+ end
13
+
14
+ private
15
+
16
+ def parsed_contents(contents, error)
17
+ return [error] if @status >= 400
18
+
19
+ begin
20
+ JSON.parse(contents) unless @status == 204
21
+ rescue JSON::ParserError => e
22
+ [contents]
23
+ end
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,5 @@
1
+ module Upkey
2
+ module Helios
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "upkey/helios/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "upkey-helios-client"
8
+ spec.version = Upkey::Helios::VERSION
9
+ spec.authors = ["ElliottAYoung"]
10
+ spec.email = ["elliott.a.young@gmail.com"]
11
+
12
+ spec.summary = "The Ruby Client for the Upkey Helios API"
13
+ spec.description = "The Ruby Client for the Upkey Helios API"
14
+ spec.homepage = "https://github.com/beupkey/upkey-helios-client.git"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.15"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ spec.add_development_dependency "pry"
28
+ spec.add_development_dependency "faraday"
29
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: upkey-helios-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - ElliottAYoung
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-08-10 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.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: pry
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: faraday
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
+ description: The Ruby Client for the Upkey Helios API
84
+ email:
85
+ - elliott.a.young@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - CODE_OF_CONDUCT.md
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/setup
100
+ - lib/upkey/helios.rb
101
+ - lib/upkey/helios/accessor.rb
102
+ - lib/upkey/helios/builder.rb
103
+ - lib/upkey/helios/client.rb
104
+ - lib/upkey/helios/errors/helios_response_error.rb
105
+ - lib/upkey/helios/errors/missing_argument_error.rb
106
+ - lib/upkey/helios/responder.rb
107
+ - lib/upkey/helios/response.rb
108
+ - lib/upkey/helios/version.rb
109
+ - upkey-helios-client.gemspec
110
+ homepage: https://github.com/beupkey/upkey-helios-client.git
111
+ licenses:
112
+ - MIT
113
+ metadata: {}
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ requirements: []
129
+ rubyforge_project:
130
+ rubygems_version: 2.4.5.1
131
+ signing_key:
132
+ specification_version: 4
133
+ summary: The Ruby Client for the Upkey Helios API
134
+ test_files: []