shiprocket_api 0.1.0 → 0.4.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: 122050eabae3accd1e92af9aa33f684b387d2b4e651ebf1f5128b0363a3169a7
4
- data.tar.gz: 655b4d1fac605f8ac5a7535cf1b8308a5dd1ad1b06992a3eda1f484b2787f050
3
+ metadata.gz: 9443675fd36232802cef16bf5c4105353594adc46dc13f31eb85088e6c005403
4
+ data.tar.gz: 2eb9395ca60960164123800c6519b5a2336d34cef8923842b16e9caf57d3a354
5
5
  SHA512:
6
- metadata.gz: e7d35d6ec3ef05c2eb0959bc59d9bc4c521c6610db8157ccd77e44bc7865ded10ee81c9695035f6341285cf79b49a35dcb97f5116ac62ded34f574efc1ca7299
7
- data.tar.gz: 4f67afabbee20217ac0cd24194a18a41f11bfba91271af3972a74620a55cebc768992e02dbe5492134d15c2c3c62175b3d66350d3fd0fdaf838c0a0a9303628e
6
+ metadata.gz: bddf22356aec2bf2ffc168c1737b162ce8df328fc5dd8deebb3e1379c6bba24e8100382c39f9de9d51eea264bdbc28173f08928010fef9f66fe069afa6c25cc0
7
+ data.tar.gz: 0ab7edd322b605a323a5b1c25e18e306f8c7f8146973f7c04bed8616ea323c957c1e7cf7aed13e8351c9cd2a3ff738014fa475702570a37f60698818da2c8c99
data/Gemfile.lock CHANGED
@@ -1,15 +1,15 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- shiprocket_api (0.1.0)
4
+ shiprocket_api (0.4.0)
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
@@ -8,6 +8,7 @@ loader.inflector.inflect(
8
8
  loader.push_dir("./lib")
9
9
  loader.collapse("./lib/shiprocket_api/resources")
10
10
  loader.ignore("#{__dir__}/config.rb")
11
+ loader.ignore("./lib/shiprocket_api/errors.rb")
11
12
  loader.enable_reloading
12
13
  # loader.log!
13
14
  loader.setup
@@ -6,6 +6,7 @@ module ShiprocketAPI
6
6
 
7
7
  require 'shiprocket_api/configuration'
8
8
  require 'shiprocket_api/connection'
9
+ require 'shiprocket_api/errors'
9
10
 
10
11
  require 'shiprocket_api/resources/base'
11
12
  require 'shiprocket_api/resources/session'
@@ -15,4 +16,9 @@ module ShiprocketAPI
15
16
  require 'shiprocket_api/resources/pickup_location'
16
17
  require 'shiprocket_api/resources/channel'
17
18
  require 'shiprocket_api/resources/courier_serviceability'
19
+ require 'shiprocket_api/resources/tracking'
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'
18
24
  end
@@ -30,5 +30,15 @@ module ShiprocketAPI
30
30
  rescue OpenSSL::SSL::SSLError => e
31
31
  raise ActiveResource::SSLError.new(e.message)
32
32
  end
33
+
34
+ # Handles response and error codes from the remote service.
35
+ def handle_response(response)
36
+ 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)
39
+ else
40
+ super
41
+ end
42
+ end
33
43
  end
34
44
  end
@@ -0,0 +1,17 @@
1
+ module ShiprocketAPI
2
+ class CreationError < ActiveResource::ConnectionError
3
+
4
+ def data
5
+ JSON.parse(@response.body).dig("data", "data")
6
+ end
7
+
8
+ def to_s
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}"
15
+ end
16
+ end
17
+ end
@@ -20,6 +20,22 @@ module ShiprocketAPI
20
20
  self.session = nil
21
21
  self.connection.bearer_token = nil
22
22
  end
23
+
24
+ def with_temp_session(email:, password:, &block)
25
+ raise ArgumentError, "A block must be given" unless block
26
+
27
+ create_session(email: email, password: password)
28
+ yield
29
+ clear_session
30
+ end
31
+
32
+ def set_prefix(prefix)
33
+ ori_prefix = self.prefix
34
+ self.prefix = prefix
35
+ result = yield
36
+ self.prefix = ori_prefix
37
+ result
38
+ end
23
39
  end
24
40
 
25
41
  def initialize(attributes = {}, persisted = false)
@@ -6,23 +6,23 @@ module ShiprocketAPI
6
6
  has_many :order_items, class_name: "ShiprocketAPI::OrderItem"
7
7
 
