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
@@ -0,0 +1,12 @@
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
+ VERSION = '1.0.0-alpha'
12
+ end
@@ -0,0 +1,18 @@
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 'net/http'
11
+
12
+ require_relative 'marble_api_client/proxy'
13
+ require_relative 'marble_api_client/requests'
14
+ require_relative 'marble_api_client/responses'
15
+
16
+ # This class interacts with Blue Marble Payroll Webglobe API
17
+ module MarbleApiClient
18
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require './lib/marble_api_client/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'marble_api_client'
7
+ s.version = MarbleApiClient::VERSION
8
+ s.summary = 'Write a summary.'
9
+
10
+ s.description = <<-DESCRIPTION
11
+ Write a description.
12
+ DESCRIPTION
13
+
14
+ s.authors = ['Dan Dewar']
15
+ s.email = ['ddewar@bluemarblepayroll.com']
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
19
+ s.homepage = 'https://github.com/bluemarblepayroll/marble_api_client'
20
+ s.license = 'MIT'
21
+
22
+ s.required_ruby_version = '>= 2.3.8'
23
+
24
+ s.add_development_dependency('guard-rspec', '~>4.7')
25
+ s.add_development_dependency('pry', '~>0')
26
+ s.add_development_dependency('rake', '~> 12')
27
+ s.add_development_dependency('rspec')
28
+ s.add_development_dependency('rubocop', '~>0.74.0')
29
+ s.add_development_dependency('simplecov', '~>0.17.0')
30
+ s.add_development_dependency('simplecov-console', '~>0.5.0')
31
+ s.add_development_dependency('webmock')
32
+ end
@@ -0,0 +1,89 @@
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 'spec_helper'
11
+
12
+ RSpec.describe MarbleApiClient::Proxy do
13
+ let(:proxy) do
14
+ MarbleApiClient::Proxy.new(
15
+ 'http://www.example.com:3000',
16
+ headers: { 'Content-Type': 'application/json' }
17
+ )
18
+ end
19
+
20
+ it 'requires a base_url' do
21
+ expect { MarbleApiClient::Proxy.new(nil) }
22
+ .to raise_error(ArgumentError, 'Base URL is not valid')
23
+ end
24
+
25
+ it 'uses SSL for HTTPS requests' do
26
+ p = MarbleApiClient::Proxy.new(
27
+ 'https://www.example.com:3000',
28
+ headers: { 'Content-Type': 'application/json' }
29
+ )
30
+
31
+ stub_request(:post, 'https://www.example.com:3000/custom/path/create')
32
+ p.create('custom/path')
33
+ expect(WebMock).to have_requested(:post, 'https://www.example.com:3000/custom/path/create')
34
+ end
35
+
36
+ context 'create' do
37
+ it 'sends requests to path' do
38
+ stub_request(:post, 'http://www.example.com:3000/custom/path/create')
39
+ proxy.create('custom/path')
40
+ expect(WebMock).to have_requested(:post, 'http://www.example.com:3000/custom/path/create')
41
+ end
42
+
43
+ it 'sends requests to path ending in "/"' do
44
+ stub_request(:post, 'http://www.example.com:3000/custom/path/create')
45
+ proxy.create('custom/path/')
46
+ expect(WebMock).to have_requested(:post, 'http://www.example.com:3000/custom/path/create')
47
+ end
48
+
49
+ it 'sends correct headers' do
50
+ stub_request(:post, 'http://www.example.com:3000/custom/path/create')
51
+ proxy.create('custom/path', headers: { option: 'val' })
52
+ expect(WebMock).to have_requested(:post, 'http://www.example.com:3000/custom/path/create')
53
+ .with(headers: { 'Content-Type': 'application/json',
54
+ option: 'val' })
55
+ end
56
+
57
+ it 'sends the correct body' do
58
+ stub_request(:post, 'http://www.example.com:3000/custom/path/create')
59
+ proxy.create('custom/path',
60
+ create_request: MarbleApiClient::Requests::Create.new(record: { name: 'blue' }))
61
+ expect(WebMock).to have_requested(:post, 'http://www.example.com:3000/custom/path/create')
62
+ .with(body: { context: {}, record: { name: 'blue' } })
63
+ end
64
+ end
65
+
66
+ context 'index' do
67
+ it 'sends to requested path' do
68
+ stub_request(:post, 'http://www.example.com:3000/custom/path/index')
69
+ proxy.index('custom/path')
70
+ expect(WebMock).to have_requested(:post, 'http://www.example.com:3000/custom/path/index')
71
+ end
72
+
73
+ it 'sends the correct headers' do
74
+ stub_request(:post, 'http://www.example.com:3000/custom/path/index')
75
+ proxy.index('custom/path', headers: { option: 'val' })
76
+ expect(WebMock).to have_requested(:post, 'http://www.example.com:3000/custom/path/index')
77
+ .with(headers: { 'Content-Type': 'application/json',
78
+ option: 'val' })
79
+ end
80
+
81
+ it 'sends the correct body' do
82
+ stub_request(:post, 'http://www.example.com:3000/custom/path/index')
83
+ proxy.index('custom/path',
84
+ index_request: MarbleApiClient::Requests::Index.new(record: { name: 'blue' }))
85
+ expect(WebMock).to have_requested(:post, 'http://www.example.com:3000/custom/path/index')
86
+ .with(body: { context: {}, record: { name: 'blue' }, page: 1, page_size: 25 })
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,30 @@
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 'spec_helper'
11
+
12
+ RSpec.describe MarbleApiClient::Requests::Create do
13
+ it 'builds the body' do
14
+ request = MarbleApiClient::Requests::Create.new(
15
+ context: { red: 'blue' },
16
+ record: { green: 'yellow' }
17
+ )
18
+
19
+ expected = {
20
+ context: {
21
+ red: 'blue'
22
+ },
23
+ record: {
24
+ green: 'yellow'
25
+ }
26
+ }.to_json
27
+
28
+ expect(request.request_body).to eq(expected)
29
+ end
30
+ end
@@ -0,0 +1,34 @@
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 'spec_helper'
11
+
12
+ RSpec.describe MarbleApiClient::Requests::Index do
13
+ it 'builds the body' do
14
+ request = MarbleApiClient::Requests::Index.new(
15
+ context: { red: 'blue' },
16
+ record: { green: 'yellow' },
17
+ page: 123,
18
+ page_size: 10
19
+ )
20
+
21
+ expected = {
22
+ context: {
23
+ red: 'blue'
24
+ },
25
+ record: {
26
+ green: 'yellow'
27
+ },
28
+ page: 123,
29
+ page_size: 10
30
+ }.to_json
31
+
32
+ expect(request.request_body).to eq(expected)
33
+ end
34
+ end
@@ -0,0 +1,24 @@
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 'spec_helper'
11
+
12
+ RSpec.describe MarbleApiClient::Responses::BadRequest do
13
+ context 'provides' do
14
+ let(:error_hash) { { name: 'invalid' }.to_json }
15
+ let(:response) do
16
+ instance_double(Net::HTTPResponse, code: 400, body: { errors: error_hash }.to_json)
17
+ end
18
+
19
+ it 'errors' do
20
+ expect(described_class.new(response).errors)
21
+ .to eq(error_hash)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,21 @@
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 'spec_helper'
11
+
12
+ RSpec.describe MarbleApiClient::Responses::ClientError do
13
+ let(:error_hash) { { name: 'invalid' }.to_json }
14
+ let(:response) do
15
+ instance_double(Net::HTTPResponse, code: 400, body: { errors: error_hash }.to_json)
16
+ end
17
+
18
+ it 'has access to response code' do
19
+ expect(described_class.new(response).code).to eq(400)
20
+ end
21
+ end
@@ -0,0 +1,31 @@
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 'spec_helper'
11
+
12
+ RSpec.describe MarbleApiClient::Responses::Forbidden do
13
+ context 'provides' do
14
+ let(:response) do
15
+ instance_double(Net::HTTPResponse,
16
+ code: 400,
17
+ body: { statusCode: '403',
18
+ redirectUrl: 'www.example.com/hello' }.to_json)
19
+ end
20
+
21
+ it 'Status Code' do
22
+ expect(described_class.new(response).status_code)
23
+ .to eq('403')
24
+ end
25
+
26
+ it 'Redirect URL' do
27
+ expect(described_class.new(response).redirect_url)
28
+ .to eq('www.example.com/hello')
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,77 @@
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 'spec_helper'
11
+
12
+ RSpec.describe MarbleApiClient::Responses::List do
13
+ context 'provides' do
14
+ let(:page) { '7' }
15
+ let(:page_size) { '12' }
16
+ let(:meta) { { grid_color: 'blue' }.to_json }
17
+ let(:records) { [{ name: 'record_1' }, { name: 'record_2' }].to_json }
18
+ let(:sort_direction) { 'ASC' }
19
+ let(:sort_column_index) { '3' }
20
+ let(:total) { '120' }
21
+ let(:total_pages) { '10' }
22
+ let(:response) do
23
+ instance_double(Net::HTTPResponse,
24
+ code: 400,
25
+ body: {
26
+ page: page,
27
+ pageSize: page_size,
28
+ meta: meta,
29
+ records: records,
30
+ sortDirection: sort_direction,
31
+ sortColumnIndex: sort_column_index,
32
+ total: total,
33
+ totalPages: total_pages
34
+ }.to_json)
35
+ end
36
+
37
+ it 'page' do
38
+ expect(described_class.new(response).page)
39
+ .to eq(page)
40
+ end
41
+
42
+ it 'page_size' do
43
+ expect(described_class.new(response).page_size)
44
+ .to eq(page_size)
45
+ end
46
+
47
+ it 'meta' do
48
+ expect(described_class.new(response).meta)
49
+ .to eq(meta)
50
+ end
51
+
52
+ it 'records' do
53
+ expect(described_class.new(response).records)
54
+ .to eq(records)
55
+ end
56
+
57
+ it 'sort driection' do
58
+ expect(described_class.new(response).sort_direction)
59
+ .to eq(sort_direction)
60
+ end
61
+
62
+ it 'sort column index' do
63
+ expect(described_class.new(response).sort_column_index)
64
+ .to eq(sort_column_index)
65
+ end
66
+
67
+ it 'total' do
68
+ expect(described_class.new(response).total)
69
+ .to eq(total)
70
+ end
71
+
72
+ it 'total pages' do
73
+ expect(described_class.new(response).total_pages)
74
+ .to eq(total_pages)
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,24 @@
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 'spec_helper'
11
+
12
+ RSpec.describe MarbleApiClient::Responses::NotFound do
13
+ context 'provides' do
14
+ let(:error_hash) { { name: 'invalid' }.to_json }
15
+ let(:response) do
16
+ instance_double(Net::HTTPResponse, code: 400, body: { errors: error_hash }.to_json)
17
+ end
18
+
19
+ it 'errors' do
20
+ expect(described_class.new(response).errors)
21
+ .to eq(error_hash)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
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 'spec_helper'
11
+
12
+ RSpec.describe MarbleApiClient::Responses::NotImplemented do
13
+ context 'provides' do
14
+ let(:error_hash) { { name: 'invalid' }.to_json }
15
+ let(:response) do
16
+ instance_double(Net::HTTPResponse, code: 400, body: { errors: error_hash }.to_json)
17
+ end
18
+
19
+ it 'errors' do
20
+ expect(described_class.new(response).errors)
21
+ .to eq(error_hash)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
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 'spec_helper'
11
+
12
+ RSpec.describe MarbleApiClient::Responses::Record do
13
+ context 'provides' do
14
+ let(:record) { { name: 'record_1' }.to_json }
15
+ let(:response) do
16
+ instance_double(Net::HTTPResponse, code: 400, body: { record: record }.to_json)
17
+ end
18
+
19
+ it 'errors' do
20
+ expect(described_class.new(response).record)
21
+ .to eq(record)
22
+ end
23
+ end
24
+ end