seko_ecom_api 0.1.1 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cd52f793929f84a440a74e2170e943719a1db83c26340c440ba85db6e89b0dd0
4
- data.tar.gz: 9c86a38d6183547d6f06a3a680685f85e5981b9520fefd4ca152cbaccfe77330
3
+ metadata.gz: e954285218ea275abf3769be91fbee63820e52b26a2d81b41bea12a8dd2c029f
4
+ data.tar.gz: a1ba313382593828b9f93b72d72892f7eced6ac658cedff0ae5a4828c29368d5
5
5
  SHA512:
6
- metadata.gz: 18d06b8c534513c5ac781a50c3691bbe941f1d189c5e1c1470d5e0115b3abd70879795da67efe65f1f672730ab6977c03f6e015b88a107c8ac2de53cdd89bd8c
7
- data.tar.gz: 98b548e8646b07a9e916468287046aeb7f833aea20192e1cb5c58789251353ecb9cde3ddeba0586aad99d98cea71279a9f55735a680fcfbd84a52e5f04cfb794
6
+ metadata.gz: c446549dcd16705c5da5ec518224785665461ff8a3178fed02938966024e0deadaaeb07f7f60e969f5a323eaabb5e519eb38d09cae155a5a958266b0121149d1
7
+ data.tar.gz: 3af01c7e4a794ab7749d3d2787833f5c408332139587cb53bf80e0ff95779a9a61029cd90535110b81587bbe0387500634f8bdf58ecf0be0dedb77450fb53b68
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- seko_ecom_api (0.1.0)
4
+ seko_ecom_api (0.1.1)
5
5
  activesupport
6
6
  faraday (~> 2.7)
7
7
  faraday-encoding
@@ -20,11 +20,13 @@ GEM
20
20
  ast (2.4.2)
21
21
  coderay (1.1.3)
22
22
  concurrent-ruby (1.2.2)
23
+ crack (0.4.5)
24
+ rexml
23
25
  diff-lcs (1.5.0)
24
26
  domain_name (0.5.20190701)
25
27
  unf (>= 0.0.5, < 1.0.0)
26
28
  dotenv (2.8.1)
27
- faraday (2.7.4)
29
+ faraday (2.7.5)
28
30
  faraday-net_http (>= 2.0, < 3.1)
29
31
  ruby2_keywords (>= 0.0.4)
30
32
  faraday-encoding (0.0.5)
@@ -37,6 +39,7 @@ GEM
37
39
  ffi-compiler (1.0.1)
38
40
  ffi (>= 1.0.0)
39
41
  rake
42
+ hashdiff (1.0.1)
40
43
  http (5.1.1)
41
44
  addressable (~> 2.8)
42
45
  http-cookie (~> 1.0)
@@ -97,6 +100,10 @@ GEM
97
100
  unf_ext
98
101
  unf_ext (0.0.8.2)
99
102
  unicode-display_width (2.4.2)
103
+ webmock (3.18.1)
104
+ addressable (>= 2.8.0)
105
+ crack (>= 0.3.2)
106
+ hashdiff (>= 0.4.0, < 2.0.0)
100
107
 
101
108
  PLATFORMS
102
109
  arm64-darwin-21
@@ -108,6 +115,7 @@ DEPENDENCIES
108
115
  rspec
109
116
  rubocop (~> 1.21)
110
117
  seko_ecom_api!
118
+ webmock
111
119
 
112
120
  BUNDLED WITH
113
121
  2.3.18
data/README.md CHANGED
@@ -40,12 +40,12 @@ omni_returns_client.create_shipment(params)
40
40
  # For example:
41
41
  destination = {
42
42
  "address" : {
43
- "building_name" : "",
44
- "street_address": "123th St",
45
- "suburb": "Los Angeles",
46
- "city": "CA",
47
- "post_code": "90013",
48
- "country_code": "US"
43
+ "building_name" : "",
44
+ "street_address": "123th St",
45
+ "suburb": "Los Angeles",
46
+ "city": "CA",
47
+ "post_code": "90013",
48
+ "country_code": "US"
49
49
  }
50
50
  }
51
51
  ```
@@ -56,6 +56,7 @@ omni_returns_client = SekoEcomAPI::OmniReturnsClient.new(access_key: ENV['ACCESS
56
56
  ```
57
57
 
58
58
  For error handling, you might encounter SekoEcomAPI::Error and SekoEcomAPI::ParseError
59
+
59
60
  ```ruby
60
61
  begin
61
62
  omni_returns_client.create_shipment(params)
@@ -70,7 +71,23 @@ end
70
71
  ```
71
72
 
72
73
  ### OmniParcel
