shiprocket_api 0.4.1 → 0.5.1

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: 9443675fd36232802cef16bf5c4105353594adc46dc13f31eb85088e6c005403
4
- data.tar.gz: 2eb9395ca60960164123800c6519b5a2336d34cef8923842b16e9caf57d3a354
3
+ metadata.gz: daaeb47a98dc3ffd00727499089bb409b69e4675b2bde2cf4b8af03f47f88529
4
+ data.tar.gz: 3da69f20d46ae87a86442a104a1bbc7738996fe2b42fdd5a0a79dd80c550879f
5
5
  SHA512:
6
- metadata.gz: bddf22356aec2bf2ffc168c1737b162ce8df328fc5dd8deebb3e1379c6bba24e8100382c39f9de9d51eea264bdbc28173f08928010fef9f66fe069afa6c25cc0
7
- data.tar.gz: 0ab7edd322b605a323a5b1c25e18e306f8c7f8146973f7c04bed8616ea323c957c1e7cf7aed13e8351c9cd2a3ff738014fa475702570a37f60698818da2c8c99
6
+ metadata.gz: 8af0d4efaff52ee451c2ffe961e266400d680e755f871b63204bef4a4034a7d5fa2f324124264b720511a4424fa02d31ef57fdb0e145bc5b35bfe872ee53452f
7
+ data.tar.gz: 863d695ae42750b80296109f1a6fa07165ec718557e997c84929e0fc147dd0aeba422802799fc0ae006eeed77d63a54bb3c40dbd723eefa04df12bf1c1d8640f
data/Gemfile.lock CHANGED
@@ -1,15 +1,15 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- shiprocket_api (0.4.0)
4
+ shiprocket_api (0.4.4)
5
5
  activeresource (~> 5.0)
6
6
  http
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activemodel (6.1.0)
12
- activesupport (= 6.1.0)
11
+ activemodel (6.1.3.2)
12
+ activesupport (= 6.1.3.2)
13
13
  activemodel-serializers-xml (1.0.2)
14
14
  activemodel (> 5.x)
15
15
  activesupport (> 5.x)
@@ -18,7 +18,7 @@ GEM
18
18
  activemodel (>= 5.0, < 7)
19
19
  activemodel-serializers-xml (~> 1.0)
20
20
  activesupport (>= 5.0, < 7)
21
- activesupport (6.1.0)
21
+ activesupport (6.1.3.2)
22
22
  concurrent-ruby (~> 1.0, >= 1.0.2)
23
23
  i18n (>= 1.6, < 2)
24
24
  minitest (>= 5.1)
@@ -29,7 +29,7 @@ GEM
29
29
  builder (3.2.4)
30
30
  byebug (11.1.3)
31
31
  coderay (1.1.2)
32
- concurrent-ruby (1.1.7)
32
+ concurrent-ruby (1.1.8)
33
33
  diff-lcs (1.3)
34
34
  domain_name (0.5.20190701)
35
35
  unf (>= 0.0.5, < 1.0.0)
@@ -61,16 +61,16 @@ GEM
61
61
  http-cookie (1.0.3)
62
62
  domain_name (~> 0.5)
63
63
  http-form_data (2.3.0)
64
- http-parser (1.2.2)
65
- ffi-compiler
66
- i18n (1.8.5)
64
+ http-parser (1.2.3)
65
+ ffi-compiler (>= 1.0, < 2.0)
66
+ i18n (1.8.10)
67
67
  concurrent-ruby (~> 1.0)
68
68
  listen (3.2.1)
69
69
  rb-fsevent (~> 0.10, >= 0.10.3)
70
70
  rb-inotify (~> 0.9, >= 0.9.10)
71
71
  lumberjack (1.2.4)
72
72
  method_source (1.0.0)
73
- minitest (5.14.2)
73
+ minitest (5.14.4)
74
74
  nenv (0.3.0)
75
75
  notiffany (0.1.3)
76
76
  nenv (~> 0.1)
@@ -101,7 +101,7 @@ GEM
101
101
  rspec-support (3.9.3)
102
102
  shellany (0.0.1)
103
103
  thor (1.0.1)
104
- tzinfo (2.0.3)
104
+ tzinfo (2.0.4)
105
105
  concurrent-ruby (~> 1.0)
106
106
  unf (0.1.4)
107
107
  unf_ext
@@ -1,17 +1,17 @@
1
- require "shiprocket_api/version"
2
- require "active_resource"
1
+ require 'shiprocket_api/version'
2
+ require 'active_resource'
3
3
  require 'http'
4
4
 
5
5
  module ShiprocketAPI