8
8
  DEFAULT_ATTRS = {
9
- order_id: "1235",
9
+ order_id: "",
10
10
  order_date: Date.today.strftime("%Y-%m-%d"),
11
- pickup_location: "test1",
11
+ pickup_location: "",
12
12
  channel_id: "",
13
13
  comment: "",
14
14
  reseller_name: "",
15
15
  company_name: "",
16
- billing_customer_name: "Andy Chong",
16
+ billing_customer_name: "",
17
17
  billing_last_name: "",
18
- billing_address: "Salarpuria Symbiosis, Arekere Village, Begur, Bannerghatta Main Rd, Uttarahalli Hobli",
18
+ billing_address: "",
19
19
  billing_address_2: "",
20
- billing_city: "Bengaluru",
21
- billing_pincode: "560076",
22
- billing_state: "Karnataka",
23
- billing_country: "India",
24
- billing_email: "andy@postco.co",
25
- billing_phone: 9223361686,
20
+ billing_city: "",
21
+ billing_pincode: "",
22
+ billing_state: "",
23
+ billing_country: "",
24
+ billing_email: "",
25
+ billing_phone: "",
26
26
  billing_alternate_phone: "",
27
27
  shipping_is_billing: true,
28
28
  shipping_customer_name: "",
@@ -41,15 +41,13 @@ module ShiprocketAPI
41
41
  giftwrap_charges: "",
42
42
  transaction_charges: "",
43
43
  total_discount: "",
44
- sub_total: 1000,
45
- length: 0.5,
46
- breadth: 0.5,
47
- height: 0.5,
48
- weight: 0.5,
44
+ sub_total: "",
45
+ length: "",
46
+ breadth: "",
47
+ height: "",
48
+ weight: "",
49
49
  ewaybill_no: "",
50
50
  customer_gstin: ""
51
51
  }
52
-
53
-
54
52
  end
55
53
  end
@@ -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
+
@@ -24,16 +24,15 @@ module ShiprocketAPI
24
24
  }
25
25
 
26
26
  class << self
27
- def set_prefix_to_list
28
- ori_prefix = self.prefix
29
- self.prefix = self.prefix.split("/")[0..-2].append("pickup").join("/")
30
- result = yield
31
- self.prefix = ori_prefix
32
- result
27
+
28
+ def set_prefix_to_list_all_locations
29
+ set_prefix("#{Base.prefix}/settings/company/pickup") do
30
+ yield
31
+ end
33
32
  end
34
33
 
35
34
  def find_every(options)
36
- set_prefix_to_list do
35
+ set_prefix_to_list_all_locations do
37
36
  prefix_options, query_options = split_options(options[:params])
38
37
  path = collection_path(prefix_options, query_options)
39
38
  instantiate_collection((format.decode(connection.get(path, headers).body) || []), query_options, prefix_options)
@@ -46,6 +45,10 @@ module ShiprocketAPI
46
45
  end
47
46
  end
48
47
 
49
-
48
+ def id_from_response(response)
49
+ JSON.parse(response.body).dig("address", "id")
50
+ rescue JSON::ParserError
51
+ nil
52
+ end
50
53
  end
51
54
  end
@@ -0,0 +1,62 @@
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
+ 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
+ )
51
+ end
52
+
53
+ def create_pickup(courier_id:)
54
+ self.pickup = Pickup.create(
55
+ shipment_id: shipment_id,
56
+ courier_id: courier_id,
57
+ is_return: 1
58
+ )
59
+ end
60
+ end
61
+ end
62
+
@@ -0,0 +1,18 @@
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
@@ -0,0 +1,16 @@
1
+ module ShiprocketAPI
2
+ class Tracking < Base
3
+ self.prefix += "/courier/track/awb"
4
+ self.element_name = ""
5
+
6
+ class << self
7
+
8
+ def find_by_shipment_id(id)
9
+ set_prefix("#{Base.prefix}/courier/track/shipment") do
10
+ find(id)
11
+ end
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -1,3 +1,3 @@
1
1
  module ShiprocketAPI
2
- VERSION = "0.1.0"
2
+ VERSION = "0.4.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.1.0
4
+ version: 0.4.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: 2020-10-22 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
@@ -131,14 +132,20 @@ files:
131
132
  - lib/shiprocket_api.rb
132
133
  - lib/shiprocket_api/configuration.rb
133
134
  - lib/shiprocket_api/connection.rb
135
+ - lib/shiprocket_api/errors.rb
134
136
  - lib/shiprocket_api/resources/base.rb
135
137
  - lib/shiprocket_api/resources/channel.rb
136
138
  - lib/shiprocket_api/resources/courier_serviceability.rb
137
139
  - lib/shiprocket_api/resources/custom_order.rb
138
140
  - lib/shiprocket_api/resources/forward_shipment.rb
141
+ - lib/shiprocket_api/resources/label.rb
139
142
  - lib/shiprocket_api/resources/order_item.rb
143
+ - lib/shiprocket_api/resources/pickup.rb
140
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
141
147
  - lib/shiprocket_api/resources/session.rb
148
+ - lib/shiprocket_api/resources/tracking.rb
142
149
  - lib/shiprocket_api/version.rb
143
150
  - shiprocket_api.gemspec
144
151
  homepage: https://github.com/PostCo/sendle_api