shipengine_sdk 1.0.3
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/CHANGELOG.md +8 -0
- data/README.md +96 -0
- data/lib/faraday/raise_http_exception.rb +77 -0
- data/lib/shipengine/configuration.rb +43 -0
- data/lib/shipengine/constants/base.rb +22 -0
- data/lib/shipengine/constants/countries.rb +16 -0
- data/lib/shipengine/constants.rb +4 -0
- data/lib/shipengine/domain/addresses/address_validation.rb +118 -0
- data/lib/shipengine/domain/addresses.rb +76 -0
- data/lib/shipengine/domain/carriers/list_carriers.rb +140 -0
- data/lib/shipengine/domain/carriers.rb +93 -0
- data/lib/shipengine/domain/labels/create_from_rate.rb +163 -0
- data/lib/shipengine/domain/labels/create_from_shipment_details.rb +163 -0
- data/lib/shipengine/domain/labels/void_label.rb +18 -0
- data/lib/shipengine/domain/labels.rb +297 -0
- data/lib/shipengine/domain/rates/get_with_shipment_details.rb +347 -0
- data/lib/shipengine/domain/rates.rb +379 -0
- data/lib/shipengine/domain/tracking/track_using_carrier_code_and_tracking_number.rb +45 -0
- data/lib/shipengine/domain/tracking/track_using_label_id.rb +45 -0
- data/lib/shipengine/domain/tracking.rb +103 -0
- data/lib/shipengine/domain.rb +7 -0
- data/lib/shipengine/exceptions/error_code.rb +254 -0
- data/lib/shipengine/exceptions/error_type.rb +49 -0
- data/lib/shipengine/exceptions.rb +132 -0
- data/lib/shipengine/internal_client.rb +91 -0
- data/lib/shipengine/utils/base58.rb +109 -0
- data/lib/shipengine/utils/pretty_print.rb +29 -0
- data/lib/shipengine/utils/request_id.rb +16 -0
- data/lib/shipengine/utils/user_agent.rb +24 -0
- data/lib/shipengine/utils/validate.rb +106 -0
- data/lib/shipengine/version.rb +5 -0
- data/lib/shipengine.rb +164 -0
- metadata +117 -0
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ShipEngine
|
4
|
+
module Utils
|
5
|
+
#
|
6
|
+
# Class responsible for managing the user agent.
|
7
|
+
#
|
8
|
+
class UserAgent
|
9
|
+
attr_reader :version, :platform
|
10
|
+
|
11
|
+
def initialize(version = VERSION, platform = RUBY_PLATFORM)
|
12
|
+
raise ::StandardError, 'Cannot get version' unless version
|
13
|
+
raise ::StandardError, 'Cannot get platform' unless platform
|
14
|
+
|
15
|
+
@version = version
|
16
|
+
@platform = platform
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_s
|
20
|
+
"shipengine-ruby/#{@version} (#{@platform})"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'shipengine/exceptions'
|
4
|
+
|
5
|
+
module ShipEngine
|
6
|
+
module Utils
|
7
|
+
module Validate
|
8
|
+
class << self
|
9
|
+
def not_nil(field, value)
|
10
|
+
return unless value.nil?
|
11
|
+
|
12
|
+
raise Exceptions.create_required_error(field)
|
13
|
+
end
|
14
|
+
|
15
|
+
def not_nil_or_empty_str(field, value)
|
16
|
+
not_nil(field, value)
|
17
|
+
return unless value == ''
|
18
|
+
|
19
|
+
raise Exceptions.create_required_error(field)
|
20
|
+
end
|
21
|
+
|
22
|
+
def str(field, value)
|
23
|
+
not_nil(field, value)
|
24
|
+
return if value.is_a?(String)
|
25
|
+
|
26
|
+
raise Exceptions.create_invalid_field_value_error("#{field} must be a String.")
|
27
|
+
end
|
28
|
+
|
29
|
+
def non_empty_str(field, value)
|
30
|
+
str(field, value)
|
31
|
+
return unless value.empty?
|
32
|
+
|
33
|
+
raise Exceptions.create_invalid_field_value_error("#{field} cannot be empty.")
|
34
|
+
end
|
35
|
+
|
36
|
+
def non_whitespace_str(field, value)
|
37
|
+
str(field, value)
|
38
|
+
return unless value.strip.empty?
|
39
|
+
|
40
|
+
raise Exceptions.create_invalid_field_value_error("#{field} cannot be all whitespace.")
|
41
|
+
end
|
42
|
+
|
43
|
+
def hash(field, value)
|
44
|
+
not_nil(field, value)
|
45
|
+
return if value.is_a?(Hash)
|
46
|
+
|
47
|
+
raise Exceptions.create_invalid_field_value_error("#{field} must be Hash.")
|
48
|
+
end
|
49
|
+
|
50
|
+
def bool(field, value)
|
51
|
+
not_nil(field, value)
|
52
|
+
return if [true, false].include?(value)
|
53
|
+
|
54
|
+
raise Exceptions.create_invalid_field_value_error("#{field} must be a Boolean.")
|
55
|
+
end
|
56
|
+
|
57
|
+
def number(field, value)
|
58
|
+
not_nil(field, value)
|
59
|
+
return if value.is_a?(Numeric)
|
60
|
+
|
61
|
+
raise Exceptions.create_invalid_field_value_error("#{field} must be Numeric.")
|
62
|
+
end
|
63
|
+
|
64
|
+
def int(field, value)
|
65
|
+
number(field, value)
|
66
|
+
return if value.to_i == value
|
67
|
+
|
68
|
+
raise Exceptions.create_invalid_field_value_error("#{field} must be a whole number.")
|
69
|
+
end
|
70
|
+
|
71
|
+
def non_neg_int(field, value)
|
72
|
+
int(field, value)
|
73
|
+
return if value >= 0
|
74
|
+
|
75
|
+
raise Exceptions.create_invalid_field_value_error("#{field} must be zero or greater.")
|
76
|
+
end
|
77
|
+
|
78
|
+
def positive_int(field, value)
|
79
|
+
int(field, value)
|
80
|
+
return if value.positive?
|
81
|
+
|
82
|
+
raise Exceptions.create_invalid_field_value_error("#{field} must be greater than zero.")
|
83
|
+
end
|
84
|
+
|
85
|
+
def array(field, value)
|
86
|
+
not_nil(field, value)
|
87
|
+
|
88
|
+
return if value.is_a?(Array)
|
89
|
+
|
90
|
+
raise Exceptions.create_invalid_field_value_error("#{field} must be an Array.")
|
91
|
+
end
|
92
|
+
|
93
|
+
def array_of_str(field, value)
|
94
|
+
array(field, value)
|
95
|
+
value.each do |v|
|
96
|
+
next if v.is_a?(String)
|
97
|
+
|
98
|
+
raise Exceptions.create_invalid_field_value_error("#{field} must be an Array of Strings.")
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def validate_input_address(address); end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
data/lib/shipengine.rb
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# for client class
|
4
|
+
require 'shipengine/internal_client'
|
5
|
+
require 'shipengine/domain'
|
6
|
+
require 'shipengine/configuration'
|
7
|
+
|
8
|
+
# just for exporting
|
9
|
+
require 'shipengine/utils/validate'
|
10
|
+
require 'shipengine/version'
|
11
|
+
require 'shipengine/constants'
|
12
|
+
require 'observer'
|
13
|
+
|
14
|
+
module ShipEngine
|
15
|
+
class Client
|
16
|
+
attr_accessor :configuration
|
17
|
+
|
18
|
+
def initialize(api_key, retries: nil, timeout: nil, page_size: nil, base_url: nil)
|
19
|
+
@configuration = Configuration.new(
|
20
|
+
api_key:,
|
21
|
+
retries:,
|
22
|
+
base_url:,
|
23
|
+
timeout:,
|
24
|
+
page_size:
|
25
|
+
)
|
26
|
+
|
27
|
+
@internal_client = ShipEngine::InternalClient.new(@configuration)
|
28
|
+
@addresses = Domain::Addresses.new(@internal_client)
|
29
|
+
@carriers = Domain::Carriers.new(@internal_client)
|
30
|
+
@labels = Domain::Labels.new(@internal_client)
|
31
|
+
@rates = Domain::Rates.new(@internal_client)
|
32
|
+
@tracking = Domain::Tracking.new(@internal_client)
|
33
|
+
end
|
34
|
+
|
35
|
+
#
|
36
|
+
# Validate an array of address
|
37
|
+
#
|
38
|
+
# @param addresses [Array<ShipEngine::Domain::Addresses::AddressValidation::Request>]
|
39
|
+
# @param config [Hash?]
|
40
|
+
# @option config [String?] :api_key
|
41
|
+
# @option config [String?] :base_url
|
42
|
+
# @option config [Number?] :retries
|
43
|
+
# @option config [Number?] :timeout
|
44
|
+
#
|
45
|
+
#
|
46
|
+
# @return [Array<ShipEngine::Domain::Addresses::AddressValidation::Response>]
|
47
|
+
#
|
48
|
+
# @see https://shipengine.github.io/shipengine-openapi/#operation/validate_address
|
49
|
+
def validate_addresses(address, config = {})
|
50
|
+
@addresses.validate(address, config)
|
51
|
+
end
|
52
|
+
|
53
|
+
#
|
54
|
+
# List all of the users Carriers
|
55
|
+
#
|
56
|
+
# @param config [Hash?]
|
57
|
+
# @option config [String?] :api_key
|
58
|
+
# @option config [String?] :base_url
|
59
|
+
# @option config [Number?] :retries
|
60
|
+
# @option config [Number?] :timeout
|
61
|
+
#
|
62
|
+
#
|
63
|
+
# @return [ShipEngine::Domain::Carriers::ListCarriers::Response]
|
64
|
+
#
|
65
|
+
# @see https://shipengine.github.io/shipengine-openapi/#operation/list_carriers
|
66
|
+
def list_carriers(config: {})
|
67
|
+
@carriers.list_carriers(config:)
|
68
|
+
end
|
69
|
+
|
70
|
+
# Create label from Rate Id
|
71
|
+
#
|
72
|
+
# @param rate_id [String]
|
73
|
+
# @param params [Hash]
|
74
|
+
# @param config [Hash]
|
75
|
+
# @option config [String?] :api_key
|
76
|
+
# @option config [String?] :base_url
|
77
|
+
# @option config [Number?] :retries
|
78
|
+
# @option config [Number?] :timeout
|
79
|
+
#
|
80
|
+
# @return [ShipEngine::Domain::Labels::CreateFromRate::Response]
|
81
|
+
#
|
82
|
+
# @see https://shipengine.github.io/shipengine-openapi/#operation/create_label_from_rate
|
83
|
+
def create_label_from_rate(rate_id, params, config = {})
|
84
|
+
@labels.create_from_rate(rate_id, params, config)
|
85
|
+
end
|
86
|
+
|
87
|
+
# Create label from Shipment Details
|
88
|
+
#
|
89
|
+
# @param params [Hash]
|
90
|
+
# @param config [Hash]
|
91
|
+
# @option config [String?] :api_key
|
92
|
+
# @option config [String?] :base_url
|
93
|
+
# @option config [Number?] :retries
|
94
|
+
# @option config [Number?] :timeout
|
95
|
+
#
|
96
|
+
# @return [ShipEngine::Domain::Labels::CreateFromShipmentDetails::Response]
|
97
|
+
#
|
98
|
+
# @see https://shipengine.github.io/shipengine-openapi/#operation/create_label
|
99
|
+
def create_label_from_shipment_details(params, config = {})
|
100
|
+
@labels.create_from_shipment_details(params, config)
|
101
|
+
end
|
102
|
+
|
103
|
+
# Void label with Label Id
|
104
|
+
#
|
105
|
+
# @param label_id [String]
|
106
|
+
# @param config [Hash]
|
107
|
+
# @option config [String?] :api_key
|
108
|
+
# @option config [String?] :base_url
|
109
|
+
# @option config [Number?] :retries
|
110
|
+
# @option config [Number?] :timeout
|
111
|
+
#
|
112
|
+
# @return [ShipEngine::Domain::Labels::CreateFromShipmentDetails::Response]
|
113
|
+
#
|
114
|
+
# @see https://shipengine.github.io/shipengine-openapi/#operation/create_label
|
115
|
+
def void_label_with_label_id(label_id, config = {})
|
116
|
+
@labels.void(label_id, config)
|
117
|
+
end
|
118
|
+
|
119
|
+
# Get Rates with Shipment Details
|
120
|
+
#
|
121
|
+
# @param Shipment Details [Hash]
|
122
|
+
# @param config [Hash]
|
123
|
+
# @option config [String?] :api_key
|
124
|
+
# @option config [String?] :base_url
|
125
|
+
# @option config [Number?] :retries
|
126
|
+
# @option config [Number?] :timeout
|
127
|
+
#
|
128
|
+
# @return [ShipEngine::Domain::Tracking::TrackUsingLabelId::Response]
|
129
|
+
#
|
130
|
+
def get_rates_with_shipment_details(shipment_details, config = {})
|
131
|
+
@rates.get_rates_with_shipment_details(shipment_details, config)
|
132
|
+
end
|
133
|
+
|
134
|
+
# Track Package by package id (recommended)
|
135
|
+
#
|
136
|
+
# @param label_id [String] <description>
|
137
|
+
# @param config [Hash]
|
138
|
+
# @option config [String?] :api_key
|
139
|
+
# @option config [String?] :base_url
|
140
|
+
# @option config [Number?] :retries
|
141
|
+
# @option config [Number?] :timeout
|
142
|
+
#
|
143
|
+
# @return [ShipEngine::Domain::Tracking::TrackUsingLabelId::Response]
|
144
|
+
#
|
145
|
+
def track_using_label_id(label_id, config = {})
|
146
|
+
@tracking.track_using_label_id(label_id, config)
|
147
|
+
end
|
148
|
+
|
149
|
+
#
|
150
|
+
# Track Package by tracking number. Tracking by package_id is preferred [@see #track_package_by_id]
|
151
|
+
# @param tracking_number [String] <description>
|
152
|
+
# @param config [Hash]
|
153
|
+
# @option config [String?] :api_key
|
154
|
+
# @option config [String?] :base_url
|
155
|
+
# @option config [Number?] :retries
|
156
|
+
# @option config [Number?] :timeout
|
157
|
+
#
|
158
|
+
# @return [ShipEngine::Domain::Tracking::TrackUsingCarrierCodeAndTrackingNumber::Response]
|
159
|
+
#
|
160
|
+
def track_using_carrier_code_and_tracking_number(carrier_code, tracking_number, config = {})
|
161
|
+
@tracking.track_using_carrier_code_and_tracking_number(carrier_code, tracking_number, config)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: shipengine_sdk
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ShipEngine Development Team
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-06-16 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: '1.4'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.4'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday_middleware
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: hashie
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.4'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.4'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
executables: []
|
58
|
+
extensions: []
|
59
|
+
extra_rdoc_files: []
|
60
|
+
files:
|
61
|
+
- CHANGELOG.md
|
62
|
+
- README.md
|
63
|
+
- lib/faraday/raise_http_exception.rb
|
64
|
+
- lib/shipengine.rb
|
65
|
+
- lib/shipengine/configuration.rb
|
66
|
+
- lib/shipengine/constants.rb
|
67
|
+
- lib/shipengine/constants/base.rb
|
68
|
+
- lib/shipengine/constants/countries.rb
|
69
|
+
- lib/shipengine/domain.rb
|
70
|
+
- lib/shipengine/domain/addresses.rb
|
71
|
+
- lib/shipengine/domain/addresses/address_validation.rb
|
72
|
+
- lib/shipengine/domain/carriers.rb
|
73
|
+
- lib/shipengine/domain/carriers/list_carriers.rb
|
74
|
+
- lib/shipengine/domain/labels.rb
|
75
|
+
- lib/shipengine/domain/labels/create_from_rate.rb
|
76
|
+
- lib/shipengine/domain/labels/create_from_shipment_details.rb
|
77
|
+
- lib/shipengine/domain/labels/void_label.rb
|
78
|
+
- lib/shipengine/domain/rates.rb
|
79
|
+
- lib/shipengine/domain/rates/get_with_shipment_details.rb
|
80
|
+
- lib/shipengine/domain/tracking.rb
|
81
|
+
- lib/shipengine/domain/tracking/track_using_carrier_code_and_tracking_number.rb
|
82
|
+
- lib/shipengine/domain/tracking/track_using_label_id.rb
|
83
|
+
- lib/shipengine/exceptions.rb
|
84
|
+
- lib/shipengine/exceptions/error_code.rb
|
85
|
+
- lib/shipengine/exceptions/error_type.rb
|
86
|
+
- lib/shipengine/internal_client.rb
|
87
|
+
- lib/shipengine/utils/base58.rb
|
88
|
+
- lib/shipengine/utils/pretty_print.rb
|
89
|
+
- lib/shipengine/utils/request_id.rb
|
90
|
+
- lib/shipengine/utils/user_agent.rb
|
91
|
+
- lib/shipengine/utils/validate.rb
|
92
|
+
- lib/shipengine/version.rb
|
93
|
+
homepage: https://github.com/ShipEngine/shipengine-ruby
|
94
|
+
licenses:
|
95
|
+
- Apache-2.0
|
96
|
+
metadata:
|
97
|
+
rubygems_mfa_required: 'true'
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: 3.2.2
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
requirements: []
|
113
|
+
rubygems_version: 3.4.10
|
114
|
+
signing_key:
|
115
|
+
specification_version: 4
|
116
|
+
summary: The Official Ruby SDK for ShipEngine.
|
117
|
+
test_files: []
|