6
-
7
6
  require 'shiprocket_api/configuration'
8
7
  require 'shiprocket_api/connection'
9
8
  require 'shiprocket_api/errors'
10
9
 
10
+ require 'shiprocket_api/shared/order_helper'
11
+
11
12
  require 'shiprocket_api/resources/base'
12
13
  require 'shiprocket_api/resources/session'
13
14
  require 'shiprocket_api/resources/order_item'
14
- require 'shiprocket_api/resources/custom_order'
15
15
  require 'shiprocket_api/resources/forward_shipment'
16
16
  require 'shiprocket_api/resources/pickup_location'
17
17
  require 'shiprocket_api/resources/channel'
@@ -19,6 +19,7 @@ module ShiprocketAPI
19
19
  require 'shiprocket_api/resources/tracking'
20
20
  require 'shiprocket_api/resources/label'
21
21
  require 'shiprocket_api/resources/pickup'
22
+ require 'shiprocket_api/resources/awb'
22
23
  require 'shiprocket_api/resources/return_order'
23
- require 'shiprocket_api/resources/return_order/awb'
24
+ require 'shiprocket_api/resources/custom_order'
24
25
  end
@@ -1,44 +1,42 @@
1
1
  module ShiprocketAPI
2
2
  class Connection < ActiveResource::Connection
3
-
4
3
  # override #get to handle get with body
5
4
  def get(path, headers = {}, body: nil)
6
5
  arguments = if body.nil?
7
- [path, build_request_headers(headers, :get, self.site.merge(path))]
8
- else
9
- [path, body, build_request_headers(headers, :get, self.site.merge(path))]
10
- end
6
+ [path, build_request_headers(headers, :get, site.merge(path))]
7
+ else
8
+ [path, body, build_request_headers(headers, :get, site.merge(path))]
9
+ end
11
10
  with_auth { request(:get, *arguments) }
12
11
  end
13
12
 
14
13
  def request(method, path, *arguments)
15
-
16
- result = ActiveSupport::Notifications.instrument("request.active_resource") do |payload|
14
+ result = ActiveSupport::Notifications.instrument('request.active_resource') do |payload|
17
15
  payload[:method] = method
18
16
  payload[:request_uri] = "#{site.scheme}://#{site.host}:#{site.port}#{path}"
19
17
  payload[:result] = if method == :get && arguments.length == 2
20
- HTTP.headers(arguments[1].symbolize_keys)
21
- .get(payload[:request_uri], json: arguments[0])
22
- else
23
- http.send(method, path, *arguments)
24
- end
18
+ HTTP.headers(arguments[1].symbolize_keys)
19
+ .get(payload[:request_uri], json: arguments[0])
20
+ else
21
+ http.send(method, path, *arguments)
22
+ end
25
23
  payload[:result]
26
24
  end
27
25
  handle_response(result)
28
26
  rescue Timeout::Error => e
29
- raise ActiveResource::TimeoutError.new(e.message)
27
+ raise ActiveResource::TimeoutError, e.message
30
28
  rescue OpenSSL::SSL::SSLError => e
31
- raise ActiveResource::SSLError.new(e.message)
29
+ raise ActiveResource::SSLError, e.message
32
30
  end
33
31
 
34
32
  # Handles response and error codes from the remote service.
35
33
  def handle_response(response)
36
34
  if response.code.to_i == 200 &&
37
- JSON.parse(response.body).dig("message") || JSON.parse(response.body).dig("payload", "error_message")
38
- raise CreationError.new(response)
35
+ JSON.parse(response.body)['message'] || JSON.parse(response.body).dig('payload', 'error_message')
36
+ raise CreationError, response
39
37
  else
40
38
  super
41
39
  end
42
40
  end
43
41
  end
44
- end
42
+ end
@@ -1,17 +1,16 @@
1
1
  module ShiprocketAPI
2
2
  class CreationError < ActiveResource::ConnectionError
3
-
4
3
  def data
5
- JSON.parse(@response.body).dig("data", "data")
4
+ JSON.parse(@response.body).dig('data', 'data')
6
5
  end
7
6
 
8
7
  def to_s
9
8
  response_json = JSON.parse(@response.body)
10
- message = response_json.dig("message")
11
- error_message = response_json.dig("payload", "error_message")
12
- action = response_json.dig("payload", "action")
9
+ message = response_json.dig('message')
10
+ error_message = response_json.dig('payload', 'error_message')
11
+ action = response_json.dig('payload', 'action')
13
12
 
14
13
  message || "#{error_message} when #{action}"
15
14
  end
16
15
  end
