shiprocket_api 0.4.2 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eea27e39a84bacbf22bb87d029727e5fb6260bcd7a759ce78dbcdd3df4ecde98
4
- data.tar.gz: 6ecca1cc3ce87622b7d072ae89d2446c221c39ea79ba8f84d7b7a184496e5872
3
+ metadata.gz: 0e2099d36382354538968648afc2e8803446cff0c7b8e45ba739066d576c7e59
4
+ data.tar.gz: 836dff95ffdace4c4650495506593d9726260a07dacd30ddddd9bbbe4d2b0151
5
5
  SHA512:
6
- metadata.gz: 53bb04015d04726c6fc71025c73ae6aec064722b3e49d7de66aae9a43c396faad61b3849b91c66a0334e995b8beeb9cd5cd6299da77d106d4d146a7b7e963008
7
- data.tar.gz: 6759589bf4118690de8a592512d350d246e8d75a9c32430078539f5660fc2474465072a5a6d50788ad7e3aaeb41924258f83b02eb5f6f689762fb07cdef9c27e
6
+ metadata.gz: 1f974cf47379525e08bf71b026e698aefe2df9ff9478436cfd6a08cba6c9974264c5fbd5bcd15e42764ff4ca6f4a8134403abb79b197b49055be51d2f7e18f83
7
+ data.tar.gz: 30514bb25e577afa0c6cc85edc50c82856f287ccf67fb54806e26f05d17d151e456e64daea33d45d7b2db11a0391cc0a18e8d1a17ba0e17900c47d30e21fa454
data/Gemfile.lock CHANGED
@@ -1,15 +1,15 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- shiprocket_api (0.4.1)
4
+ shiprocket_api (0.5.1)
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
  }
40
+
41
+ def generate_awb(courier_id:)
42
+ return false unless attributes['shipment_id'] && shipment_id != 0
43
+
44
+ self.awb = ::ShiprocketAPI::Awb.new(
45
+ shipment_id: shipment_id,
46
+ courier_id: courier_id,
47
+ is_return: 0
48
+ )
49
+ awb.save
50
+ end
52
51
  end
53
- 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,60 +1,61 @@
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
+
8
+ has_many :order_items, class_name: 'ShiprocketAPI::OrderItem'
9
+
6
10
  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: "",
11
+ order_id: '',
12
+ order_date: '',
13
+ channel_id: '',
14
+ pickup_customer_name: '',
15
+ pickup_last_name: '',
16
+ pickup_address: '',
17
+ pickup_address_2: '',
18
+ pickup_city: '',
19
+ pickup_state: '',
20
+ pickup_country: '',
21
+ pickup_pincode: '',
22
+ pickup_email: '',
23
+ pickup_phone: '',
24
+ pickup_isd_code: '',
25
+ pickup_location_id: '',
26
+ shipping_customer_name: '',
27
+ shipping_last_name: '',
28
+ shipping_address: '',
29
+ shipping_address_2: '',
30
+ shipping_city: '',
31
+ shipping_country: '',
32
+ shipping_pincode: '',
33
+ shipping_state: '',
34
+ shipping_email: '',
35
+ shipping_isd_code: '',
36
+ shipping_phone: '',
33
37
  order_items: [
34
38
  ShiprocketAPI::OrderItem.new
35
39
  ],
36
- payment_method: "",
37
- total_discount: "",
38
- sub_total: "",
39
- length: "",
40
- breadth: "",
41
- height: "",
42
- weight: ""
40
+ payment_method: 'Prepaid',
41
+ sub_total: '',
42
+ length: '',
43
+ breadth: '',
44
+ height: '',
45
+ weight: ''
43
46
  }
44
47
 
45
48
  class << self
46
-
47
- def set_prefix_to_list_all
48
- set_prefix("#{Base.prefix}/orders/processing/return") do
49
- yield
50
- end
49
+ def set_prefix_to_list_all(&block)
50
+ set_prefix("#{Base.prefix}/orders/processing/return", &block)
51
51
  end
52
52
 
53
53
  def find_every(options)
54
54
  set_prefix_to_list_all do
55
55
  prefix_options, query_options = split_options(options[:params])
56
56
  path = collection_path(prefix_options, query_options)
57
- instantiate_collection((format.decode(connection.get(path, headers).body)["data"] || []), query_options, prefix_options)
57
+ instantiate_collection((format.decode(connection.get(path, headers).body)['data'] || []), query_options,
58
+ prefix_options)
58
59
  rescue ActiveResource::ResourceNotFound
59
60
  # Swallowing ResourceNotFound exceptions and return nil - as per
60
61
  # ActiveRecord.
@@ -65,20 +66,14 @@ module ShiprocketAPI
65
66
  end
66
67
 
67
68
  def generate_awb(courier_id:)
68
- self.awb = Awb.create(
69
- shipment_id: shipment_id,
70
- courier_id: courier_id,
71
- is_return: 1
72
- )
73
- end
69
+ return false unless attributes['shipment_id'] && shipment_id != 0
74
70
 
75
- def create_pickup(courier_id:)
76
- self.pickup = Pickup.create(
71
+ self.awb = ::ShiprocketAPI::Awb.new(
77
72
  shipment_id: shipment_id,
78
73
  courier_id: courier_id,
79
74
  is_return: 1
80
75
  )
76
+ awb.save
81
77
  end
82
78
  end
83
79
  end
84
-
@@ -0,0 +1,19 @@
1
+ module ShiprocketAPI
2
+ module Shared
3
+ module OrderHelper
4
+ def generate_label
5
+ return false unless attributes['shipment_id'] && shipment_id != 0
6
+
7
+ self.label = ::ShiprocketAPI::Label.new(shipment_id: [shipment_id])
8
+ label.save
9
+ end
10
+
11
+ def create_pickup
12
+ return false unless attributes['shipment_id'] && shipment_id != 0
13
+
14
+ self.pickup = ::ShiprocketAPI::Pickup.new(shipment_id: [shipment_id])
15
+ pickup.save
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,3 +1,3 @@
1
1
  module ShiprocketAPI
2
- VERSION = "0.4.2"
2
+ VERSION = "0.5.2"
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.2
4
+ version: 0.5.2
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-16 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