shift_commerce-oms_api_client 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c22d8bbfb4d12a2e03b19a50a8db61c9fae98f46e3676c155d5f0fa1fd3bd788
4
+ data.tar.gz: f8608af40ebec634cfa24b11bae49dd0a37bf594f3ffd448b995d146914b6afd
5
+ SHA512:
6
+ metadata.gz: 6b8131bce04e95e5bebbe7357787904f36dec799d78c56254c1b7752411966f48eff976dbb482906de5baeaf5d2b4c1e05c738375fe15de5bce49bab72b38309
7
+ data.tar.gz: 6197216f60aec50734d890ce1e2489e546b169ee8bc4daeef078088d10f1b009aa8c57fae7ac83f25eefd840d630f0e087855307518fcb06877608feb4c28665
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.2
6
+ before_install: gem install bundler -v 2.1.4
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in shift_commerce-oms_api_client.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,40 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ shift_commerce-oms_api_client (1.0.0)
5
+ json-schema (~> 2.8)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.7.0)
11
+ public_suffix (>= 2.0.2, < 5.0)
12
+ diff-lcs (1.4.4)
13
+ json-schema (2.8.1)
14
+ addressable (>= 2.4)
15
+ public_suffix (4.0.6)
16
+ rake (12.3.3)
17
+ rspec (3.10.0)
18
+ rspec-core (~> 3.10.0)
19
+ rspec-expectations (~> 3.10.0)
20
+ rspec-mocks (~> 3.10.0)
21
+ rspec-core (3.10.1)
22
+ rspec-support (~> 3.10.0)
23
+ rspec-expectations (3.10.1)
24
+ diff-lcs (>= 1.2.0, < 2.0)
25
+ rspec-support (~> 3.10.0)
26
+ rspec-mocks (3.10.2)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.10.0)
29
+ rspec-support (3.10.2)
30
+
31
+ PLATFORMS
32
+ ruby
33
+
34
+ DEPENDENCIES
35
+ rake (~> 12.0)
36
+ rspec (~> 3.0)
37
+ shift_commerce-oms_api_client!
38
+
39
+ BUNDLED WITH
40
+ 2.1.4
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # ShiftCommerce::OmsApiClient
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/shift_commerce/oms_api_client`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'shift_commerce-oms_api_client'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install shift_commerce-oms_api_client
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/paulspringett/shift_commerce-oms_api_client.
36
+
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/TASK.md ADDED
@@ -0,0 +1,115 @@
1
+ ## Tasks
2
+
3
+ 4. Convert the fulfillments and cancellations into valid payloads and submit them to the Shift OMS.
4
+
5
+ The Shift OMS provides two endpoints, one for fulfilling an order and another for cancelling. As a convenience, we've provided an Ruby API client to do this.
6
+
7
+ ### Setup
8
+
9
+ Add the gem to your Gemfile:
10
+
11
+ ```ruby
12
+ # Gemfile
13
+
14
+ gem "shift_commerce-oms-api-client"
15
+ ```
16
+
17
+ Install:
18
+
19
+ ```
20
+ bundle install
21
+ ```
22
+
23
+ ### Recording fulfillments
24
+
25
+ Create a new client:
26
+
27
+ ```ruby
28
+ client = ShiftCommerce::OmsApiClient.new
29
+ ```
30
+
31
+ Record the fulfillment:
32
+
33
+ ```ruby
34
+ response = client.record_fulfillment(valid_payload)
35
+ response.status_code
36
+ # => 201
37
+ response.data
38
+ # => {success: true}
39
+
40
+ response = client.record_fulfillment(invalid_payload)
41
+ response.status_code
42
+ # => 422
43
+ response.data
44
+ # => {success: false, error: "The property '#/data/attributes' did not contain a required property of 'account_reference'"}
45
+ ```
46
+
47
+ The following is an example of a valid payload:
48
+
49
+ ```json
50
+ // Example fulfillment payload
51
+
52
+ {
53
+ "data": {
54
+ "type": "record_fulfillment",
55
+ "attributes": {
56
+ "account_reference": "acme",
57
+ "order_reference": "500324412",
58
+ "shipments": [
59
+ {
60
+ "line_items": [
61
+ {
62
+ "sku": "MG60-D15-81400-small",
63
+ "quantity": 1
64
+ }
65
+ ],
66
+ "tracking_codes": [
67
+ {
68
+ "url": "https://somecourier.com/?tracking_code=examplecode8279278"
69
+ }
70
+ ],
71
+ "shipped_at": "2020-01-08T12:01:01Z"
72
+ }
73
+ ]
74
+ }
75
+ }
76
+ }
77
+ ```
78
+
79
+ ### Cancelling orders
80
+
81
+ Create a new client:
82
+
83
+ ```ruby
84
+ client = ShiftCommerce::OmsApiClient.new
85
+ ```
86
+
87
+ Record the fulfillment:
88
+
89
+ ```ruby
90
+ response = client.cancel_order(valid_payload)
91
+ response.status_code
92
+ # => 201
93
+ response.data
94
+ # => {success: true}
95
+
96
+ response = client.cancel_order(invalid_payload)
97
+ response.status_code
98
+ # => 422
99
+ response.data
100
+ # => {success: false, error: "The property '#/data/attributes' did not contain a required property of 'account_reference'"}
101
+ ```
102
+
103
+ ```json
104
+ // Example cancellation payload
105
+
106
+ {
107
+ "data": {
108
+ "type": "cancel_order",
109
+ "attributes": {
110
+ "account_reference": "acme",
111
+ "order_reference": "500324412"
112
+ }
113
+ }
114
+ }
115
+ ```
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "shift_commerce/oms_api_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__)
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,35 @@
1
+ require "shift_commerce/oms_api_client/version"
2
+
3
+ require "json"
4
+ require "json-schema"
5
+
6
+ module ShiftCommerce
7
+ Response = Struct.new(:status_code, :data)
8
+ class OmsApiClient
9
+ def record_fulfillment(payload)
10
+ JSON::Validator.validate!(record_fulfillment_schema, payload)
11
+ Response.new(201, {success: true})
12
+ rescue JSON::Schema::ValidationError => ex
13
+ Response.new(422, {success: false, error: ex.message})
14
+ end
15
+
16
+ def cancel_order(payload)
17
+ JSON::Validator.validate!(cancel_order_schema, payload)
18
+ Response.new(201, {success: true})
19
+ rescue JSON::Schema::ValidationError => ex
20
+ Response.new(422, {success: false, error: ex.message})
21
+ end
22
+
23
+ private
24
+
25
+ def record_fulfillment_schema
26
+ @record_fulfillment_schema ||=
27
+ JSON.parse(File.read("schemas/record_fulfillment.json"))
28
+ end
29
+
30
+ def cancel_order_schema
31
+ @cancel_order_schema ||=
32
+ JSON.parse(File.read("schemas/cancel_order.json"))
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,5 @@
1
+ module ShiftCommerce
2
+ class OmsApiClient
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,39 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-04/schema",
3
+ "type": "object",
4
+ "required": [
5
+ "data"
6
+ ],
7
+ "properties": {
8
+ "data": {
9
+ "type": "object",
10
+ "required": [
11
+ "type",
12
+ "attributes"
13
+ ],
14
+ "properties": {
15
+ "type": {
16
+ "const": "cancel_order"
17
+ },
18
+ "attributes": {
19
+ "type": "object",
20
+ "required": [
21
+ "account_reference",
22
+ "order_reference"
23
+ ],
24
+ "properties": {
25
+ "account_reference": {
26
+ "type": "string"
27
+ },
28
+ "order_reference": {
29
+ "type": "string"
30
+ }
31
+ },
32
+ "additionalProperties": false
33
+ }
34
+ },
35
+ "additionalProperties": false
36
+ }
37
+ },
38
+ "additionalProperties": false
39
+ }
@@ -0,0 +1,105 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-04/schema",
3
+ "type": "object",
4
+ "required": [
5
+ "data"
6
+ ],
7
+ "properties": {
8
+ "data": {
9
+ "type": "object",
10
+ "required": [
11
+ "type",
12
+ "attributes"
13
+ ],
14
+ "properties": {
15
+ "type": {
16
+ "const": "record_fulfillment"
17
+ },
18
+ "attributes": {
19
+ "type": "object",
20
+ "required": [
21
+ "account_reference",
22
+ "order_reference",
23
+ "shipments"
24
+ ],
25
+ "properties": {
26
+ "account_reference": {
27
+ "type": "string"
28
+ },
29
+ "order_reference": {
30
+ "type": "string"
31
+ },
32
+ "shipments": {
33
+ "type": "array",
34
+ "additionalItems": true,
35
+ "items": {
36
+ "anyOf": [
37
+ {
38
+ "type": "object",
39
+ "required": [
40
+ "line_items",
41
+ "shipped_at"
42
+ ],
43
+ "properties": {
44
+ "line_items": {
45
+ "type": "array",
46
+ "additionalItems": true,
47
+ "items": {
48
+ "anyOf": [
49
+ {
50
+ "type": "object",
51
+ "required": [
52
+ "sku",
53
+ "quantity"
54
+ ],
55
+ "properties": {
56
+ "sku": {
57
+ "type": "string"
58
+ },
59
+ "quantity": {
60
+ "type": "integer"
61
+ }
62
+ },
63
+ "additionalProperties": false
64
+ }
65
+ ]
66
+ }
67
+ },
68
+ "tracking_codes": {
69
+ "type": "array",
70
+ "additionalItems": true,
71
+ "items": {
72
+ "anyOf": [
73
+ {
74
+ "type": "object",
75
+ "required": [
76
+ "url"
77
+ ],
78
+ "properties": {
79
+ "url": {
80
+ "type": "string"
81
+ }
82
+ },
83
+ "additionalProperties": false
84
+ }
85
+ ]
86
+ }
87
+ },
88
+ "shipped_at": {
89
+ "type": "string"
90
+ }
91
+ },
92
+ "additionalProperties": false
93
+ }
94
+ ]
95
+ }
96
+ }
97
+ },
98
+ "additionalProperties": false
99
+ }
100
+ },
101
+ "additionalProperties": false
102
+ }
103
+ },
104
+ "additionalProperties": false
105
+ }
@@ -0,0 +1,22 @@
1
+ require_relative "lib/shift_commerce/oms_api_client/version"
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "shift_commerce-oms_api_client"
5
+ spec.version = ShiftCommerce::OmsApiClient::VERSION
6
+ spec.authors = ["Paul Springett"]
7
+ spec.email = ["paul.springett@shiftcommerce.com"]
8
+
9
+ spec.summary = "Dummy API client for the SHIFT Commerce Ruby Exercise"
10
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
11
+
12
+ # Specify which files should be added to the gem when it is released.
13
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
14
+ spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
15
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ end
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "json-schema", "~> 2.8"
22
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shift_commerce-oms_api_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Paul Springett
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-05-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json-schema
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.8'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.8'
27
+ description:
28
+ email:
29
+ - paul.springett@shiftcommerce.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - ".rspec"
36
+ - ".travis.yml"
37
+ - Gemfile
38
+ - Gemfile.lock
39
+ - README.md
40
+ - Rakefile
41
+ - TASK.md
42
+ - bin/console
43
+ - bin/setup
44
+ - lib/shift_commerce/oms_api_client.rb
45
+ - lib/shift_commerce/oms_api_client/version.rb
46
+ - schemas/cancel_order.json
47
+ - schemas/record_fulfillment.json
48
+ - shift_commerce-oms_api_client.gemspec
49
+ homepage:
50
+ licenses: []
51
+ metadata: {}
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 2.3.0
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubygems_version: 3.1.4
68
+ signing_key:
69
+ specification_version: 4
70
+ summary: Dummy API client for the SHIFT Commerce Ruby Exercise
71
+ test_files: []