17
- end
16
+ end
@@ -0,0 +1,12 @@
1
+ module ShiprocketAPI
2
+ class Awb < Base
3
+ self.prefix += '/courier/assign/awb'
4
+ self.element_name = ''
5
+
6
+ DEFAULT_ATTRS = {
7
+ shipment_id: 0,
8
+ courier_id: 0,
9
+ is_return: 0
10
+ }
11
+ end
12
+ end
@@ -1,53 +1,52 @@
1
1
  module ShiprocketAPI
2
2
  class CustomOrder < Base
3
- self.prefix += "/orders/create/adhoc"
4
- self.element_name = ""
3
+ include Shared::OrderHelper
5
4
 
6
- has_many :order_items, class_name: "ShiprocketAPI::OrderItem"
5
+ self.prefix += '/orders/create/adhoc'
6
+ self.element_name = ''
7
+
8
+ has_many :order_items, class_name: 'ShiprocketAPI::OrderItem'
7
9
 
8
10
  DEFAULT_ATTRS = {
9
- order_id: "",
10
- order_date: Date.today.strftime("%Y-%m-%d"),
11
- pickup_location: "",
12
- channel_id: "",
13
- comment: "",
14
- reseller_name: "",
15
- company_name: "",
16
- billing_customer_name: "",
17
- billing_last_name: "",
18
- billing_address: "",
19
- billing_address_2: "",
20
- billing_city: "",
21
- billing_pincode: "",
22
- billing_state: "",
23
- billing_country: "",
24
- billing_email: "",
25
- billing_phone: "",
26
- billing_alternate_phone: "",
11
+ order_id: '',
12
+ order_date: Date.today.strftime('%Y-%m-%d'),
13
+ pickup_location: '',
14
+ channel_id: '',
15
+ comment: '',
16
+ reseller_name: '',
17
+ company_name: '',
18
+ billing_customer_name: '',
19
+ billing_last_name: '',
20
+ billing_address: '',
21
+ billing_address_2: '',
22
+ billing_city: '',
23
+ billing_pincode: '',
24
+ billing_state: '',
25
+ billing_country: '',
26
+ billing_email: '',
27
+ billing_phone: '',
28
+ billing_alternate_phone: '',
27
29
  shipping_is_billing: true,
28
- shipping_customer_name: "",
29
- shipping_last_name: "",
30
- shipping_address: "",
31
- shipping_address_2: "",
32
- shipping_city: "",
33
- shipping_pincode: "",
34
- shipping_country: "",
35
- shipping_state: "",
36
- shipping_email: "",
37
- shipping_phone: "",
38
- order_items: [ShiprocketAPI::OrderItem.new],
39
- payment_method: "Prepaid",
40
- shipping_charges: "",
41
- giftwrap_charges: "",
42
- transaction_charges: "",
43
- total_discount: "",
44
- sub_total: "",
45
- length: "",
46
- breadth: "",
47
- height: "",
48
- weight: "",
49
- ewaybill_no: "",
50
- customer_gstin: ""
30
+ order_items: [
31
+ ShiprocketAPI::OrderItem.new
32
+ ],
33
+ payment_method: 'Prepaid',
34
+ sub_total: '',
35
+ length: '',
36
+ breadth: '',
37
+ height: '',
38
+ weight: ''
51
39
  }
52
40
  end
53
- end
41
+
42
+ def generate_awb(courier_id:)
43
+ return false unless attributes['shipment_id'] && shipment_id != 0
44
+
45
+ self.awb = ::ShiprocketAPI::Awb.new(
46
+ shipment_id: shipment_id,
47
+ courier_id: courier_id,
48
+ is_return: 0
49
+ )
50
+ awb.save
51
+ end
52
+ end
@@ -4,9 +4,7 @@ module ShiprocketAPI
4
4
  self.element_name= ""
5
5
 
6
6
  DEFAULT_ATTRS = {
7
- shipment_id: 0,
8
- courier_id: 0,
9
- is_return: 1
7
+ shipment_id: [0]
10
8
  }
11
9
  end
12
10
  end
@@ -1,41 +1,40 @@
1
1
  module ShiprocketAPI
2
2
  class PickupLocation < Base
3
- self.prefix += "/settings/company/addpickup"
4
- self.element_name = ""
3
+ self.prefix += '/settings/company/addpickup'
4
+ self.element_name = ''
5
5
 
6
6
  class Collection < ActiveResource::Collection
7
7
  def initialize(parsed = {})
8
- @elements = parsed["shipping_address"]
8
+ super
9
+ @elements = parsed['shipping_address']
9
10
  end
