shiprocket_api 0.3.0 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c057099ffcbca01d9bd58bc897b1c4fabc88ba62829936265fae8501fe878eb1
4
- data.tar.gz: 9181af583fd91e33238fc6ea455eef127493a94297efcebda5ec58514de46265
3
+ metadata.gz: 1e55a3ebda672952872f26c745bc366c00ddad9f431535df333a542768a685d8
4
+ data.tar.gz: 2f4e70f857c0388cf03eb52a3844fdac59f5c84f3e7955fbc3f4b40ec1012d12
5
5
  SHA512:
6
- metadata.gz: 6c07cca3490315c4c51dfde8a58bac0230468e7d6f958f0e4c858cb06b64e360877aefbece413c1b43fca23fe5b94bb019c981a168c13d519aa5acbe9495b87d
7
- data.tar.gz: 54d5ff95903c61046d096f711dad7058c6bcc3e9d3ee7fbcee7391b9a8cfbdfa2a8df6b897c665b7e921322111123a8c4623c0f56d038984d2b00e4a6afafcef
6
+ metadata.gz: 8b9703cef3013af7bd5e9a76b7b59c4d8c036edaed872b32245d745a9203f97365d7010e9f43b65be48114e32f000e4c204f2987ae60ce59e482d27cf939b4f2
7
+ data.tar.gz: 3a8b58fd4c08838c3138b23fe98ec3c9e1df60205492004b2580ceaa463d3228c9e9719687f87671e5e3b358766c297fa19fc9b655177ae70d6a831762aa2c89
data/Gemfile.lock CHANGED
@@ -1,15 +1,15 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- shiprocket_api (0.2.0)
4
+ shiprocket_api (0.4.2)
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.0.3.4)
12
- activesupport (= 6.0.3.4)
11
+ activemodel (6.1.0)
12
+ activesupport (= 6.1.0)
13
13
  activemodel-serializers-xml (1.0.2)
14
14
  activemodel (> 5.x)
15
15
  activesupport (> 5.x)
@@ -18,12 +18,12 @@ GEM
18
18
  activemodel (>= 5.0, < 7)
19
19
  activemodel-serializers-xml (~> 1.0)
20
20
  activesupport (>= 5.0, < 7)
21
- activesupport (6.0.3.4)
21
+ activesupport (6.1.0)
22
22
  concurrent-ruby (~> 1.0, >= 1.0.2)
23
- i18n (>= 0.7, < 2)
24
- minitest (~> 5.1)
25
- tzinfo (~> 1.1)
26
- zeitwerk (~> 2.2, >= 2.2.2)
23
+ i18n (>= 1.6, < 2)
24
+ minitest (>= 5.1)
25
+ tzinfo (~> 2.0)
26
+ zeitwerk (~> 2.3)
27
27
  addressable (2.7.0)
28
28
  public_suffix (>= 2.0.2, < 5.0)
29
29
  builder (3.2.4)
@@ -61,8 +61,8 @@ 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.1)
65
- ffi-compiler (>= 1.0, < 2.0)
64
+ http-parser (1.2.2)
65
+ ffi-compiler
66
66
  i18n (1.8.5)
67
67
  concurrent-ruby (~> 1.0)
68
68
  listen (3.2.1)
@@ -101,13 +101,12 @@ GEM
101
101
  rspec-support (3.9.3)
102
102
  shellany (0.0.1)
103
103
  thor (1.0.1)
104
- thread_safe (0.3.6)
105
- tzinfo (1.2.7)
106
- thread_safe (~> 0.1)
104
+ tzinfo (2.0.3)
105
+ concurrent-ruby (~> 1.0)
107
106
  unf (0.1.4)
108
107
  unf_ext
109
108
  unf_ext (0.0.7.7)
110
- zeitwerk (2.4.0)
109
+ zeitwerk (2.4.2)
111
110
 
112
111
  PLATFORMS
113
112
  ruby
