marble_api_client 1.0.0.pre.alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +8 -0
  3. data/.gitignore +6 -0
  4. data/.rubocop.yml +25 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +25 -0
  7. data/CHANGELOG.md +3 -0
  8. data/CODE_OF_CONDUCT.md +74 -0
  9. data/Gemfile +5 -0
  10. data/Guardfile +16 -0
  11. data/LICENSE +7 -0
  12. data/README.md +137 -0
  13. data/Rakefile +17 -0
  14. data/bin/console +18 -0
  15. data/lib/marble_api_client/proxy.rb +68 -0
  16. data/lib/marble_api_client/requests/create.rb +27 -0
  17. data/lib/marble_api_client/requests/index.rb +31 -0
  18. data/lib/marble_api_client/requests.rb +4 -0
  19. data/lib/marble_api_client/responses/bad_request.rb +25 -0
  20. data/lib/marble_api_client/responses/client_error.rb +21 -0
  21. data/lib/marble_api_client/responses/forbidden.rb +29 -0
  22. data/lib/marble_api_client/responses/http_methods.rb +29 -0
  23. data/lib/marble_api_client/responses/list.rb +60 -0
  24. data/lib/marble_api_client/responses/not_found.rb +25 -0
  25. data/lib/marble_api_client/responses/not_implemented.rb +24 -0
  26. data/lib/marble_api_client/responses/record.rb +25 -0
  27. data/lib/marble_api_client/responses/server_error.rb +27 -0
  28. data/lib/marble_api_client/responses/success.rb +21 -0
  29. data/lib/marble_api_client/responses/unauthorized.rb +19 -0
  30. data/lib/marble_api_client/responses/unprocessable_entity.rb +40 -0
  31. data/lib/marble_api_client/responses.rb +92 -0
  32. data/lib/marble_api_client/version.rb +12 -0
  33. data/lib/marble_api_client.rb +18 -0
  34. data/marble_api_client.gemspec +32 -0
  35. data/spec/marble_api_client/proxy_spec.rb +89 -0
  36. data/spec/marble_api_client/requests/create_spec.rb +30 -0
  37. data/spec/marble_api_client/requests/index_spec.rb +34 -0
  38. data/spec/marble_api_client/responses/bad_request_spec.rb +24 -0
  39. data/spec/marble_api_client/responses/client_error_spec.rb +21 -0
  40. data/spec/marble_api_client/responses/forbidden_spec.rb +31 -0
  41. data/spec/marble_api_client/responses/list_spec.rb +77 -0
  42. data/spec/marble_api_client/responses/not_found_spec.rb +24 -0
  43. data/spec/marble_api_client/responses/not_implmented_spec.rb +24 -0
  44. data/spec/marble_api_client/responses/record_spec.rb +24 -0
  45. data/spec/marble_api_client/responses/responses_spec.rb +90 -0
  46. data/spec/marble_api_client/responses/server_error_spec.rb +24 -0
  47. data/spec/marble_api_client/responses/success_spec.rb +13 -0
  48. data/spec/marble_api_client/responses/unauthorized_spec.rb +13 -0
  49. data/spec/marble_api_client/responses/unprocessable_entity_spec.rb +49 -0
  50. data/spec/marble_api_client_spec.rb +16 -0
  51. data/spec/spec_helper.rb +23 -0
  52. metadata +223 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 07bb0106eb2b330cbedd19e5c4e3eb2ada24ee0730d1a1215f40f6747f8a28b9
