we_ship_client 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.env.example +7 -0
- data/.github/workflows/gem-push.yml +33 -0
- data/.github/workflows/specs.yml +35 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +118 -0
- data/LICENSE.txt +21 -0
- data/README.md +111 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/we_ship_client/client.rb +33 -0
- data/lib/we_ship_client/entities/address.rb +19 -0
- data/lib/we_ship_client/entities/base.rb +23 -0
- data/lib/we_ship_client/entities/order.rb +20 -0
- data/lib/we_ship_client/entities/order_item.rb +16 -0
- data/lib/we_ship_client/entities/order_items.rb +14 -0
- data/lib/we_ship_client/entities/process_orders_request.rb +24 -0
- data/lib/we_ship_client/entities/responses/order_accepted.rb +18 -0
- data/lib/we_ship_client/entities/responses/order_rejected.rb +17 -0
- data/lib/we_ship_client/entities/responses/process_orders.rb +17 -0
- data/lib/we_ship_client/entities/responses/proof_of_delivery.rb +18 -0
- data/lib/we_ship_client/entities/responses/rejected_orders.rb +17 -0
- data/lib/we_ship_client/entities/responses/track_order.rb +32 -0
- data/lib/we_ship_client/entities/responses/track_response.rb +16 -0
- data/lib/we_ship_client/entities/responses/tracking_item.rb +18 -0
- data/lib/we_ship_client/entities/track_request.rb +21 -0
- data/lib/we_ship_client/entities/types.rb +15 -0
- data/lib/we_ship_client/entities.rb +17 -0
- data/lib/we_ship_client/exceptions.rb +17 -0
- data/lib/we_ship_client/interactors/get_tracking.rb +119 -0
- data/lib/we_ship_client/interactors/process_orders.rb +63 -0
- data/lib/we_ship_client/token_client.rb +36 -0
- data/lib/we_ship_client/transforms/tracking_item.rb +136 -0
- data/lib/we_ship_client/version.rb +5 -0
- data/lib/we_ship_client.rb +15 -0
- data/we_ship_client.gemspec +33 -0
- metadata +186 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4a9ab972e96d49172e5934d5bd6ce9dda80cd309d4c9a12ae969a0b6571e5a0b
|
4
|
+
data.tar.gz: aae67d43ab246cefb44f098211bbb5d5c8700698b824b587112777b73bcc7b72
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6d9c64d5ba2a473cca8e7852529861a564080bb51146c21cf735ba6b6510bbc5ef58d580d4922994f3dc9e19bfb736753d4402296f696d1106a953f8d278f344
|
7
|
+
data.tar.gz: 66b82e1b2d136a712be2a9c28a17f45d127d856b173075f9272747fad61e6db01040a858c080298460e87e18c3924c8408001a37dc597dc70c4188f693ce0499
|
data/.env.example
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
name: Ruby Gem
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ "main" ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ "main" ]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
build:
|
11
|
+
name: Build + Publish
|
12
|
+
runs-on: ubuntu-latest
|
13
|
+
permissions:
|
14
|
+
contents: read
|
15
|
+
packages: write
|
16
|
+
|
17
|
+
steps:
|
18
|
+
- uses: actions/checkout@v3
|
19
|
+
- name: Set up Ruby 2.6
|
20
|
+
uses: actions/setup-ruby@v1
|
21
|
+
with:
|
22
|
+
ruby-version: 2.6.x
|
23
|
+
|
24
|
+
- name: Publish to RubyGems
|
25
|
+
run: |
|
26
|
+
mkdir -p $HOME/.gem
|
27
|
+
touch $HOME/.gem/credentials
|
28
|
+
chmod 0600 $HOME/.gem/credentials
|
29
|
+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
30
|
+
gem build *.gemspec
|
31
|
+
gem push *.gem
|
32
|
+
env:
|
33
|
+
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: Specs
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
branches: [ main ]
|
13
|
+
pull_request:
|
14
|
+
branches: [ main ]
|
15
|
+
|
16
|
+
jobs:
|
17
|
+
test:
|
18
|
+
|
19
|
+
runs-on: ubuntu-latest
|
20
|
+
strategy:
|
21
|
+
matrix:
|
22
|
+
ruby-version: ['2.7', '3.0']
|
23
|
+
|
24
|
+
steps:
|
25
|
+
- uses: actions/checkout@v2
|
26
|
+
- name: Set up Ruby
|
27
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
28
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
29
|
+
# uses: ruby/setup-ruby@v1
|
30
|
+
uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
|
31
|
+
with:
|
32
|
+
ruby-version: ${{ matrix.ruby-version }}
|
33
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
34
|
+
- name: Run tests
|
35
|
+
run: bundle exec rake spec
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -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 alessandro@juul.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
data/Gemfile.lock
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ../loogi_http
|
3
|
+
specs:
|
4
|
+
loogi_http (1.0.0)
|
5
|
+
faraday (~> 1.0.1)
|
6
|
+
faraday-cookie_jar (~> 0.0.6)
|
7
|
+
faraday_middleware (~> 1.0.0)
|
8
|
+
|
9
|
+
PATH
|
10
|
+
remote: .
|
11
|
+
specs:
|
12
|
+
we_ship_client (1.0.0)
|
13
|
+
activesupport
|
14
|
+
dry-struct (>= 0.6, < 1.5)
|
15
|
+
dry-types
|
16
|
+
loogi_http (~> 1.0)
|
17
|
+
|
18
|
+
GEM
|
19
|
+
remote: https://rubygems.org/
|
20
|
+
specs:
|
21
|
+
activesupport (6.1.4.6)
|
22
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
23
|
+
i18n (>= 1.6, < 2)
|
24
|
+
minitest (>= 5.1)
|
25
|
+
tzinfo (~> 2.0)
|
26
|
+
zeitwerk (~> 2.3)
|
27
|
+
addressable (2.8.0)
|
28
|
+
public_suffix (>= 2.0.2, < 5.0)
|
29
|
+
concurrent-ruby (1.1.9)
|
30
|
+
crack (0.4.5)
|
31
|
+
rexml
|
32
|
+
diff-lcs (1.5.0)
|
33
|
+
domain_name (0.5.20190701)
|
34
|
+
unf (>= 0.0.5, < 1.0.0)
|
35
|
+
dotenv (2.7.6)
|
36
|
+
dry-configurable (0.14.0)
|
37
|
+
concurrent-ruby (~> 1.0)
|
38
|
+
dry-core (~> 0.6)
|
39
|
+
dry-container (0.9.0)
|
40
|
+
concurrent-ruby (~> 1.0)
|
41
|
+
dry-configurable (~> 0.13, >= 0.13.0)
|
42
|
+
dry-core (0.7.1)
|
43
|
+
concurrent-ruby (~> 1.0)
|
44
|
+
dry-inflector (0.2.1)
|
45
|
+
dry-logic (1.2.0)
|
46
|
+
concurrent-ruby (~> 1.0)
|
47
|
+
dry-core (~> 0.5, >= 0.5)
|
48
|
+
dry-struct (1.4.0)
|
49
|
+
dry-core (~> 0.5, >= 0.5)
|
50
|
+
dry-types (~> 1.5)
|
51
|
+
ice_nine (~> 0.11)
|
52
|
+
dry-types (1.5.1)
|
53
|
+
concurrent-ruby (~> 1.0)
|
54
|
+
dry-container (~> 0.3)
|
55
|
+
dry-core (~> 0.5, >= 0.5)
|
56
|
+
dry-inflector (~> 0.1, >= 0.1.2)
|
57
|
+
dry-logic (~> 1.0, >= 1.0.2)
|
58
|
+
faraday (1.0.1)
|
59
|
+
multipart-post (>= 1.2, < 3)
|
60
|
+
faraday-cookie_jar (0.0.7)
|
61
|
+
faraday (>= 0.8.0)
|
62
|
+
http-cookie (~> 1.0.0)
|
63
|
+
faraday_middleware (1.0.0)
|
64
|
+
faraday (~> 1.0)
|
65
|
+
hashdiff (1.0.1)
|
66
|
+
http-cookie (1.0.4)
|
67
|
+
domain_name (~> 0.5)
|
68
|
+
i18n (1.10.0)
|
69
|
+
concurrent-ruby (~> 1.0)
|
70
|
+
ice_nine (0.11.2)
|
71
|
+
minitest (5.15.0)
|
72
|
+
multipart-post (2.1.1)
|
73
|
+
public_suffix (4.0.6)
|
74
|
+
rake (12.3.3)
|
75
|
+
rexml (3.2.5)
|
76
|
+
rspec (3.10.0)
|
77
|
+
rspec-core (~> 3.10.0)
|
78
|
+
rspec-expectations (~> 3.10.0)
|
79
|
+
rspec-mocks (~> 3.10.0)
|
80
|
+
rspec-core (3.10.1)
|
81
|
+
rspec-support (~> 3.10.0)
|
82
|
+
rspec-expectations (3.10.2)
|
83
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
84
|
+
rspec-support (~> 3.10.0)
|
85
|
+
rspec-mocks (3.10.2)
|
86
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
87
|
+
rspec-support (~> 3.10.0)
|
88
|
+
rspec-support (3.10.3)
|
89
|
+
stub_env (1.0.4)
|
90
|
+
rspec (>= 2.0, < 4.0)
|
91
|
+
tzinfo (2.0.4)
|
92
|
+
concurrent-ruby (~> 1.0)
|
93
|
+
unf (0.1.4)
|
94
|
+
unf_ext
|
95
|
+
unf_ext (0.0.8)
|
96
|
+
vcr (6.0.0)
|
97
|
+
webmock (3.14.0)
|
98
|
+
addressable (>= 2.8.0)
|
99
|
+
crack (>= 0.3.2)
|
100
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
101
|
+
zeitwerk (2.5.4)
|
102
|
+
|
103
|
+
PLATFORMS
|
104
|
+
x86_64-darwin-20
|
105
|
+
x86_64-darwin-21
|
106
|
+
|
107
|
+
DEPENDENCIES
|
108
|
+
dotenv (~> 2.7)
|
109
|
+
loogi_http (~> 1.0)!
|
110
|
+
rake (~> 12.0)
|
111
|
+
rspec (~> 3.0)
|
112
|
+
stub_env
|
113
|
+
vcr
|
114
|
+
we_ship_client!
|
115
|
+
webmock
|
116
|
+
|
117
|
+
BUNDLED WITH
|
118
|
+
2.2.32
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 JUUL Labs
|
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,111 @@
|
|
1
|
+
# WeShipClient
|
2
|
+
|
3
|
+
[![Specs](https://github.com/JuulLabs-OSS/we_ship_client/actions/workflows/specs.yml/badge.svg)](https://github.com/JuulLabs-OSS/we_ship_client/actions/workflows/specs.yml)
|
4
|
+
|
5
|
+
This is a Ruby client for the We Ship Express V2 API provided by https://www.weshipexpress.com/
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'we_ship_client'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install we_ship_client
|
22
|
+
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
First, set the required environment variables and load them in your app, using your preferred method (dotenv, figaro etc.).
|
27
|
+
See `.env.example` for a reference.
|
28
|
+
|
29
|
+
### Get Tracking
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
auth_token = WeShipClient::TokenClient.new.generate_access_token
|
33
|
+
|
34
|
+
request = WeShipClient::Entities::TrackRequest.new(
|
35
|
+
customer_code: [ENV['WE_SHIP_CUSTOMER_CODE']],
|
36
|
+
internal_tracking_num: [your_tracking_number]
|
37
|
+
)
|
38
|
+
|
39
|
+
response = WeShipClient::Interactors::GetTracking.new(
|
40
|
+
auth_token: auth_token,
|
41
|
+
track_request: request
|
42
|
+
).call
|
43
|
+
```
|
44
|
+
|
45
|
+
### Process Orders
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
auth_token = WeShipClient::TokenClient.new.generate_access_token
|
49
|
+
|
50
|
+
orders = [
|
51
|
+
WeShipClient::Entities::Order.new(
|
52
|
+
orderNo: 'ABC123',
|
53
|
+
orderDate: '2021-01-01',
|
54
|
+
shipMethod: '',
|
55
|
+
fulfillmentLocation: 'XXX',
|
56
|
+
shipToAddress: WeShipClient::Entities::Address.new(
|
57
|
+
name: 'Name',
|
58
|
+
address1: 'Address 1'
|
59
|
+
address2: 'Address 2',
|
60
|
+
city: 'New York',
|
61
|
+
state: 'NY',
|
62
|
+
postalCode: '12345',
|
63
|
+
country: 'US',
|
64
|
+
homePhone: '+123456789'
|
65
|
+
),
|
66
|
+
orderItems: WeShipClient::Entities::OrderItems.new(
|
67
|
+
orderItem: [
|
68
|
+
WeShipClient::Entities::OrderItem.new(
|
69
|
+
productName: 'Item name',
|
70
|
+
productSKU: 'SKU',
|
71
|
+
productType: 'XXX',
|
72
|
+
quantity: 1,
|
73
|
+
weight: '10'
|
74
|
+
)
|
75
|
+
]
|
76
|
+
)
|
77
|
+
)
|
78
|
+
]
|
79
|
+
|
80
|
+
request = WeShipClient::Entities::ProcessOrdersRequest.new(
|
81
|
+
clientCode: ENV['WE_SHIP_CUSTOMER_CODE'],
|
82
|
+
order: orders
|
83
|
+
)
|
84
|
+
|
85
|
+
response = WeShipClient::Interactors::ProcessOrders.new(
|
86
|
+
auth_token: auth_token,
|
87
|
+
process_orders_request: request
|
88
|
+
).call
|
89
|
+
```
|
90
|
+
|
91
|
+
## Development
|
92
|
+
|
93
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
94
|
+
|
95
|
+
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).
|
96
|
+
|
97
|
+
To execute tests, run `bundle exec rake spec`.
|
98
|
+
|
99
|
+
## Contributing
|
100
|
+
|
101
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/JuulLabs-OSS/we_ship_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.
|
102
|
+
|
103
|
+
## License
|
104
|
+
|
105
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
106
|
+
|
107
|
+
## Code of Conduct
|
108
|
+
|
109
|
+
Everyone interacting in the Test project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/JuulLabs-OSS/we_ship_client/blob/master/CODE_OF_CONDUCT.md).
|
110
|
+
|
111
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'we_ship_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,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'loogi_http'
|
4
|
+
require 'loogi_http/connection'
|
5
|
+
|
6
|
+
module WeShipClient
|
7
|
+
class Client
|
8
|
+
DEFAULT_TIMEOUT = 90
|
9
|
+
|
10
|
+
attr_reader :http_client, :logger
|
11
|
+
|
12
|
+
# @param http_client [LoogiHttp::Connection]
|
13
|
+
# @param logger [Logger]
|
14
|
+
# @param timeout [Integer,nil] The request timeout
|
15
|
+
def initialize(http_client: LoogiHttp::Connection, logger: LoogiHttp.logger, timeout: nil)
|
16
|
+
timeout ||= DEFAULT_TIMEOUT
|
17
|
+
|
18
|
+
@http_client = http_client.new(
|
19
|
+
Faraday::Connection.new do |connection|
|
20
|
+
connection.request :json
|
21
|
+
connection.adapter Faraday.default_adapter
|
22
|
+
connection.options[:open_timeout] = timeout
|
23
|
+
connection.options[:timeout] = timeout
|
24
|
+
end
|
25
|
+
)
|
26
|
+
@logger = logger
|
27
|
+
end
|
28
|
+
|
29
|
+
def base_url
|
30
|
+
ENV['WE_SHIP_BASE_URL']
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'we_ship_client/entities/base'
|
4
|
+
|
5
|
+
module WeShipClient
|
6
|
+
module Entities
|
7
|
+
# A shipping/billing address.
|
8
|
+
class Address < Base
|
9
|
+
attribute :name, Types::Strict::String
|
10
|
+
attribute :address1, Types::Strict::String
|
11
|
+
attribute? :address2, Types::Strict::String.optional
|
12
|
+
attribute :city, Types::Strict::String
|
13
|
+
attribute :state, Types::Strict::String
|
14
|
+
attribute :postalCode, Types::Strict::String
|
15
|
+
attribute :country, Types::Strict::String
|
16
|
+
attribute :homePhone, Types::Strict::String
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dry-struct'
|
4
|
+
require_relative 'types'
|
5
|
+
|
6
|
+
module WeShipClient
|
7
|
+
module Entities
|
8
|
+
class Base < Dry::Struct
|
9
|
+
transform_keys(&:to_sym)
|
10
|
+
|
11
|
+
# This sets dry types to use the default value when nil is passed
|
12
|
+
transform_types do |type|
|
13
|
+
if type.default?
|
14
|
+
type.constructor do |value|
|
15
|
+
value.nil? ? Dry::Types::Undefined : value
|
16
|
+
end
|
17
|
+
else
|
18
|
+
type
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'we_ship_client/entities/base'
|
4
|
+
require 'we_ship_client/entities/address'
|
5
|
+
require 'we_ship_client/entities/order_items'
|
6
|
+
|
7
|
+
module WeShipClient
|
8
|
+
module Entities
|
9
|
+
# A single order with all the details.
|
10
|
+
class Order < Base
|
11
|
+
attribute :orderNo, Types::Strict::String
|
12
|
+
attribute :orderDate, Types::Strict::String
|
13
|
+
attribute :shipMethod, Types::Strict::String
|
14
|
+
attribute :fulfillmentLocation, Types::Strict::String
|
15
|
+
attribute? :billToAddress, Address.optional
|
16
|
+
attribute :shipToAddress, Address
|
17
|
+
attribute :orderItems, OrderItems
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'we_ship_client/entities/base'
|
4
|
+
|
5
|
+
module WeShipClient
|
6
|
+
module Entities
|
7
|
+
# A single order item.
|
8
|
+
class OrderItem < Base
|
9
|
+
attribute :productName, Types::Strict::String
|
10
|
+
attribute :productSKU, Types::Strict::String
|
11
|
+
attribute :productType, Types::Strict::String.default(ENV['WE_SHIP_DEFAULT_PRODUCT_TYPE'])
|
12
|
+
attribute :quantity, Types::Strict::Integer
|
13
|
+
attribute :weight, Types::Strict::String
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'we_ship_client/entities/base'
|
4
|
+
require 'we_ship_client/entities/order_item'
|
5
|
+
|
6
|
+
module WeShipClient
|
7
|
+
module Entities
|
8
|
+
# Just a container for the order items list.
|
9
|
+
# Note the singular "orderItem" name that may be confusing.
|
10
|
+
class OrderItems < Base
|
11
|
+
attribute :orderItem, Types::Strict::Array.of(OrderItem).constrained(min_size: 1)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'we_ship_client/entities/base'
|
4
|
+
require 'we_ship_client/entities/order'
|
5
|
+
|
6
|
+
module WeShipClient
|
7
|
+
module Entities
|
8
|
+
# The request payload used by `Interactors::ProcessOrders`.
|
9
|
+
class ProcessOrdersRequest < Base
|
10
|
+
# NOTE: The order of these attributes MUST remain this way
|
11
|
+
# or the API will not properly handle the request and instead
|
12
|
+
# throw: {
|
13
|
+
# :response=>{
|
14
|
+
# :invalidrequest=>{
|
15
|
+
# :description=>"Invalid content was found starting with element 'clientCode'. One of '{order}' is expected.",
|
16
|
+
# :status=>"Fail"
|
17
|
+
# }}}
|
18
|
+
attribute :formatVersion, Types::Strict::String.default(ENV['WE_SHIP_FORMAT_VERSION'])
|
19
|
+
attribute :clientCode, Types::Strict::String.default(ENV['WE_SHIP_CUSTOMER_CODE'])
|
20
|
+
attribute :allowDuplicates, Types::Strict::String.default(ENV['WE_SHIP_ALLOW_DUPLICATES'])
|
21
|
+
attribute :order, Types::Strict::Array.of(Order)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'we_ship_client/entities/base'
|
4
|
+
|
5
|
+
module WeShipClient
|
6
|
+
module Entities
|
7
|
+
module Responses
|
8
|
+
# Details of a single accepted order.
|
9
|
+
class OrderAccepted < Base
|
10
|
+
attribute :description, Types::Strict::String
|
11
|
+
attribute :orderId, Types::Strict::String
|
12
|
+
attribute :referenceNo, Types::Strict::String
|
13
|
+
attribute :status, Types::Strict::String
|
14
|
+
attribute :type, Types::Strict::String
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'we_ship_client/entities/base'
|
4
|
+
|
5
|
+
module WeShipClient
|
6
|
+
module Entities
|
7
|
+
module Responses
|
8
|
+
# Details of a single rejected order.
|
9
|
+
class OrderRejected < Base
|
10
|
+
attribute :description, Types::Strict::String
|
11
|
+
attribute? :referenceNo, Types::Strict::String.optional
|
12
|
+
attribute :status, Types::Strict::String
|
13
|
+
attribute? :type, Types::Strict::String.optional
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|