data/Guardfile ADDED
@@ -0,0 +1,70 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec features) \
6
+ # .select{|d| Dir.exist?(d) ? d : UI.warning("Directory #{d} does not exist")}
7
+
8
+ ## Note: if you are using the `directories` clause above and you are not
9
+ ## watching the project directory ('.'), then you will want to move
10
+ ## the Guardfile to a watched dir and symlink it back, e.g.
11
+ #
12
+ # $ mkdir config
13
+ # $ mv Guardfile config/
14
+ # $ ln -s config/Guardfile .
15
+ #
16
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
17
+
18
+ # Note: The cmd option is now required due to the increasing number of ways
19
+ # rspec may be run, below are examples of the most common uses.
20
+ # * bundler: 'bundle exec rspec'
21
+ # * bundler binstubs: 'bin/rspec'
22
+ # * spring: 'bin/rspec' (This will use spring if running and you have
23
+ # installed the spring binstubs per the docs)
24
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
25
+ # * 'just' rspec: 'rspec'
26
+
27
+ guard :rspec, cmd: "bundle exec rspec" do
28
+ require "guard/rspec/dsl"
29
+ dsl = Guard::RSpec::Dsl.new(self)
30
+
31
+ # Feel free to open issues for suggestions and improvements
32
+
33
+ # RSpec files
34
+ rspec = dsl.rspec
35
+ watch(rspec.spec_helper) { rspec.spec_dir }
36
+ watch(rspec.spec_support) { rspec.spec_dir }
37
+ watch(rspec.spec_files)
38
+
39
+ # Ruby files
40
+ ruby = dsl.ruby
41
+ dsl.watch_spec_files_for(ruby.lib_files)
42
+
43
+ # Rails files
44
+ rails = dsl.rails(view_extensions: %w(erb haml slim))
45
+ dsl.watch_spec_files_for(rails.app_files)
46
+ dsl.watch_spec_files_for(rails.views)
47
+
48
+ watch(rails.controllers) do |m|
49
+ [
50
+ rspec.spec.call("routing/#{m[1]}_routing"),
51
+ rspec.spec.call("controllers/#{m[1]}_controller"),
52
+ rspec.spec.call("acceptance/#{m[1]}")
53
+ ]
54
+ end
55
+
56
+ # Rails config changes
57
+ watch(rails.spec_helper) { rspec.spec_dir }
58
+ watch(rails.routes) { "#{rspec.spec_dir}/routing" }
59
+ watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
60
+
61
+ # Capybara features specs
62
+ watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
63
+ watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
64
+
65
+ # Turnip features and steps
66
+ watch(%r{^spec/acceptance/(.+)\.feature$})
67
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
68
+ Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
69
+ end
70
+ end
@@ -17,5 +17,8 @@ module ShiprocketAPI
17
17
  require 'shiprocket_api/resources/channel'
18
18
  require 'shiprocket_api/resources/courier_serviceability'
19
19
  require 'shiprocket_api/resources/tracking'
20
-
20
+ require 'shiprocket_api/resources/label'
21
+ require 'shiprocket_api/resources/pickup'
22
+ require 'shiprocket_api/resources/return_order'
23
+ require 'shiprocket_api/resources/return_order/awb'
21
24
  end
@@ -33,7 +33,8 @@ module ShiprocketAPI
33
33
 
34
34
  # Handles response and error codes from the remote service.
35
35
  def handle_response(response)
36
- if response.code.to_i == 200 && JSON.parse(response.body).keys.include?("message")
36
+ if response.code.to_i == 200 &&
37
+ JSON.parse(response.body).dig("message") || JSON.parse(response.body).dig("payload", "error_message")
37
38
  raise CreationError.new(response)
38
39
  else
39
40
  super
@@ -6,7 +6,12 @@ module ShiprocketAPI
6
6
  end
7
7
 
8
8
  def to_s
9
- JSON.parse(@response.body)["message"]
9
+ 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")
13
+
14
+ message || "#{error_message} when #{action}"
10
15
  end
11
16
  end
12
17
  end
@@ -29,9 +29,9 @@ module ShiprocketAPI
29
29
  clear_session
30
30
  end
31
31
 
32
- def set_resource(resource)
32
+ def set_prefix(prefix)
33
33
  ori_prefix = self.prefix
34
- self.prefix = self.prefix.split("/")[0..-2].append(resource).join("/")
34
+ self.prefix = prefix
35
35
  result = yield
36
36
  self.prefix = ori_prefix
37
37
  result
@@ -0,0 +1,11 @@
1
+ module ShiprocketAPI
2
+ class Label < Base
3
+ self.prefix += "/courier/generate/label"
4
+ self.element_name= ""
5
+
6
+ DEFAULT_ATTRS = {
7
+ shipment_id: [0]
8
+ }
9
+
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ module ShiprocketAPI
2
+ class Pickup < Base
3
+ self.prefix += "/courier/generate/pickup"
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
13
+
@@ -26,7 +26,7 @@ module ShiprocketAPI
26
26
  class << self
27
27
 
