torque_api 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a216d635ef659ea2f23c07ba8ce670693edc8a6b8358048eb921b2c6a1739af0
4
+ data.tar.gz: c80a94e86e03fe9cc7829ba2e077c177d61de5c42bebf5f2899af13f27f49520
5
+ SHA512:
6
+ metadata.gz: 00b9dafb12806bf974976e9194269d003c426a91292d0c41923fcaea6ff92545726ecf9c6ebc4650fe5f7dda91bb883d27ca26aa0e12cb1723548abc3e37ec8a
7
+ data.tar.gz: 6637619950bcecee7e8164d3351bff9b3eddc24505a3569fdbd403a4b2cb82d36a9e0c69bb053667c73ed559b65c1174dade3117dc8bec7a8bac79db6fccb7c1
data/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # Changelog
2
+
3
+ ## [0.1.0] - 2025-03-04
4
+
5
+ ### Added
6
+ - Initial release
7
+ - `TorqueAPI::Client` with Faraday, Basic auth, sandbox toggle, and client-specific headers
8
+ - `TorqueAPI::PreAdviceResource` — POST `/preAdvice` (passthrough payload)
9
+ - `TorqueAPI::ReturnRmaResource` — GET `/returnRma` with typed response objects
10
+ - `TorqueAPI::Object` — OpenStruct-based response wrapper with auto snake_case keys and `original_response`
11
+ - Comprehensive error hierarchy: `APIError`, `AuthenticationError`, `ValidationError`, `NotFoundError`, `RateLimitError`, `ServerError`
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 PostCo
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,112 @@
1
+ # TorqueAPI
2
+
3
+ Ruby client for the [Torque WMS](https://torque.eu/) (Warehouse Management System) API.
4
+
5
+ ## Installation
6
+
7
+ Add to your Gemfile:
8
+
9
+ ```ruby
10
+ gem "torque_api", git: "https://github.com/PostCo/torque_api", branch: "main"
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ### Initialize a client
16
+
17
+ ```ruby
18
+ client = TorqueAPI::Client.new(
19
+ api_key: "your_api_key",
20
+ client_defaults: {
21
+ "CLIENT_ID" => "AM",
22
+ "CLIENT_GROUP" => "AMVIS",
23
+ "SITE_ID" => "WO6",
24
+ "CONFIG_ID" => "P1",
25
+ "OWNER_ID" => "TORQUE",
26
+ "PALLET_CONFIG" => "MD"
27
+ },
28
+ sandbox: true # Use test environment
29
+ )
30
+ ```
31
+
32
+ ### Create a Pre Advice
33
+
34
+ ```ruby
35
+ payload = [
36
+ {
37
+ "Record_Type" => "PAH",
38
+ "Pre_Advice_Id" => "12345",
39
+ "Status" => "Released",
40
+ "PreAdviceLines" => [
41
+ {
42
+ "Record_Type" => "PAL",
43
+ "Pre_Advice_Id" => "12345",
44
+ "Sku_Id" => "SKU-001",
45
+ "Qty_Due" => 1,
46
+ "Line_Id" => 1
47
+ }
48
+ ]
49
+ }
50
+ ]
51
+
52
+ response = client.pre_advice.create(payload)
53
+ ```
54
+
55
+ ### Poll Return RMA items
56
+
57
+ ```ruby
58
+ items = client.return_rma.list
59
+ # Returns an array of TorqueAPI::Objects::ReturnRma
60
+
61
+ items.each do |item|
62
+ puts item.orderid # snake_case accessors
63
+ puts item.sku_id
64
+ puts item.sampling_type
65
+ puts item.raw # Access original (frozen) response data
66
+ end
67
+ ```
68
+
69
+ ### Error handling
70
+
71
+ ```ruby
72
+ begin
73
+ client.pre_advice.create(payload)
74
+ rescue TorqueAPI::AuthenticationError => e
75
+ # 401/403 responses
76
+ puts e.message
77
+ puts e.status_code
78
+ puts e.response # Full Faraday response
79
+ rescue TorqueAPI::ValidationError => e
80
+ # 400 responses
81
+ rescue TorqueAPI::NotFoundError => e
82
+ # 404 responses
83
+ rescue TorqueAPI::ServerError => e
84
+ # 500-599 responses
85
+ rescue TorqueAPI::APIError => e
86
+ # All other error responses
87
+ end
88
+ ```
89
+
90
+ ### Sandbox mode
91
+
92
+ Toggle between test and live Torque environments:
93
+
94
+ ```ruby
95
+ # Test: https://wms-api.torque.eu/torqueapitest/api/v1
96
+ client = TorqueAPI::Client.new(api_key: key, sandbox: true)
97
+
98
+ # Live: https://wms-api.torque.eu/torqueapi/api/v1
99
+ client = TorqueAPI::Client.new(api_key: key, sandbox: false)
100
+ ```
101
+
102
+ ## Development
103
+
104
+ ```bash
105
+ bundle install
106
+ bundle exec rspec # Run tests
107
+ bundle exec standardrb # Run linter
108
+ ```
109
+
110
+ ## License
111
+
112
+ MIT License. See [LICENSE.txt](LICENSE.txt).
@@ -0,0 +1,43 @@
1
+ require "faraday"
2
+
3
+ module TorqueAPI
4
+ class Client
5
+ LIVE_BASE_URL = "https://wms-api.torque.eu/torqueapi/api/v1/"
6
+ TEST_BASE_URL = "https://wms-api.torque.eu/torqueapitest/api/v1/"
7
+
8
+ attr_reader :api_key, :client_defaults, :adapter
9
+
10
+ def initialize(api_key:, client_defaults: {}, sandbox: false, adapter: Faraday.default_adapter)
11
+ @api_key = api_key
12
+ @client_defaults = client_defaults
13
+ @sandbox = sandbox
14
+ @adapter = adapter
15
+ end
16
+
17
+ def pre_advice
18
+ @pre_advice ||= PreAdviceResource.new(self)
19
+ end
20
+
21
+ def return_rma
22
+ @return_rma ||= ReturnRmaResource.new(self)
23
+ end
24
+
25
+ def connection
26
+ @connection ||= Faraday.new do |conn|
27
+ conn.url_prefix = sandbox? ? TEST_BASE_URL : LIVE_BASE_URL
28
+ conn.headers["Authorization"] = "Basic #{api_key}"
29
+ conn.headers["Accept"] = "application/json"
30
+ client_defaults.each { |key, value| conn.headers[key.to_s] = value.to_s }
31
+ conn.request :json
32
+ conn.response :json, content_type: "application/json"
33
+ conn.adapter adapter
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+ def sandbox?
40
+ @sandbox
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,18 @@
1
+ module TorqueAPI
2
+ class Error < StandardError
3
+ attr_reader :response, :status_code
4
+
5
+ def initialize(message = nil, response: nil, status_code: nil)
6
+ super(message)
7
+ @response = response
8
+ @status_code = status_code
9
+ end
10
+ end
11
+
12
+ class APIError < Error; end
13
+ class AuthenticationError < Error; end
14
+ class ValidationError < Error; end
15
+ class NotFoundError < Error; end
16
+ class RateLimitError < Error; end
17
+ class ServerError < Error; end
18
+ end
@@ -0,0 +1,60 @@
1
+ require "ostruct"
2
+ require "active_support/core_ext/string/inflections"
3
+
4
+ module TorqueAPI
5
+ class Base < OpenStruct
6
+ attr_reader :original_response
7
+
8
+ def initialize(attributes)
9
+ @original_response = deep_freeze(attributes)
10
+ super(to_ostruct(attributes))
11
+ end
12
+
13
+ def to_hash
14
+ ostruct_to_hash(self)
15
+ end
16
+
17
+ def raw
18
+ @original_response
19
+ end
20
+
21
+ private
22
+
23
+ def to_ostruct(obj)
24
+ case obj
25
+ when Hash
26
+ OpenStruct.new(
27
+ obj.transform_keys { |key| key.to_s.underscore }
28
+ .transform_values { |val| to_ostruct(val) }
29
+ )
30
+ when Array
31
+ obj.map { |o| to_ostruct(o) }
32
+ else
33
+ obj
34
+ end
35
+ end
36
+
37
+ def deep_freeze(obj)
38
+ case obj
39
+ when Hash then obj.transform_values { |v| deep_freeze(v) }.freeze
40
+ when Array then obj.map { |i| deep_freeze(i) }.freeze
41
+ else obj.respond_to?(:freeze) ? obj.freeze : obj
42
+ end
43
+ end
44
+
45
+ def ostruct_to_hash(object)
46
+ case object
47
+ when OpenStruct
48
+ object.each_pair.to_h
49
+ .transform_keys(&:to_s)
50
+ .transform_values { |v| ostruct_to_hash(v) }
51
+ when Array then object.map { |i| ostruct_to_hash(i) }
52
+ when Hash
53
+ object.transform_keys(&:to_s)
54
+ .transform_values { |v| ostruct_to_hash(v) }
55
+ else
56
+ object
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,5 @@
1
+ module TorqueAPI
2
+ module Objects
3
+ class ReturnRma < Base; end
4
+ end
5
+ end
@@ -0,0 +1,50 @@
1
+ module TorqueAPI
2
+ class Resource
3
+ attr_reader :client
4
+
5
+ def initialize(client)
6
+ @client = client
7
+ end
8
+
9
+ private
10
+
11
+ def get_request(url, params: {}, headers: {})
12
+ handle_response client.connection.get(url, params, headers)
13
+ rescue Faraday::Error => e
14
+ raise APIError, "Network error: #{e.message}"
15
+ end
16
+
17
+ def post_request(url, body:, headers: {})
18
+ handle_response client.connection.post(url, body, headers)
19
+ rescue Faraday::Error => e
20
+ raise APIError, "Network error: #{e.message}"
21
+ end
22
+
23
+ def handle_response(response)
24
+ return response.body if response.status.between?(200, 299)
25
+
26
+ error_class, prefix = error_mapping(response.status)
27
+ message = "#{prefix} (HTTP #{response.status}): #{extract_error_message(response.body)}"
28
+ raise error_class.new(message, response: response, status_code: response.status)
29
+ end
30
+
31
+ def error_mapping(status)
32
+ case status
33
+ when 400 then [ValidationError, "Bad request"]
34
+ when 401, 403 then [AuthenticationError, "Authentication failed"]
35
+ when 404 then [NotFoundError, "Resource not found"]
36
+ when 429 then [RateLimitError, "Rate limited"]
37
+ when 500..599 then [ServerError, "Server error"]
38
+ else [APIError, "API error"]
39
+ end
40
+ end
41
+
42
+ def extract_error_message(body)
43
+ case body
44
+ when Hash then body["message"] || body["error"] || body.to_s
45
+ when String then body
46
+ else body.to_s
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,7 @@
1
+ module TorqueAPI
2
+ class PreAdviceResource < Resource
3
+ def create(payload)
4
+ post_request("preAdvice", body: payload)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ module TorqueAPI
2
+ class ReturnRmaResource < Resource
3
+ def list
4
+ data = get_request("returnRma")
5
+ Array(data).map { |item| Objects::ReturnRma.new(item) }
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module TorqueAPI
2
+ VERSION = "0.1.0"
3
+ end
data/lib/torque_api.rb ADDED
@@ -0,0 +1,20 @@
1
+ require_relative "torque_api/version"
2
+
3
+ module TorqueAPI
4
+ autoload :Client, "torque_api/client"
5
+ autoload :Base, "torque_api/object"
6
+ autoload :Resource, "torque_api/resource"
7
+ autoload :Error, "torque_api/errors"
8
+ autoload :APIError, "torque_api/errors"
9
+ autoload :AuthenticationError, "torque_api/errors"
10
+ autoload :ValidationError, "torque_api/errors"
11
+ autoload :NotFoundError, "torque_api/errors"
12
+ autoload :RateLimitError, "torque_api/errors"
13
+ autoload :ServerError, "torque_api/errors"
14
+ autoload :PreAdviceResource, "torque_api/resources/pre_advice_resource"
15
+ autoload :ReturnRmaResource, "torque_api/resources/return_rma_resource"
16
+
17
+ module Objects
18
+ autoload :ReturnRma, "torque_api/objects/return_rma"
19
+ end
20
+ end
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: torque_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - PostCo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2026-03-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday-net_http
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '7.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '7.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: standard
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: A Ruby wrapper for the Torque Warehouse Management System API, supporting
98
+ Pre Advice creation and Return RMA polling.
99
+ email:
100
+ - dev@postco.co
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - CHANGELOG.md
106
+ - LICENSE.txt
107
+ - README.md
108
+ - lib/torque_api.rb
109
+ - lib/torque_api/client.rb
110
+ - lib/torque_api/errors.rb
111
+ - lib/torque_api/object.rb
112
+ - lib/torque_api/objects/return_rma.rb
113
+ - lib/torque_api/resource.rb
114
+ - lib/torque_api/resources/pre_advice_resource.rb
115
+ - lib/torque_api/resources/return_rma_resource.rb
116
+ - lib/torque_api/version.rb
117
+ homepage: https://github.com/PostCo/torque_api
118
+ licenses:
119
+ - MIT
120
+ metadata:
121
+ homepage_uri: https://github.com/PostCo/torque_api
122
+ source_code_uri: https://github.com/PostCo/torque_api
123
+ changelog_uri: https://github.com/PostCo/torque_api/blob/main/CHANGELOG.md
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: 3.0.0
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubygems_version: 3.5.22
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: Ruby client for the Torque WMS API
143
+ test_files: []