jumingo 0.1.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 +7 -0
- data/.rspec +3 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +110 -0
- data/Rakefile +8 -0
- data/lib/jumingo/client.rb +174 -0
- data/lib/jumingo/configuration.rb +21 -0
- data/lib/jumingo/errors.rb +25 -0
- data/lib/jumingo/models.rb +40 -0
- data/lib/jumingo/version.rb +5 -0
- data/lib/jumingo.rb +17 -0
- data/openapi/jumingo.yaml +4778 -0
- data/sig/jumingo.rbs +16 -0
- metadata +116 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 6233763808ce1fed9b129928f7db7e3aed8d26415efd276ec8dcf3ffbe914abc
|
|
4
|
+
data.tar.gz: 240cb46f9433f6761d50f3af48ffe80761207d97daba215e8d0e90beba1e0695
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: efe908457dac34c1b8fe1052b19bec09ac888fd98f4b0b6e3aaabdf17e14844cedecbe9387020485f77892f2bfeb047ae44ec6e177340f9c70a9b74e0eedcde9
|
|
7
|
+
data.tar.gz: f3a79cf35dac453a21a693985787ddeb6b7b871788f06cc58dc221cea141daf2cbe600e61c370608f0816c1932407513671cc4330991eba8b4f810a090f8142e
|
data/.rspec
ADDED
data/CHANGELOG.md
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 florian2
|
|
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,110 @@
|
|
|
1
|
+
# Jumingo
|
|
2
|
+
|
|
3
|
+
Ruby client for the Jumingo shipping API.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Install the gem and add to the application's Gemfile by executing:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
bundle add jumingo
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
gem install jumingo
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
```ruby
|
|
22
|
+
require "jumingo"
|
|
23
|
+
|
|
24
|
+
client = Jumingo::Client.new(
|
|
25
|
+
Jumingo::Configuration.new.tap do |config|
|
|
26
|
+
config.api_key = "your-api-key"
|
|
27
|
+
config.base_url = "https://api.jumingo.com"
|
|
28
|
+
config.timeout = 30
|
|
29
|
+
config.open_timeout = 10
|
|
30
|
+
end
|
|
31
|
+
)
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Jumingo::Client API Reference
|
|
35
|
+
|
|
36
|
+
Carrier:
|
|
37
|
+
- `POST /v1/carrier/access-points-search` → `carrier_access_points_search(payload)`
|
|
38
|
+
|
|
39
|
+
Cart:
|
|
40
|
+
- `POST /v1/cart/total` → `cart_total(payload)`
|
|
41
|
+
|
|
42
|
+
Connections:
|
|
43
|
+
- `GET /v1/connections` → `list_connections(params: {})`
|
|
44
|
+
- `GET /v1/connections/{uuid}` → `get_connection(uuid)`
|
|
45
|
+
- `POST /v1/connections` → `create_connection(payload)`
|
|
46
|
+
|
|
47
|
+
Orders:
|
|
48
|
+
- `GET /v1/orders` → `list_orders(params: {})`
|
|
49
|
+
- `GET /v1/orders/{id}` → `get_order(id)`
|
|
50
|
+
- `GET /v1/orders/{id}/documents` → `get_order_documents(id)`
|
|
51
|
+
- `POST /v1/orders` → `create_order(payload)`
|
|
52
|
+
|
|
53
|
+
Shipments:
|
|
54
|
+
- `GET /v1/shipments` → `list_shipments(params: {})`
|
|
55
|
+
- `GET /v1/shipments/{shipment_id}` → `get_shipment(shipment_id)`
|
|
56
|
+
- `POST /v1/shipments` → `create_shipment(payload)`
|
|
57
|
+
- `PUT /v1/shipments/{shipment_id}` → `update_shipment(shipment_id, payload)`
|
|
58
|
+
- `PATCH /v1/shipments/{shipment_id}` → `patch_shipment(shipment_id, payload)`
|
|
59
|
+
- `DELETE /v1/shipments/{shipment_id}` → `delete_shipment(shipment_id)`
|
|
60
|
+
- `POST /v1/shipments/cheapest` → `cheapest_shipment_rate(payload, params: {})`
|
|
61
|
+
- `POST /v1/shipments/{uuid}/file/upload/{type}` → `upload_shipment_file(uuid, type, file)`
|
|
62
|
+
- `DELETE /v1/shipments/{uuid}/file/upload/{type}` → `delete_shipment_file(uuid, type)`
|
|
63
|
+
|
|
64
|
+
Shipment Rates:
|
|
65
|
+
- `POST /v1/shipment-rates` → `create_shipment_rate(payload)`
|
|
66
|
+
|
|
67
|
+
### Example Calls
|
|
68
|
+
|
|
69
|
+
```ruby
|
|
70
|
+
client.list_orders(params: { page: 1, itemsPerPage: 20 })
|
|
71
|
+
client.create_shipment({ reference: "ORDER-123" })
|
|
72
|
+
client.upload_shipment_file("s_fbf8e2a57185478194fa264583b5b388", "commercial-invoice", "/path/to/invoice.pdf")
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Pagination Helper
|
|
76
|
+
|
|
77
|
+
```ruby
|
|
78
|
+
client.each_page("/orders", params: { itemsPerPage: 50 }) do |orders|
|
|
79
|
+
puts orders.count
|
|
80
|
+
end
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Error Handling
|
|
84
|
+
|
|
85
|
+
```ruby
|
|
86
|
+
begin
|
|
87
|
+
client.get_order("missing-id")
|
|
88
|
+
rescue Jumingo::Errors::NotFound => e
|
|
89
|
+
puts e.status
|
|
90
|
+
puts e.body
|
|
91
|
+
end
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### OpenAPI Source
|
|
95
|
+
|
|
96
|
+
The OpenAPI definition used to implement this client is stored at `openapi/jumingo.yaml`.
|
|
97
|
+
|
|
98
|
+
## Development
|
|
99
|
+
|
|
100
|
+
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.
|
|
101
|
+
|
|
102
|
+
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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
103
|
+
|
|
104
|
+
## Contributing
|
|
105
|
+
|
|
106
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/florian2/jumingo.
|
|
107
|
+
|
|
108
|
+
## License
|
|
109
|
+
|
|
110
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "faraday"
|
|
4
|
+
require "faraday/multipart"
|
|
5
|
+
require "json"
|
|
6
|
+
|
|
7
|
+
module Jumingo
|
|
8
|
+
class Client
|
|
9
|
+
BASE_PATH = "/v1"
|
|
10
|
+
|
|
11
|
+
def initialize(configuration = Jumingo.configuration)
|
|
12
|
+
@configuration = configuration
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def carrier_access_points_search(payload)
|
|
16
|
+
request_json(:post, "#{BASE_PATH}/carrier/access-points-search", body: payload)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def cart_total(payload)
|
|
20
|
+
request_json(:post, "#{BASE_PATH}/cart/total", body: payload)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def list_connections(params: {})
|
|
24
|
+
request_json(:get, "#{BASE_PATH}/connections", params: params)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def get_connection(uuid)
|
|
28
|
+
request_json(:get, "#{BASE_PATH}/connections/#{uuid}")
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def create_connection(payload)
|
|
32
|
+
request_json(:post, "#{BASE_PATH}/connections", body: payload)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def list_orders(params: {})
|
|
36
|
+
request_json(:get, "#{BASE_PATH}/orders", params: params)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def get_order(id)
|
|
40
|
+
request_json(:get, "#{BASE_PATH}/orders/#{id}")
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def get_order_documents(id)
|
|
44
|
+
request_json(:get, "#{BASE_PATH}/orders/#{id}/documents")
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def create_order(payload)
|
|
48
|
+
request_json(:post, "#{BASE_PATH}/orders", body: payload)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def list_shipments(params: {})
|
|
52
|
+
request_json(:get, "#{BASE_PATH}/shipments", params: params)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def get_shipment(shipment_id)
|
|
56
|
+
request_json(:get, "#{BASE_PATH}/shipments/#{shipment_id}")
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def create_shipment(payload)
|
|
60
|
+
request_json(:post, "#{BASE_PATH}/shipments", body: payload)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def update_shipment(shipment_id, payload)
|
|
64
|
+
request_json(:put, "#{BASE_PATH}/shipments/#{shipment_id}", body: payload)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def patch_shipment(shipment_id, payload)
|
|
68
|
+
request_json(:patch, "#{BASE_PATH}/shipments/#{shipment_id}", body: payload)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def delete_shipment(shipment_id)
|
|
72
|
+
request_json(:delete, "#{BASE_PATH}/shipments/#{shipment_id}")
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def cheapest_shipment_rate(payload, params: {})
|
|
76
|
+
request_json(:post, "#{BASE_PATH}/shipments/cheapest", params: params, body: payload)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def create_shipment_rate(payload)
|
|
80
|
+
request_json(:post, "#{BASE_PATH}/shipment-rates", body: payload)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def upload_shipment_file(uuid, type, file)
|
|
84
|
+
file_part = file_part_for(file)
|
|
85
|
+
request_multipart(:post, "#{BASE_PATH}/shipments/#{uuid}/file/upload/#{type}", body: { file: file_part })
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def delete_shipment_file(uuid, type)
|
|
89
|
+
request_json(:delete, "#{BASE_PATH}/shipments/#{uuid}/file/upload/#{type}")
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def each_page(path, params: {}, items_per_page: 50)
|
|
93
|
+
return enum_for(:each_page, path, params: params, items_per_page: items_per_page) unless block_given?
|
|
94
|
+
|
|
95
|
+
page = 1
|
|
96
|
+
loop do
|
|
97
|
+
response = request_json(:get, path, params: params.merge(page: page, itemsPerPage: items_per_page))
|
|
98
|
+
yield response
|
|
99
|
+
break unless response.is_a?(Array)
|
|
100
|
+
break if response.length < items_per_page
|
|
101
|
+
|
|
102
|
+
page += 1
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
private
|
|
107
|
+
|
|
108
|
+
def request_json(method, path, params: nil, body: nil)
|
|
109
|
+
response = connection.public_send(method) do |req|
|
|
110
|
+
apply_headers(req)
|
|
111
|
+
req.url(path)
|
|
112
|
+
req.params.update(params) if params
|
|
113
|
+
req.body = body if body
|
|
114
|
+
end
|
|
115
|
+
handle_response(response)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def request_multipart(method, path, body:)
|
|
119
|
+
response = connection(multipart: true).public_send(method) do |req|
|
|
120
|
+
apply_headers(req)
|
|
121
|
+
req.url(path)
|
|
122
|
+
req.body = body
|
|
123
|
+
end
|
|
124
|
+
handle_response(response)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def apply_headers(request)
|
|
128
|
+
request.headers["X-AUTH-TOKEN"] = @configuration.api_key if @configuration.api_key
|
|
129
|
+
request.headers["Accept"] = "application/json"
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def connection(multipart: false)
|
|
133
|
+
builder = Faraday.new(url: @configuration.base_url) do |f|
|
|
134
|
+
f.request :multipart if multipart
|
|
135
|
+
f.request :json
|
|
136
|
+
f.response :json, content_type: /\bjson$/
|
|
137
|
+
f.adapter Faraday.default_adapter
|
|
138
|
+
end
|
|
139
|
+
builder.options.timeout = @configuration.timeout
|
|
140
|
+
builder.options.open_timeout = @configuration.open_timeout
|
|
141
|
+
builder
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def file_part_for(file)
|
|
145
|
+
return file if file.is_a?(Faraday::Multipart::FilePart)
|
|
146
|
+
return Faraday::Multipart::FilePart.new(file, "application/octet-stream") if file.is_a?(String)
|
|
147
|
+
|
|
148
|
+
raise ArgumentError, "file must be a path or Faraday::Multipart::FilePart"
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def handle_response(response)
|
|
152
|
+
status = response.status
|
|
153
|
+
body = response.body
|
|
154
|
+
headers = response.headers
|
|
155
|
+
|
|
156
|
+
return Models.parse(body) if status.between?(200, 299)
|
|
157
|
+
|
|
158
|
+
error_class = case status
|
|
159
|
+
when 400 then Errors::BadRequest
|
|
160
|
+
when 401 then Errors::Unauthorized
|
|
161
|
+
when 403 then Errors::Forbidden
|
|
162
|
+
when 404 then Errors::NotFound
|
|
163
|
+
when 409 then Errors::Conflict
|
|
164
|
+
when 422 then Errors::UnprocessableEntity
|
|
165
|
+
when 429 then Errors::RateLimited
|
|
166
|
+
when 500..599 then Errors::ServerError
|
|
167
|
+
else Error
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
message = body.is_a?(Hash) ? body["message"] || body["error"] : body.to_s
|
|
171
|
+
raise error_class.new(message, status: status, body: body, headers: headers)
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Jumingo
|
|
4
|
+
class Configuration
|
|
5
|
+
DEFAULT_BASE_URL = "https://api.jumingo.com"
|
|
6
|
+
DEFAULT_TIMEOUT = 30
|
|
7
|
+
DEFAULT_OPEN_TIMEOUT = 10
|
|
8
|
+
DEFAULT_RETRIES = 0
|
|
9
|
+
|
|
10
|
+
attr_accessor :base_url, :api_key, :timeout, :open_timeout, :retries, :logger
|
|
11
|
+
|
|
12
|
+
def initialize
|
|
13
|
+
@base_url = DEFAULT_BASE_URL
|
|
14
|
+
@api_key = nil
|
|
15
|
+
@timeout = DEFAULT_TIMEOUT
|
|
16
|
+
@open_timeout = DEFAULT_OPEN_TIMEOUT
|
|
17
|
+
@retries = DEFAULT_RETRIES
|
|
18
|
+
@logger = nil
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Jumingo
|
|
4
|
+
class Error < StandardError
|
|
5
|
+
attr_reader :status, :body, :headers
|
|
6
|
+
|
|
7
|
+
def initialize(message = nil, status: nil, body: nil, headers: nil)
|
|
8
|
+
super(message)
|
|
9
|
+
@status = status
|
|
10
|
+
@body = body
|
|
11
|
+
@headers = headers
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
module Errors
|
|
16
|
+
class BadRequest < Error; end
|
|
17
|
+
class Unauthorized < Error; end
|
|
18
|
+
class Forbidden < Error; end
|
|
19
|
+
class NotFound < Error; end
|
|
20
|
+
class Conflict < Error; end
|
|
21
|
+
class UnprocessableEntity < Error; end
|
|
22
|
+
class RateLimited < Error; end
|
|
23
|
+
class ServerError < Error; end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Jumingo
|
|
4
|
+
module Models
|
|
5
|
+
class Object
|
|
6
|
+
def initialize(attributes = {})
|
|
7
|
+
@attributes = attributes.transform_keys { |key| key.to_s }
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def [](key)
|
|
11
|
+
@attributes[key.to_s]
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def to_h
|
|
15
|
+
@attributes.dup
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def respond_to_missing?(name, include_private = false)
|
|
19
|
+
@attributes.key?(name.to_s) || super
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def method_missing(name, *args, &block)
|
|
23
|
+
return @attributes[name.to_s] if @attributes.key?(name.to_s)
|
|
24
|
+
|
|
25
|
+
super
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def self.parse(value)
|
|
30
|
+
case value
|
|
31
|
+
when Array
|
|
32
|
+
value.map { |item| parse(item) }
|
|
33
|
+
when Hash
|
|
34
|
+
Object.new(value.transform_values { |v| parse(v) })
|
|
35
|
+
else
|
|
36
|
+
value
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
data/lib/jumingo.rb
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "jumingo/version"
|
|
4
|
+
require_relative "jumingo/configuration"
|
|
5
|
+
require_relative "jumingo/errors"
|
|
6
|
+
require_relative "jumingo/models"
|
|
7
|
+
require_relative "jumingo/client"
|
|
8
|
+
|
|
9
|
+
module Jumingo
|
|
10
|
+
def self.configure
|
|
11
|
+
yield(configuration)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def self.configuration
|
|
15
|
+
@configuration ||= Configuration.new
|
|
16
|
+
end
|
|
17
|
+
end
|