10
11
  end
11
12
  self.collection_parser = Collection
12
13
 
13
14
  DEFAULT_ATTRS = {
14
- pickup_location: "",
15
- name: "",
16
- email: "",
17
- phone: "",
18
- address: "",
19
- address_2: "",
20
- city: "",
21
- state: "",
22
- country: "",
23
- pin_code: ""
15
+ pickup_location: '',
16
+ name: '',
17
+ email: '',
18
+ phone: '',
19
+ address: '',
20
+ address_2: '',
21
+ city: '',
22
+ state: '',
23
+ country: '',
24
+ pin_code: ''
24
25
  }
25
26
 
26
27
  class << self
27
-
28
- def set_prefix_to_list_all_locations
29
- set_prefix("#{Base.prefix}/settings/company/pickup") do
30
- yield
31
- end
28
+ def set_prefix_to_list_all_locations(&block)
29
+ set_prefix("#{Base.prefix}/settings/company/pickup", &block)
32
30
  end
33
31
 
34
32
  def find_every(options)
35
33
  set_prefix_to_list_all_locations do
36
34
  prefix_options, query_options = split_options(options[:params])
37
35
  path = collection_path(prefix_options, query_options)
38
- instantiate_collection((format.decode(connection.get(path, headers).body) || []), query_options, prefix_options)
36
+ instantiate_collection((format.decode(connection.get(path, headers).body) || []), query_options,
37
+ prefix_options)
39
38
  rescue ActiveResource::ResourceNotFound
40
39
  # Swallowing ResourceNotFound exceptions and return nil - as per
41
40
  # ActiveRecord.
@@ -44,11 +43,11 @@ module ShiprocketAPI
44
43
  end
45
44
  end
46
45
  end
47
-
46
+
48
47
  def id_from_response(response)
49
- JSON.parse(response.body).dig("address", "id")
48
+ JSON.parse(response.body).dig('address', 'id')
50
49
  rescue JSON::ParserError
51
50
  nil
52
51
  end
53
52
  end
54
- end
53
+ end
@@ -1,62 +1,77 @@
1
1
  module ShiprocketAPI
2
2
  class ReturnOrder < Base
3
- self.prefix += "/orders/create/return"
4
- self.element_name= ""
5
-
3
+ include Shared::OrderHelper
4
+
5
+ self.prefix += '/orders/create/return'
6
+ self.element_name = ''
7
+
6
8
  DEFAULT_ATTRS = {
7
- order_id: "",
8
- order_date: "",
9
- channel_id: "",
10
- pickup_customer_name: "",
11
- pickup_last_name: "",
12
- pickup_address: "",
13
- pickup_address_2: "",
14
- pickup_city: "",
15
- pickup_state: "",
16
- pickup_country: "",
17
- pickup_pincode: "",
18
- pickup_email: "",
19
- pickup_phone: "",
20
- pickup_isd_code: "",
21
- pickup_location_id: "",
22
- shipping_customer_name: "",
23
- shipping_last_name: "",
24
- shipping_address: "",
25
- shipping_address_2: "",
26
- shipping_city: "",
27
- shipping_country: "",
28
- shipping_pincode: "",
29
- shipping_state: "",
30
- shipping_email: "",
31
- shipping_isd_code: "",
32
- shipping_phone: "",
9
+ order_id: '',
10
+ order_date: '',
11
+ channel_id: '',
12
+ pickup_customer_name: '',
13
+ pickup_last_name: '',
14
+ pickup_address: '',
15
+ pickup_address_2: '',
16
+ pickup_city: '',
17
+ pickup_state: '',
18
+ pickup_country: '',
19
+ pickup_pincode: '',
20
+ pickup_email: '',
21
+ pickup_phone: '',
22
+ pickup_isd_code: '',
23
+ pickup_location_id: '',
24
+ shipping_customer_name: '',
25
+ shipping_last_name: '',
26
+ shipping_address: '',
27
+ shipping_address_2: '',
28
+ shipping_city: '',
29
+ shipping_country: '',
30
+ shipping_pincode: '',
31
+ shipping_state: '',
32
+ shipping_email: '',
33
+ shipping_isd_code: '',
34
+ shipping_phone: '',
33
35
  order_items: [
34
36
  ShiprocketAPI::OrderItem.new
35
37
  ],
36
- payment_method: "",
37
- total_discount: "",
38
- sub_total: "",
39
- length: "",
40
- breadth: "",
41
- height: "",
42
- weight: ""
38
+ payment_method: 'Prepaid',
39
+ sub_total: '',
40
+ length: '',
41
+ breadth: '',
42
+ height: '',
43
+ weight: ''
43
44
  }