4
+ data.tar.gz: e69d6c1eac333ad79019901d46eb4533c482124ea5fbb6c5f33e644db38d0c98
5
+ SHA512:
6
+ metadata.gz: 31aec67b60ec58add566da56550505c09c97116be608eb565bdeb6e72dd66b2c4fbfa5bd503ef4eb941cab583bc8d91a5f40c232b86bd7e7ec639d9e86fcfd3a
7
+ data.tar.gz: fff2dd756c5c60eadd571583493aa8a7c222879c0c066dd65d7208119b474a4626d2246af353d81236949f3aee90e58a8b1d0591a4a8d43db263fa9340e8bf49
data/.editorconfig ADDED
@@ -0,0 +1,8 @@
1
+ # See http://editorconfig.org/
2
+
3
+ [*]
4
+ trim_trailing_whitespace = true
5
+ indent_style = space
6
+ indent_size = 2
7
+ insert_final_newline = true
8
+ end_of_line = lf
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ .DS_Store
2
+ *.gem
3
+ /tmp
4
+ /coverage
5
+ Gemfile.lock
6
+ /pkg
data/.rubocop.yml ADDED
@@ -0,0 +1,25 @@
1
+ Metrics/LineLength:
2
+ Max: 100
3
+ Exclude:
4
+ - marble_api_client.gemspec
5
+
6
+ Metrics/BlockLength:
7
+ ExcludedMethods:
8
+ - let
9
+ - it
10
+ - describe
11
+ - context
12
+ - specify
13
+ - define
14
+
15
+ Metrics/MethodLength:
16
+ Max: 25
17
+
18
+ AllCops:
19
+ TargetRubyVersion: 2.3
20
+
21
+ Metrics/AbcSize:
22
+ Max: 16
23
+
24
+ Metrics/ClassLength:
25
+ Max: 125
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.6.3
data/.travis.yml ADDED
@@ -0,0 +1,25 @@
1
+ env:
2
+ global:
3
+ - CC_TEST_REPORTER_ID=1f3dee90870bee4a1946b3b12521369414a9e06e84f982728fc729990ebebc2f
4
+ language: ruby
5
+ rvm:
6
+ # Build on the latest stable of all supported Rubies (https://www.ruby-lang.org/en/downloads/):
7
+ - 2.3.8
8
+ - 2.4.6
9
+ - 2.5.5
10
+ - 2.6.3
11
+ cache: bundler
12
+ before_script:
13
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
14
+ - chmod +x ./cc-test-reporter
15
+ - ./cc-test-reporter before-build
16
+ script:
17
+ - bundle exec rubocop
18
+ - bundle exec rspec spec --format documentation
19
+ after_script:
20
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
21
+ addons:
22
+ # https://docs.travis-ci.com/user/uploading-artifacts/
23
+ artifacts:
24
+ paths:
25
+ - Gemfile.lock
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ # 0.0.1 (November 18th, 2019)
2
+
3
+ Initial shell. Library has no functionality yet.
@@ -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 oss@bluemarblepayroll.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,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ guard :rspec, cmd: 'DISABLE_SIMPLECOV=true bundle exec rspec --format=documentation' do
4
+ require 'guard/rspec/dsl'
5
+ dsl = Guard::RSpec::Dsl.new(self)
6
+
7
+ # RSpec files
8
+ rspec = dsl.rspec
9
+ watch(rspec.spec_helper) { rspec.spec_dir }
10
+ watch(rspec.spec_support) { rspec.spec_dir }
11
+ watch(rspec.spec_files)
12
+
13
+ # Ruby files
14
+ ruby = dsl.ruby
15
+ dsl.watch_spec_files_for(ruby.lib_files)
16
+ end
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2019 Blue Marble Payroll, LLC
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,137 @@
1
+ # Marble API Client
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/marble_api_client.svg)](https://badge.fury.io/rb/marble_api_client) [![Build Status](https://travis-ci.org/bluemarblepayroll/marble_api_client.svg?branch=master)](https://travis-ci.org/bluemarblepayroll/marble_api_client)
4
+ [![Maintainability](https://api.codeclimate.com/v1/badges/fba9ec43303ca1595e5a/maintainability)](https://codeclimate.com/github/bluemarblepayroll/marble_api_client/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/fba9ec43303ca1595e5a/test_coverage)](https://codeclimate.com/github/bluemarblepayroll/marble_api_client/test_coverage)[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+
6
+
7
+ This library is to simplify requests made to Marble Service Model (Still in procgress). This library offers simple objects to comply with the Marble Service Model request and response objects.
8
+ The library currently supports:
9
+
10
+ * Create
11
+ * Index
12
+
13
+ ## Installation
14
+
15
+ To install through Rubygems:
16
+
17
+ ````
18
+ gem install install marble_api_client
19
+ ````
20
+
21
+ You can also add this to your Gemfile:
22
+
23
+ ````
24
+ bundle add marble_api_client
25
+ ````
26
+
27
+ ## Examples
28
+
29
+ ### Creating the client
30
+
31
+ A client can be created with a url and any headers that should be included
32
+ in all requests.
33
+ ````ruby
34
+ client = MarbleApiClient::Proxy.new(
35
+ 'https://www.example.com:3000',
36
+ headers: { 'Content-Type': 'application/json' }
37
+ )
38
+
39
+ ````
40
+
41
+ ### Making Request Objects
42
+
43
+ Create
44
+ ````ruby
45
+ create_request_obj = Requests::Create.new(context: { key: 'value' },
46
+ record: { key: 'value' })
47
+ ````
48
+
49
+ Index
50
+ ````ruby
51
+ index_request_obj = Requests::Index.new(context: { key: 'value' },
52
+ record: { key: 'value' },
53
+ page: 1,
54
+ page_size: 25)
55
+ ````
56
+
57
+ ### Using the Client:
58
+
59
+ Create
60
+ ````ruby
61
+ create_response = client.create('custom/path',
62
+ create_request_obj,
63
+ headers)
64
+ ````
65
+
66
+ Index
67
+ ````ruby
68
+ index_response = client.index('custom/path',
69
+ index_request_obj,
70
+ headers)
71
+ ````
72
+
73
+ ### Response Objects
74
+
75
+ Responses will be one of these response objects:
76
+
77
+ * Success
78
+ * BadRequest
79
+ * Unauthorized
80
+ * Forbidden
81
+ * NotFound
82
+ * UnprocessableEntity
83
+ * ServerError
84
+ * NotImplemented
85
+
86
+ ## Contributing
87
+
88
+ ### Development Environment Configuration
89
+
90
+ Basic steps to take to get this repository compiling:
91
+
92
+ 1. Install [Ruby](https://www.ruby-lang.org/en/documentation/installation/) (check marble_api_client.gemspec for versions supported)
93
+ 2. Install bundler (gem install bundler)
94
+ 3. Clone the repository (git clone git@github.com:bluemarblepayroll/marble_api_client.git)
95
+ 4. Navigate to the root folder (cd marble_api_client)
96
+ 5. Install dependencies (bundle)
97
+
98
+ ### Running Tests
99
+
100
+ To execute the test suite run:
101
+
102
+ ````
103
+ bundle exec rspec spec --format documentation
104
+ ````
105
+
106
+ Alternatively, you can have Guard watch for changes:
107
+
108
+ ````
109
+ bundle exec guard
110
+ ````
111
+
112
+ Also, do not forget to run Rubocop:
113
+
114
+ ````
115
+ bundle exec rubocop
116
+ ````
117
+
118
+ ### Publishing
119
+
120
+ Note: ensure you have proper authorization before trying to publish new versions.
121
+
122
+ After code changes have successfully gone through the Pull Request review process then the following steps should be followed for publishing new versions:
123
+
124
+ 1. Merge Pull Request into master
125
+ 2. Update ```lib/marble_api_client/version.rb``` using [semantic versioning](https://semver.org/)
126
+ 3. Install dependencies: ```bundle```
127
+ 4. Update ```CHANGELOG.md``` with release notes
128
+ 5. Commit & push master to remote and ensure CI builds master successfully
129
+ 6. 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).
130
+
131
+ ## Code of Conduct
132
+
133
+ Everyone interacting in this codebase, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/bluemarblepayroll/marble_api_client/blob/master/CODE_OF_CONDUCT.md).
134
+
135
+ ## License
136
+
137
+ This project is MIT Licensed.
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2019-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
10
+ require 'bundler/gem_tasks'
11
+ require 'rspec/core/rake_task'
12
+ require 'rubocop/rake_task'
13
+
14
+ RSpec::Core::RakeTask.new(:spec)
15
+ RuboCop::RakeTask.new
16
+
17
+ task default: %i[rubocop spec]
data/bin/console ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # Copyright (c) 2018-present, Blue Marble Payroll, LLC
6
+ #
7
+ # This source code is licensed under the MIT license found in the
8
+ # LICENSE file in the root directory of this source tree.
9
+ #
10
+
11
+ require 'bundler/setup'
12
+ require 'marble_api_client'
13
+
14
+ # You can add fixtures and/or initialization code here to make experimenting
15
+ # with your gem easier. You can also use a different console, if you like.
16
+
17
+ require 'pry'
18
+ Pry.start
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2019-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
10
+ module MarbleApiClient
11
+ # Main class for sending http requests to url.
12
+ # Requests are sent using request and response objects crafted for each action.
13
+ # Headers can be provided to the Proxy as default headers for all requests
14
+ class Proxy
15
+ def initialize(base_url, headers: {})
16
+ raise ArgumentError, 'Base URL is not valid' unless base_url_valid?(base_url)
17
+
18
+ @base_url = base_url
19
+ @headers = headers
20
+ freeze
21
+ end
22
+
23
+ def create(path, create_request: Requests::Create.new, headers: {})
24
+ response = send_request(path, create_request, headers, 'create')
25
+ Responses.get_response_object(response, Responses::CREATE_ACTION)
26
+ end
27
+
28
+ def index(path, index_request: Requests::Index.new, headers: {})
29
+ response = send_request(path, index_request, headers, 'index')
30
+ Responses.get_response_object(response, Responses::INDEX_ACTION)
31
+ end
32
+
33
+ private
34
+
35
+ def send_request(path, request_object, headers, action)
36
+ uri = join_path(path, action)
37
+ merged_headers = @headers.merge(headers)
38
+
39
+ Net::HTTP.start(uri.host, uri.port, use_ssl: ssl?(uri)) do |http|
40
+ request = Net::HTTP::Post.new(uri.request_uri)
41
+ merged_headers.each { |key, value| request.add_field(key, value) }
42
+ request.body = request_object.request_body
43
+ http.request(request)
44
+ end
45
+ end
46
+
47
+ def join_path(path, action)
48
+ if path[-1] == '/'
49
+ URI.join(@base_url, path + action)
50
+ else
51
+ URI.join(@base_url, path + '/' + action)
52
+ end
53
+ end
54
+
55
+ def ssl?(uri)
56
+ uri.scheme == 'https'
57
+ end
58
+
59
+ def base_url_valid?(url)
60
+ uri = begin
61
+ URI.parse(url)
62
+ rescue URI::InvalidURIError
63
+ false
64
+ end
65
+ uri.is_a?(URI::HTTP) || uri.is_a?(URI::HTTPS)
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2019-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
10
+ module MarbleApiClient
11
+ module Requests
12
+ # Create Request Object
13
+ class Create
14
+ def initialize(context: {}, record: {})
15
+ @context = context
16
+ @record = record
17
+ end
18
+
19
+ def request_body
20
+ {
21
+ context: @context,
22
+ record: @record
23
+ }.to_json
24
+ end
25
+ end
26
+ end
27
+ end