73
- TBA
74
+
75
+ ```ruby
76
+ omni_parcel_client = SekoEcomAPI::OmniParcelClient.new(access_key: ENV['ACCESS_KEY'])
77
+
78
+ # Retrieve rates
79
+ omni_parcel_client.retrieve_rates(params)
80
+ ```
81
+
82
+ For error handle, there will only be SekoEcomAPI::Error with the Validation errors message
83
+
84
+ ```ruby
85
+ begin
86
+ omni_parcel_client.retrieve_rates(params)
87
+ rescue SekoEcomAPI::Error => err
88
+ end
89
+
90
+ ```
74
91
 
75
92
  ## Development
76
93
 
@@ -0,0 +1,55 @@
1
+ require 'faraday'
2
+ require 'faraday/encoding'
3
+ require 'faraday/http'
4
+
5
+ module SekoEcomAPI
6
+ class OmniParcelClient
7
+ include Client
8
+
9
+ BASE_URL = 'https://api.omniparcel.com/'
10
+ TEST_BASE_URL = 'https://staging.omniparcel.com/'
11
+
12
+ attr_reader :access_key, :adapter, :test, :conn_opts
13
+
14
+ def initialize(access_key:, adapter: :http, test: false, conn_opts: {})
15
+ @access_key = access_key
16
+ @adapter = adapter
17
+ @test = test
18
+ @conn_opts = conn_opts
19
+ end
20
+
21
+ def retrieve_rates(params)
22
+ response = handle_response post_request('ratesqueryv1/availablerates', params: params)
23
+
24
+ available_rates = response['available']&.map { |rate| Rate.new(rate) }
25
+ rejected_rates = response['rejected']&.map { |rate| Rate.new(rate) }
26
+ hidden_rates = response['hidden']&.map { |rate| Rate.new(rate) }
27
+
28
+ Struct.new(:available, :rejected, :hidden).new(available_rates, rejected_rates, hidden_rates)
29
+ end
30
+
31
+ def connection
32
+ @connection ||= Faraday.new do |conn|
33
+ conn.url_prefix = test ? TEST_BASE_URL : BASE_URL
34
+ conn.options.merge!(conn_opts)
35
+ conn.headers['Access_Key'] = access_key
36
+ conn.request :json
37
+ conn.response :json, content_type: 'application/json'
38
+ conn.response :encoding
39
+ conn.adapter adapter
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ def handle_response(response)
46
+ super
47
+ transformed_body = response.body.deep_transform_keys(&:underscore)
48
+
49
+ validation_errors = transformed_body['validation_errors']
50
+ raise Error, "Something went wrong. Validation errors message: #{validation_errors}" if validation_errors.present?
51
+
52
+ transformed_body
53
+ end
54
+ end
55
+ end
@@ -24,8 +24,6 @@ module SekoEcomAPI
24
24
  Shipment.new(response)
25
25
  end
26
26
 
27
- private
28
-
29
27
  def connection
30
28
  @connection ||= Faraday.new do |conn|
31
29
  conn.url_prefix = test ? TEST_BASE_URL : BASE_URL
@@ -38,6 +36,10 @@ module SekoEcomAPI
38
36
  end
39
37
  end
40
38
 
39
+ private
40
+
41
+ # since Seko seems to send a 200 OK response even if there're errors
42
+ # we will need to also check for errors in the response body
41
43
  def handle_response(response)
42
44
  super
43
45
  parsed_response = parse_response(response)
@@ -48,6 +50,9 @@ module SekoEcomAPI
48
50
  parsed_response
49
51
  end
50
52
 
53
+ # need to be manual parsed here instead of in the middleware
54
+ # since Seko response's Content-Type is always in 'text/html'
55
+ # with the response body can be in JSON or in html
51
56
  def parse_response(response)
52
57
  parsed_response = JSON.parse(response.body)
53
58
  parsed_response.deep_transform_keys(&:underscore)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SekoEcomAPI
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
data/lib/seko_ecom_api.rb CHANGED
@@ -11,5 +11,6 @@ module SekoEcomAPI
11
11
  autoload :Shipment, 'seko_ecom_api/objects/shipment'
12
12
 
13
13
  # Clients
14
+ autoload :OmniParcelClient, 'seko_ecom_api/clients/omni_parcel_client'
14
15
  autoload :OmniReturnsClient, 'seko_ecom_api/clients/omni_returns_client'
15
16
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seko_ecom_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jane Trang Mai Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-06-08 00:00:00.000000000 Z
11
+ date: 2023-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: webmock
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  description:
112
126
  email:
113
127
  - jane.trangm@gmail.com
@@ -126,6 +140,7 @@ files:
126
140
  - Rakefile
127
141
  - lib/seko_ecom_api.rb
128
142
  - lib/seko_ecom_api/client.rb
143
+ - lib/seko_ecom_api/clients/omni_parcel_client.rb
129
144
  - lib/seko_ecom_api/clients/omni_returns_client.rb
130
145
  - lib/seko_ecom_api/error.rb
131
146
  - lib/seko_ecom_api/object.rb