44
45
 
45
- def generate_awb(courier_id:)
46
- self.awb = Awb.create(
47
- shipment_id: shipment_id,
48
- courier_id: courier_id,
49
- is_return: 1
50
- )
46
+ class << self
47
+ def set_prefix_to_list_all(&block)
48
+ set_prefix("#{Base.prefix}/orders/processing/return", &block)
49
+ end
50
+
51
+ def find_every(options)
52
+ set_prefix_to_list_all do
53
+ prefix_options, query_options = split_options(options[:params])
54
+ path = collection_path(prefix_options, query_options)
55
+ instantiate_collection((format.decode(connection.get(path, headers).body)['data'] || []), query_options,
56
+ prefix_options)
57
+ rescue ActiveResource::ResourceNotFound
58
+ # Swallowing ResourceNotFound exceptions and return nil - as per
59
+ # ActiveRecord.
60
+ set_prefix_to_add
61
+ nil
62
+ end
63
+ end
51
64
  end
52
65
 
53
- def create_pickup(courier_id:)
54
- self.pickup = Pickup.create(
66
+ def generate_awb(courier_id:)
67
+ return false unless attributes['shipment_id'] && shipment_id != 0
68
+
69
+ self.awb = ::ShiprocketAPI::Awb.new(
55
70
  shipment_id: shipment_id,
56
71
  courier_id: courier_id,
57
72
  is_return: 1
58
73
  )
74
+ awb.save
59
75
  end
60
76
  end
61
77
  end
62
-
@@ -0,0 +1,17 @@
1
+ module Shared
2
+ module OrderHelper
3
+ def generate_label
4
+ return false unless attributes['shipment_id'] && shipment_id != 0
5
+
6
+ self.label = ::ShiprocketAPI::Label.new(shipment_id: [shipment_id])
7
+ label.save
8
+ end
9
+
10
+ def create_pickup
11
+ return false unless attributes['shipment_id'] && shipment_id != 0
12
+
13
+ self.pickup = ::ShiprocketAPI::Pickup.new(shipment_id: [shipment_id])
14
+ pickup.save
15
+ end
16
+ end
17
+ end
@@ -1,3 +1,3 @@
1
1
  module ShiprocketAPI
2
- VERSION = "0.4.1"
2
+ VERSION = "0.5.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shiprocket_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Chong
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-02-02 00:00:00.000000000 Z
11
+ date: 2021-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeresource
@@ -133,6 +133,7 @@ files:
133
133
  - lib/shiprocket_api/configuration.rb
134
134
  - lib/shiprocket_api/connection.rb
135
135
  - lib/shiprocket_api/errors.rb
136
+ - lib/shiprocket_api/resources/awb.rb
136
137
  - lib/shiprocket_api/resources/base.rb
137
138
  - lib/shiprocket_api/resources/channel.rb
138
139
  - lib/shiprocket_api/resources/courier_serviceability.rb
@@ -143,9 +144,9 @@ files:
143
144
  - lib/shiprocket_api/resources/pickup.rb
144
145
  - lib/shiprocket_api/resources/pickup_location.rb
145
146
  - lib/shiprocket_api/resources/return_order.rb
146
- - lib/shiprocket_api/resources/return_order/awb.rb
147
147
  - lib/shiprocket_api/resources/session.rb
148
148
  - lib/shiprocket_api/resources/tracking.rb
149
+ - lib/shiprocket_api/shared/order_helper.rb
149
150
  - lib/shiprocket_api/version.rb
150
151
  - shiprocket_api.gemspec
151
152
  homepage: https://github.com/PostCo/sendle_api
@@ -171,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
172
  - !ruby/object:Gem::Version
172
173
  version: '0'
173
174
  requirements: []
174
- rubygems_version: 3.0.3
175
+ rubygems_version: 3.1.6
175
176
  signing_key:
176
177
  specification_version: 4
177
178
  summary: Ruby object based Sendle API wrapper.
@@ -1,18 +0,0 @@
1
- module ShiprocketAPI
2
- class ReturnOrder::Awb < Base
3
- self.prefix += "/courier/assign/awb"
4
- self.element_name= ""
5
-
6
- DEFAULT_ATTRS = {
7
- shipment_id: 0,
8
- courier_id: 0,
9
- is_return: 1
10
- }
11
-
12
- def generate_label
13
- return false unless self.attributes.shipment_id != 0
14
-
15
- self.label= ::ShiprocketAPI::Label.create([shipment_id])
16
- end
17
- end
18
- end