shiprocket_api 0.4.4 → 0.5.0

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: 9b03ee9034588c44b804bb772fcc9a69c596264a54d897c6fa0e726f349318d7
4
- data.tar.gz: e73bca24913df4676e3386c661f8d9b8c416d829cf99fa768e403396d95cceb4
3
+ metadata.gz: d6e479f884a67ba9c33fac15732871db1a0a997aad506d2736d71cda83ba77d6
4
+ data.tar.gz: 90eb64ae49b5dc68a6e4ec6b3ab6660d0c60e14c7315820b8a81083dd88ce128
5
5
  SHA512:
6
- metadata.gz: b730d322c4da4c099f8cf27534fd26a69f2061ff4cc1b7cb3005385894607e0e6e7ab0e73cf1731bc751229e66e70948b2cf0519ca3e3118afb16eabc578efae
7
- data.tar.gz: 7b368aeb68edbb2ba261ca4b9076167f096a047be692220592a6b933a876ff1281c5cad9decb4cd1a819468e80f7c1afd13d087836ada928629eea17119e34a8
6
+ metadata.gz: f8091d4335498511f68cd4e63bd38a3ec6a06111f767e13b974dc6b37308a87e7a21a3baa8b5bf5faa923d7e014aad4ea5c9c102ca6ef68fb1ee4e3a73cf310a
7
+ data.tar.gz: 0414aea496a7bb87c321bfd707f8a015ed264429f4dd264a05e01ac1c8e720803427a6cbd14e5e2ee4c926fab83c058f5d230df717b28a5c31f625c596540dd6
data/Gemfile.lock CHANGED
@@ -1,15 +1,15 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- shiprocket_api (0.4.3)
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,41 @@
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
+ 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,59 @@
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
46
  class << self
46
-
47
- def set_prefix_to_list_all
48
- set_prefix("#{Base.prefix}/orders/processing/return") do
49
- yield
50
- end
47
+ def set_prefix_to_list_all(&block)
48
+ set_prefix("#{Base.prefix}/orders/processing/return", &block)
51
49
  end
52
50
 
53
51
  def find_every(options)
54
52
  set_prefix_to_list_all do
55
53
  prefix_options, query_options = split_options(options[:params])
56
54
  path = collection_path(prefix_options, query_options)
57
- instantiate_collection((format.decode(connection.get(path, headers).body)["data"] || []), query_options, prefix_options)
55
+ instantiate_collection((format.decode(connection.get(path, headers).body)['data'] || []), query_options,
56
+ prefix_options)
58
57
  rescue ActiveResource::ResourceNotFound
59
58
  # Swallowing ResourceNotFound exceptions and return nil - as per
60
59
  # ActiveRecord.
@@ -63,31 +62,5 @@ module ShiprocketAPI
63
62
  end
64
63
  end
65
64
  end
66
-
67
- def generate_awb(courier_id:)
68
- return false unless attributes["shipment_id"] && shipment_id != 0
69
-
70
- self.awb = Awb.new(
71
- shipment_id: shipment_id,
72
- courier_id: courier_id,
73
- is_return: 1
74
- )
75
- self.awb.save
76
- end
77
-
78
- def generate_label
79
- return false unless attributes["shipment_id"] && shipment_id != 0
80
-
81
- self.label = ::ShiprocketAPI::Label.new(shipment_id: [shipment_id])
82
- self.label.save
83
- end
84
-
85
- def create_pickup
86
- return false unless attributes["shipment_id"] && shipment_id != 0
87
-
88
- self.pickup = ::ShiprocketAPI::Pickup.new(shipment_id: [shipment_id])
89
- self.pickup.save
90
- end
91
65
  end
92
66
  end
93
-
@@ -0,0 +1,28 @@
1
+ module Shared
2
+ module OrderHelper
3
+ def generate_awb(courier_id:)
4
+ return false unless attributes['shipment_id'] && shipment_id != 0
5
+
6
+ self.awb = ::ShiprocketAPI::Awb.new(
7
+ shipment_id: shipment_id,
8
+ courier_id: courier_id,
9
+ is_return: 1
10
+ )
11
+ awb.save
12
+ end
13
+
14
+ def generate_label
15
+ return false unless attributes['shipment_id'] && shipment_id != 0
16
+
17
+ self.label = ::ShiprocketAPI::Label.new(shipment_id: [shipment_id])
18
+ label.save
19
+ end
20
+
21
+ def create_pickup
22
+ return false unless attributes['shipment_id'] && shipment_id != 0
23
+
24
+ self.pickup = ::ShiprocketAPI::Pickup.new(shipment_id: [shipment_id])
25
+ pickup.save
26
+ end
27
+ end
28
+ end
@@ -1,3 +1,3 @@
1
1
  module ShiprocketAPI
2
- VERSION = "0.4.4"
2
+ VERSION = "0.5.0"
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.4
4
+ version: 0.5.0
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-05 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,12 +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
- end
12
- end