shiprocket_api 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 122050eabae3accd1e92af9aa33f684b387d2b4e651ebf1f5128b0363a3169a7
4
+ data.tar.gz: 655b4d1fac605f8ac5a7535cf1b8308a5dd1ad1b06992a3eda1f484b2787f050
5
+ SHA512:
6
+ metadata.gz: e7d35d6ec3ef05c2eb0959bc59d9bc4c521c6610db8157ccd77e44bc7865ded10ee81c9695035f6341285cf79b49a35dcb97f5116ac62ded34f574efc1ca7299
7
+ data.tar.gz: 4f67afabbee20217ac0cd24194a18a41f11bfba91271af3972a74620a55cebc768992e02dbe5492134d15c2c3c62175b3d66350d3fd0fdaf838c0a0a9303628e
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ .env
13
+ .pryrc
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.6.6
6
+ before_install: gem install bundler -v 2.1.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at andy_gg1996@hotmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in shiprocket_api.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
@@ -0,0 +1,125 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ shiprocket_api (0.1.0)
5
+ activeresource (~> 5.0)
6
+ http
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activemodel (6.0.3.4)
12
+ activesupport (= 6.0.3.4)
13
+ activemodel-serializers-xml (1.0.2)
14
+ activemodel (> 5.x)
15
+ activesupport (> 5.x)
16
+ builder (~> 3.1)
17
+ activeresource (5.1.1)
18
+ activemodel (>= 5.0, < 7)
19
+ activemodel-serializers-xml (~> 1.0)
20
+ activesupport (>= 5.0, < 7)
21
+ activesupport (6.0.3.4)
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)
27
+ addressable (2.7.0)
28
+ public_suffix (>= 2.0.2, < 5.0)
29
+ builder (3.2.4)
30
+ byebug (11.1.3)
31
+ coderay (1.1.2)
32
+ concurrent-ruby (1.1.7)
33
+ diff-lcs (1.3)
34
+ domain_name (0.5.20190701)
35
+ unf (>= 0.0.5, < 1.0.0)
36
+ dotenv (2.7.6)
37
+ ffi (1.13.1)
38
+ ffi-compiler (1.0.1)
39
+ ffi (>= 1.0.0)
40
+ rake
41
+ formatador (0.2.5)
42
+ guard (2.16.2)
43
+ formatador (>= 0.2.4)
44
+ listen (>= 2.7, < 4.0)
45
+ lumberjack (>= 1.0.12, < 2.0)
46
+ nenv (~> 0.1)
47
+ notiffany (~> 0.0)
48
+ pry (>= 0.9.12)
49
+ shellany (~> 0.0)
50
+ thor (>= 0.18.1)
51
+ guard-compat (1.2.1)
52
+ guard-rspec (4.7.3)
53
+ guard (~> 2.1)
54
+ guard-compat (~> 1.1)
55
+ rspec (>= 2.99.0, < 4.0)
56
+ http (4.4.1)
57
+ addressable (~> 2.3)
58
+ http-cookie (~> 1.0)
59
+ http-form_data (~> 2.2)
60
+ http-parser (~> 1.2.0)
61
+ http-cookie (1.0.3)
62
+ domain_name (~> 0.5)
63
+ http-form_data (2.3.0)
64
+ http-parser (1.2.1)
65
+ ffi-compiler (>= 1.0, < 2.0)
66
+ i18n (1.8.5)
67
+ concurrent-ruby (~> 1.0)
68
+ listen (3.2.1)
69
+ rb-fsevent (~> 0.10, >= 0.10.3)
70
+ rb-inotify (~> 0.9, >= 0.9.10)
71
+ lumberjack (1.2.4)
72
+ method_source (1.0.0)
73
+ minitest (5.14.2)
74
+ nenv (0.3.0)
75
+ notiffany (0.1.3)
76
+ nenv (~> 0.1)
77
+ shellany (~> 0.0)
78
+ pry (0.13.1)
79
+ coderay (~> 1.1)
80
+ method_source (~> 1.0)
81
+ pry-byebug (3.9.0)
82
+ byebug (~> 11.0)
83
+ pry (~> 0.13.0)
84
+ public_suffix (4.0.6)
85
+ rake (12.3.3)
86
+ rb-fsevent (0.10.4)
87
+ rb-inotify (0.10.1)
88
+ ffi (~> 1.0)
89
+ rspec (3.9.0)
90
+ rspec-core (~> 3.9.0)
91
+ rspec-expectations (~> 3.9.0)
92
+ rspec-mocks (~> 3.9.0)
93
+ rspec-core (3.9.2)
94
+ rspec-support (~> 3.9.3)
95
+ rspec-expectations (3.9.2)
96
+ diff-lcs (>= 1.2.0, < 2.0)
97
+ rspec-support (~> 3.9.0)
98
+ rspec-mocks (3.9.1)
99
+ diff-lcs (>= 1.2.0, < 2.0)
100
+ rspec-support (~> 3.9.0)
101
+ rspec-support (3.9.3)
102
+ shellany (0.0.1)
103
+ thor (1.0.1)
104
+ thread_safe (0.3.6)
105
+ tzinfo (1.2.7)
106
+ thread_safe (~> 0.1)
107
+ unf (0.1.4)
108
+ unf_ext
109
+ unf_ext (0.0.7.7)
110
+ zeitwerk (2.4.0)
111
+
112
+ PLATFORMS
113
+ ruby
114
+
115
+ DEPENDENCIES
116
+ dotenv
117
+ guard-rspec
118
+ pry
119
+ pry-byebug
120
+ rake (~> 12.0)
121
+ rspec (~> 3.0)
122
+ shiprocket_api!
123
+
124
+ BUNDLED WITH
125
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Andy Chong
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,98 @@
1
+ # ShiprocketAPI
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/shiprocket_api`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'shiprocket_api'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install shiprocket_api
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ ShiprocketAPI::ForwardShipment.new(
27
+ request_pickup: false,
28
+ print_label: true,
29
+ generate_manifest: true,
30
+ courier_id: 10,
31
+ order_id: "1235",
32
+ order_date: Date.today.strftime("%Y-%m-%d"),
33
+ pickup_location: "testing2",
34
+ billing_customer_name: "Andy Chong",
35
+ billing_last_name: "",
36
+ billing_address: "Salarpuria Symbiosis, Arekere Village, Begur, Bannerghatta Main Rd, Uttarahalli Hobli",
37
+ billing_address_2: "",
38
+ billing_city: "Bengaluru",
39
+ billing_pincode: "560076",
40
+ billing_state: "Karnataka",
41
+ billing_country: "India",
42
+ billing_email: "andy@postco.co",
43
+ billing_phone: 9223361686,
44
+ billing_alternate_phone: "",
45
+ shipping_is_billing: true,
46
+ shipping_customer_name: "",
47
+ shipping_last_name: "",
48
+ shipping_address: "",
49
+ shipping_address_2: "",
50
+ shipping_city: "",
51
+ shipping_pincode: "",
52
+ shipping_country: "",
53
+ shipping_state: "",
54
+ shipping_email: "",
55
+ shipping_phone: "",
56
+ order_items: [ShiprocketAPI::OrderItem.new(
57
+ name: "a book",
58
+ sku: "23232",
59
+ units: 1,
60
+ selling_price: 1234
61
+ )],
62
+ payment_method: "Prepaid",
63
+ sub_total: 1000,
64
+ length: 0.5,
65
+ breadth: 0.5,
66
+ height: 0.5,
67
+ weight: 0.5,
68
+ vendor_details: {
69
+ email: "andy@postco.co",
70
+ phone: "8888999888",
71
+ name: "Andy",
72
+ address: "C - 20, G Block Rd, G Block BKC, Bandra Kurla Complex, Bandra East",
73
+ address_2: "",
74
+ city: "Mumbai",
75
+ state: "Maharashtra",
76
+ country: "India",
77
+ pin_code: "400051",
78
+ pickup_location: "testing2"
79
+ })
80
+ ```
81
+
82
+ ## Development
83
+
84
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
85
+
86
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
87
+
88
+ ## Contributing
89
+
90
+ Bug reports and pull requests are welcome on GitHub at https://github.com/PostCo/shiprocket_api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/PostCo/shiprocket_api/blob/master/CODE_OF_CONDUCT.md).
91
+
92
+ ## License
93
+
94
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
95
+
96
+ ## Code of Conduct
97
+
98
+ Everyone interacting in the ShiprocketAPI project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/PostCo/shiprocket_api/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ require "bundler/setup"
3
+ require "dotenv/load"
4
+ require "dev/zeitwerk_loader"
5
+ require "dev/config"
6
+ require "shiprocket_api"
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ set_config
11
+
12
+ # (If you use this, don't forget to add pry to your Gemfile!)
13
+ require "pry"
14
+ require "pry-byebug"
15
+ Pry.start
16
+
17
+ # require "irb"
18
+ # IRB.start(__FILE__)
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
9
+ filename=".env"
10
+ if [ ! -f $filename ]; then
11
+ touch $filename
12
+ echo "SHIPROCKET_API_USERNAME=" >>$filename
13
+ echo "SHIPROCKET_API_PASSWORD=" >>$filename
14
+ fi
15
+
16
+ filename=".pryrc"
17
+ if [ ! -f $filename ]; then
18
+ touch $filename
19
+ echo "
20
+ Pry.commands.alias_command 'c', 'continue'
21
+ Pry.commands.alias_command 's', 'step'
22
+ Pry.commands.alias_command 'n', 'next'
23
+ Pry.commands.alias_command 'f', 'finish'
24
+ " >>$filename
25
+ fi
@@ -0,0 +1,8 @@
1
+ require "dotenv/load"
2
+
3
+ def set_config
4
+ ShiprocketAPI.configure do |config|
5
+ config.email = ENV["SHIPROCKET_API_USERNAME"]
6
+ config.password = ENV["SHIPROCKET_API_PASSWORD"]
7
+ end
8
+ end
@@ -0,0 +1,21 @@
1
+ require "zeitwerk"
2
+ require_relative "config"
3
+
4
+ loader = Zeitwerk::Loader.for_gem
5
+ loader.inflector.inflect(
6
+ "shiprocket_api" => "ShiprocketAPI"
7
+ )
8
+ loader.push_dir("./lib")
9
+ loader.collapse("./lib/shiprocket_api/resources")
10
+ loader.ignore("#{__dir__}/config.rb")
11
+ loader.enable_reloading
12
+ # loader.log!
13
+ loader.setup
14
+
15
+ $__shiprocket_api_loader__ = loader
16
+
17
+ def reload!
18
+ $__shiprocket_api_loader__.reload
19
+ set_config
20
+ true
21
+ end
@@ -0,0 +1,18 @@
1
+ require "shiprocket_api/version"
2
+ require "active_resource"
3
+ require 'http'
4
+
5
+ module ShiprocketAPI
6
+
7
+ require 'shiprocket_api/configuration'
8
+ require 'shiprocket_api/connection'
9
+
10
+ require 'shiprocket_api/resources/base'
11
+ require 'shiprocket_api/resources/session'
12
+ require 'shiprocket_api/resources/order_item'
13
+ require 'shiprocket_api/resources/custom_order'
14
+ require 'shiprocket_api/resources/forward_shipment'
15
+ require 'shiprocket_api/resources/pickup_location'
16
+ require 'shiprocket_api/resources/channel'
17
+ require 'shiprocket_api/resources/courier_serviceability'
18
+ end
@@ -0,0 +1,17 @@
1
+ module ShiprocketAPI
2
+ class Configuration
3
+ attr_accessor :email, :password
4
+ end
5
+
6
+ def self.config
7
+ @config ||= Configuration.new
8
+ end
9
+
10
+ def self.config=(config)
11
+ @config = config
12
+ end
13
+
14
+ def self.configure
15
+ yield config
16
+ end
17
+ end
@@ -0,0 +1,34 @@
1
+ module ShiprocketAPI
2
+ class Connection < ActiveResource::Connection
3
+
4
+ # override #get to handle get with body
5
+ def get(path, headers = {}, body: nil)
6
+ 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
11
+ with_auth { request(:get, *arguments) }
12
+ end
13
+
14
+ def request(method, path, *arguments)
15
+
16
+ result = ActiveSupport::Notifications.instrument("request.active_resource") do |payload|
17
+ payload[:method] = method
18
+ payload[:request_uri] = "#{site.scheme}://#{site.host}:#{site.port}#{path}"
19
+ 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
25
+ payload[:result]
26
+ end
27
+ handle_response(result)
28
+ rescue Timeout::Error => e
29
+ raise ActiveResource::TimeoutError.new(e.message)
30
+ rescue OpenSSL::SSL::SSLError => e
31
+ raise ActiveResource::SSLError.new(e.message)
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,32 @@
1
+ module ShiprocketAPI
2
+ class Base < ActiveResource::Base
3
+ cattr_accessor :session
4
+
5
+ self.connection_class = ShiprocketAPI::Connection
6
+ self.include_root_in_json = false
7
+ self.include_format_in_path = false
8
+ self.site = "https://apiv2.shiprocket.in"
9
+ self.connection.auth_type = :bearer
10
+ self.prefix = '/v1/external'
11
+ self.session = nil
12
+
13
+ class << self
14
+ def create_session(email: ShiprocketAPI.config.email, password: ShiprocketAPI.config.password)
15
+ self.session = Session.create(email: email, password: password)
16
+ self.connection.bearer_token = session.token
17
+ end
18
+
19
+ def clear_session
20
+ self.session = nil
21
+ self.connection.bearer_token = nil
22
+ end
23
+ end
24
+
25
+ def initialize(attributes = {}, persisted = false)
26
+ if defined?(self.class::DEFAULT_ATTRS)
27
+ attributes = self.class::DEFAULT_ATTRS.merge(attributes)
28
+ end
29
+ super
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,6 @@
1
+ module ShiprocketAPI
2
+ class Channel < Base
3
+ self.prefix += "/channels"
4
+ self.element_name = ""
5
+ end
6
+ end
@@ -0,0 +1,35 @@
1
+ module ShiprocketAPI
2
+ class CourierServiceability < Base
3
+ self.prefix += "/courier/serviceability"
4
+ self.element_name = ""
5
+
6
+ class Collection < ActiveResource::Collection
7
+ attr_accessor :is_recommendation_enabled,
8
+ :recommended_by,
9
+ :child_courier_id,
10
+ :recommended_courier_company_id,
11
+ :shiprocket_recommended_courier_id,
12
+ :elements
13
+
14
+ def initialize(parsed = {})
15
+ @is_recommendation_enabled = parsed["data"]["is_recommendation_enabled"]
16
+ @recommended_by = parsed["data"]["recommended_by"]
17
+ @child_courier_id = parsed["data"]["child_courier_id"]
18
+ @recommended_courier_company_id = parsed["data"]["recommended_courier_company_id"]
19
+ @shiprocket_recommended_courier_id = parsed["data"]["shiprocket_recommended_courier_id"]
20
+ @elements = parsed["data"]["available_courier_companies"]
21
+ end
22
+ end
23
+
24
+ self.collection_parser = Collection
25
+
26
+ def self.find_every(options)
27
+ instantiate_collection(format.decode(connection.get(collection_path, headers, body: options[:params]).body) || [], options[:params])
28
+ rescue ActiveResource::ResourceNotFound
29
+ # Swallowing ResourceNotFound exceptions and return nil - as per
30
+ # ActiveRecord.
31
+ nil
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,55 @@
1
+ module ShiprocketAPI
2
+ class CustomOrder < Base
3
+ self.prefix += "/orders/create/adhoc"
4
+ self.element_name = ""
5
+
6
+ has_many :order_items, class_name: "ShiprocketAPI::OrderItem"
7
+
8
+ DEFAULT_ATTRS = {
9
+ order_id: "1235",
10
+ order_date: Date.today.strftime("%Y-%m-%d"),
11
+ pickup_location: "test1",
12
+ channel_id: "",
13
+ comment: "",
14
+ reseller_name: "",
15
+ company_name: "",
16
+ billing_customer_name: "Andy Chong",
17
+ billing_last_name: "",
18
+ billing_address: "Salarpuria Symbiosis, Arekere Village, Begur, Bannerghatta Main Rd, Uttarahalli Hobli",
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,
26
+ billing_alternate_phone: "",
27
+ 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: 1000,
45
+ length: 0.5,
46
+ breadth: 0.5,
47
+ height: 0.5,
48
+ weight: 0.5,
49
+ ewaybill_no: "",
50
+ customer_gstin: ""
51
+ }
52
+
53
+
54
+ end
55
+ end
@@ -0,0 +1,71 @@
1
+ module ShiprocketAPI
2
+ class ForwardShipment < Base
3
+ self.prefix += "/shipments/create/forward-shipment"
4
+ self.element_name = ""
5
+
6
+ DEFAULT_ATTRS = {
7
+ mode: "",
8
+ request_pickup: true,
9
+ print_label: true,
10
+ generate_manifest: "",
11
+ ewaybill_no: "",
12
+ courier_id: "",
13
+ reseller_name: "",
14
+ order_id: "",
15
+ isd_code: "",
16
+ billing_isd_code: "",
17
+ order_date: "",
18
+ channel_id: "",
19
+ company_name: "",
20
+ billing_customer_name: "",
21
+ billing_last_name: "",
22
+ billing_address: "",
23
+ billing_address_2: "",
24
+ billing_city: "",
25
+ billing_state: "",
26
+ billing_country: "",
27
+ billing_pincode: "",
28
+ billing_email: "",
29
+ billing_phone: "",
30
+ billing_alternate_phone: "",
31
+ shipping_is_billing: "",
32
+ shipping_customer_name: "",
33
+ shipping_last_name: "",
34
+ shipping_address: "",
35
+ shipping_address_2: "",
36
+ shipping_city: "",
37
+ shipping_state: "",
38
+ shipping_country: "",
39
+ shipping_pincode: "",
40
+ shipping_email: "",
41
+ shipping_phone: "",
42
+ order_items: [
43
+ ShiprocketAPI::OrderItem.new
44
+ ],
45
+ payment_method: "",
46
+ shipping_charges: "",
47
+ giftwrap_charges: "",
48
+ transaction_charges: "",
49
+ total_discount: "",
50
+ sub_total: "",
51
+ weight: "",
52
+ length: "",
53
+ breadth: "",
54
+ height: "",
55
+ pickup_location: "",
56
+ customer_gstin: "",
57
+ vendor_details: {
58
+ email: "",
59
+ phone: "",
60
+ name: "",
61
+ address: "",
62
+ address_2: "",
63
+ city: "",
64
+ state: "",
65
+ country: "",
66
+ pin_code: "",
67
+ pickup_location: ""
68
+ }
69
+ }
70
+ end
71
+ end
@@ -0,0 +1,13 @@
1
+ module ShiprocketAPI
2
+ class OrderItem < Base
3
+ DEFAULT_ATTRS = {
4
+ name: "",
5
+ sku: "",
6
+ units: 0,
7
+ selling_price: 0,
8
+ discount: "",
9
+ tax: "",
10
+ hsn: ""
11
+ }
12
+ end
13
+ end
@@ -0,0 +1,51 @@
1
+ module ShiprocketAPI
2
+ class PickupLocation < Base
3
+ self.prefix += "/settings/company/addpickup"
4
+ self.element_name = ""
5
+
6
+ class Collection < ActiveResource::Collection
7
+ def initialize(parsed = {})
8
+ @elements = parsed["shipping_address"]
9
+ end
10
+ end
11
+ self.collection_parser = Collection
12
+
13
+ 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: ""
24
+ }
25
+
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
33
+ end
34
+
35
+ def find_every(options)
36
+ set_prefix_to_list do
37
+ prefix_options, query_options = split_options(options[:params])
38
+ path = collection_path(prefix_options, query_options)
39
+ instantiate_collection((format.decode(connection.get(path, headers).body) || []), query_options, prefix_options)
40
+ rescue ActiveResource::ResourceNotFound
41
+ # Swallowing ResourceNotFound exceptions and return nil - as per
42
+ # ActiveRecord.
43
+ set_prefix_to_add
44
+ nil
45
+ end
46
+ end
47
+ end
48
+
49
+
50
+ end
51
+ end
@@ -0,0 +1,7 @@
1
+ module ShiprocketAPI
2
+ class Session < Base
3
+ self.prefix += "/auth/login"
4
+ self.element_name = ""
5
+
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module ShiprocketAPI
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,37 @@
1
+ require_relative 'lib/shiprocket_api/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "shiprocket_api"
5
+ spec.version = ShiprocketAPI::VERSION
6
+ spec.authors = ["Andy Chong"]
7
+ spec.email = ["andygg1996personal@gmail.com"]
8
+
9
+ spec.summary = "Ruby object based Sendle API wrapper."
10
+ spec.homepage = "https://github.com/PostCo/sendle_api"
11
+ spec.license = "MIT"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+
14
+ spec.metadata["allowed_push_host"] = "https://rubygems.org/"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://github.com/PostCo/shiprocket_api"
18
+ spec.metadata["changelog_uri"] = "https://github.com/PostCo/shiprocket_api/releases"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_dependency "activeresource", "~> 5.0"
30
+ spec.add_dependency "http"
31
+
32
+ spec.add_development_dependency "rspec", "~> 3.2"
33
+ spec.add_development_dependency "dotenv"
34
+ spec.add_development_dependency "pry-byebug"
35
+ spec.add_development_dependency "pry"
36
+ spec.add_development_dependency "guard-rspec"
37
+ end
metadata ADDED
@@ -0,0 +1,171 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shiprocket_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Andy Chong
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-10-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activeresource
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: http
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: dotenv
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: guard-rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description:
112
+ email:
113
+ - andygg1996personal@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".travis.yml"
121
+ - CODE_OF_CONDUCT.md
122
+ - Gemfile
123
+ - Gemfile.lock
124
+ - LICENSE.txt
125
+ - README.md
126
+ - Rakefile
127
+ - bin/console
128
+ - bin/setup
129
+ - lib/dev/config.rb
130
+ - lib/dev/zeitwerk_loader.rb
131
+ - lib/shiprocket_api.rb
132
+ - lib/shiprocket_api/configuration.rb
133
+ - lib/shiprocket_api/connection.rb
134
+ - lib/shiprocket_api/resources/base.rb
135
+ - lib/shiprocket_api/resources/channel.rb
136
+ - lib/shiprocket_api/resources/courier_serviceability.rb
137
+ - lib/shiprocket_api/resources/custom_order.rb
138
+ - lib/shiprocket_api/resources/forward_shipment.rb
139
+ - lib/shiprocket_api/resources/order_item.rb
140
+ - lib/shiprocket_api/resources/pickup_location.rb
141
+ - lib/shiprocket_api/resources/session.rb
142
+ - lib/shiprocket_api/version.rb
143
+ - shiprocket_api.gemspec
144
+ homepage: https://github.com/PostCo/sendle_api
145
+ licenses:
146
+ - MIT
147
+ metadata:
148
+ allowed_push_host: https://rubygems.org/
149
+ homepage_uri: https://github.com/PostCo/sendle_api
150
+ source_code_uri: https://github.com/PostCo/shiprocket_api
151
+ changelog_uri: https://github.com/PostCo/shiprocket_api/releases
152
+ post_install_message:
153
+ rdoc_options: []
154
+ require_paths:
155
+ - lib
156
+ required_ruby_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: 2.3.0
161
+ required_rubygems_version: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ requirements: []
167
+ rubygems_version: 3.0.3
168
+ signing_key:
169
+ specification_version: 4
170
+ summary: Ruby object based Sendle API wrapper.
171
+ test_files: []