28
28
  def set_prefix_to_list_all_locations
29
- set_resource('pickup') do
29
+ set_prefix("#{Base.prefix}/settings/company/pickup") do
30
30
  yield
31
31
  end
32
32
  end
@@ -45,6 +45,10 @@ module ShiprocketAPI
45
45
  end
46
46
  end
47
47
 
48
-
48
+ def id_from_response(response)
49
+ JSON.parse(response.body).dig("address", "id")
50
+ rescue JSON::ParserError
51
+ nil
52
+ end
49
53
  end
50
54
  end
@@ -0,0 +1,93 @@
1
+ module ShiprocketAPI
2
+ class ReturnOrder < Base
3
+ self.prefix += "/orders/create/return"
4
+ self.element_name= ""
5
+
6
+ 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: "",
33
+ order_items: [
34
+ ShiprocketAPI::OrderItem.new
35
+ ],
36
+ payment_method: "",
37
+ total_discount: "",
38
+ sub_total: "",
39
+ length: "",
40
+ breadth: "",
41
+ height: "",
42
+ weight: ""
43
+ }
44
+
45
+ class << self
46
+
47
+ def set_prefix_to_list_all
48
+ set_prefix("#{Base.prefix}/orders/processing/return") do
49
+ yield
50
+ end
51
+ end
52
+
53
+ def find_every(options)
54
+ set_prefix_to_list_all do
55
+ prefix_options, query_options = split_options(options[:params])
56
+ path = collection_path(prefix_options, query_options)
57
+ instantiate_collection((format.decode(connection.get(path, headers).body)["data"] || []), query_options, prefix_options)
58
+ rescue ActiveResource::ResourceNotFound
59
+ # Swallowing ResourceNotFound exceptions and return nil - as per
60
+ # ActiveRecord.
61
+ set_prefix_to_add
62
+ nil
63
+ end
64
+ end
65
+ end
66
+
67
+ def generate_awb(courier_id:)
68
+ self.awb = Awb.new(
69
+ shipment_id: shipment_id,
70
+ courier_id: courier_id,
71
+ is_return: 1
72
+ )
73
+ self.awb.save
74
+ end
75
+
76
+ def generate_label
77
+ return false unless respond_to?(:shipment_id) && shipment_id != 0
78
+
79
+ self.label = ::ShiprocketAPI::Label.new(shipment_id: [shipment_id])
80
+ self.label.save
81
+ end
82
+
83
+ def create_pickup(courier_id:)
84
+ self.pickup = ::ShiprocketAPI::Pickup.new(
85
+ shipment_id: shipment_id,
86
+ courier_id: courier_id,
87
+ is_return: 1
88
+ )
89
+ self.pickup.save
90
+ end
91
+ end
92
+ end
93
+
@@ -0,0 +1,12 @@
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
@@ -6,7 +6,7 @@ module ShiprocketAPI
6
6
  class << self
7
7
 
8
8
  def find_by_shipment_id(id)
9
- set_resource('shipment') do
9
+ set_prefix("#{Base.prefix}/courier/track/shipment") do
10
10
  find(id)
11
11
  end
12
12
  end
@@ -1,3 +1,3 @@
1
1
  module ShiprocketAPI
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.3"
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.3.0
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Chong
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-11-30 00:00:00.000000000 Z
11
+ date: 2021-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeresource
@@ -121,6 +121,7 @@ files:
121
121
  - CODE_OF_CONDUCT.md
122
122
  - Gemfile
123
123
  - Gemfile.lock
124
+ - Guardfile
124
125
  - LICENSE.txt
125
126
  - README.md
126
127
  - Rakefile
@@ -137,8 +138,12 @@ files:
137
138
  - lib/shiprocket_api/resources/courier_serviceability.rb
138
139
  - lib/shiprocket_api/resources/custom_order.rb
139
140
  - lib/shiprocket_api/resources/forward_shipment.rb
141
+ - lib/shiprocket_api/resources/label.rb
140
142
  - lib/shiprocket_api/resources/order_item.rb
143
+ - lib/shiprocket_api/resources/pickup.rb
141
144
  - lib/shiprocket_api/resources/pickup_location.rb
145
+ - lib/shiprocket_api/resources/return_order.rb
146
+ - lib/shiprocket_api/resources/return_order/awb.rb
142
147
  - lib/shiprocket_api/resources/session.rb
143
148
  - lib/shiprocket_api/resources/tracking.rb
144
149
  - lib/shiprocket_api/version.rb