cm_clickpost 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.
- checksums.yaml +7 -0
- data/README.md +43 -0
- data/lib/cm_clickpost/additional_info.rb +12 -0
- data/lib/cm_clickpost/api_version.rb +8 -0
- data/lib/cm_clickpost/base_payload.rb +23 -0
- data/lib/cm_clickpost/concerns/helpers.rb +13 -0
- data/lib/cm_clickpost/configuration.rb +11 -0
- data/lib/cm_clickpost/drop_address.rb +11 -0
- data/lib/cm_clickpost/gst_info.rb +12 -0
- data/lib/cm_clickpost/order.rb +12 -0
- data/lib/cm_clickpost/pickup_address.rb +14 -0
- data/lib/cm_clickpost/product_info.rb +8 -0
- data/lib/cm_clickpost/return_address.rb +8 -0
- data/lib/cm_clickpost/shipment.rb +78 -0
- data/lib/cm_clickpost/version.rb +5 -0
- data/lib/cm_clickpost.rb +57 -0
- metadata +62 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 77a7d42124bb9b21c709fe046cd0d033d412eee61eba14ae29f4e9cf31438ea4
|
4
|
+
data.tar.gz: 5623e7be27011aa6b34ab1da53ea3ee72c90893e741c92306a061a1574f9cb4e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f2e26ced3b18acce9fe80bb9a58e7495742314491feef492b88781005a2fe35729ecae3919d13f78f0c114ec4ecc5e2e25cad27c5330bd70d8fc38100ea784c8
|
7
|
+
data.tar.gz: 74aea3248db9b4e0b5223c642161d66018c6635270788b07ad6fb602f699e1566ef92037eb3f294fa17f8a2391f275141218eb646e3987d956fc01d5f14acdbe
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# CmClickpost
|
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/cm_clickpost`. 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 'cm_clickpost'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install cm_clickpost
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/cm_clickpost. 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/[USERNAME]/cm_clickpost/blob/master/CODE_OF_CONDUCT.md).
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
40
|
+
|
41
|
+
## Code of Conduct
|
42
|
+
|
43
|
+
Everyone interacting in the CmClickpost project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/cm_clickpost/blob/master/CODE_OF_CONDUCT.md).
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module CmClickpost
|
2
|
+
class AdditionalInfo < CmClickpost::BasePayload
|
3
|
+
@@attributes = [
|
4
|
+
:label, :awb_number, :delivery_type, :async,
|
5
|
+
:gst_number, :account_code, :order_date, :is_fragile,
|
6
|
+
:is_dangerous, :order_id
|
7
|
+
]
|
8
|
+
|
9
|
+
define_class_methods(@@attributes, @attributes)
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module CmClickpost
|
2
|
+
class BasePayload
|
3
|
+
|
4
|
+
|
5
|
+
def self.define_class_methods(fields, attributes)
|
6
|
+
fields.each do |field|
|
7
|
+
define_method(field) do
|
8
|
+
attributes[field]
|
9
|
+
end
|
10
|
+
|
11
|
+
define_method("#{field}=") do |value|
|
12
|
+
attributes[field] = value
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(attributes = {})
|
19
|
+
@attributes = attributes
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module CmClickpost
|
2
|
+
module Concerns
|
3
|
+
module Helpers
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
included do
|
6
|
+
def convert_to_json(data)
|
7
|
+
return data.as_json.map {|a| a['attributes'].with_indifferent_access } if data.instance_of? (Array)
|
8
|
+
data.as_json['attributes'].with_indifferent_access
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module CmClickpost
|
2
|
+
class DropAddress < CmClickpost::BasePayload
|
3
|
+
@@attributes = [
|
4
|
+
:drop_state, :drop_address, :drop_email,
|
5
|
+
:drop_pincode, :drop_city, :drop_phone, :drop_country, :drop_name
|
6
|
+
]
|
7
|
+
|
8
|
+
define_class_methods(@@attributes, @attributes)
|
9
|
+
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module CmClickpost
|
2
|
+
class GstInfo < CmClickpost::BasePayload
|
3
|
+
@@attributes = [
|
4
|
+
:seller_gstin, :taxable_value, :is_seller_registered_under_gst,
|
5
|
+
:place_of_supply, :hsn_code, :enterprise_gstin, :gst_total_tax,
|
6
|
+
:igst_amount, :cgst_amount, :consignee_gstin, :invoice_reference
|
7
|
+
]
|
8
|
+
|
9
|
+
define_class_methods(@@attributes, @attributes)
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module CmClickpost
|
2
|
+
class Order < CmClickpost::BasePayload
|
3
|
+
@@attributes = [
|
4
|
+
:height, :length, :breadth, :weight,
|
5
|
+
:cod_value, :courier_partner, :order_type, :invoice_value,
|
6
|
+
:invoice_number, :invoice_date, :reference_number
|
7
|
+
]
|
8
|
+
|
9
|
+
define_class_methods(@@attributes, @attributes)
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module CmClickpost
|
2
|
+
class PickupAddress < CmClickpost::BasePayload
|
3
|
+
@@attributes = [
|
4
|
+
:pickup_state, :pickup_address, :email,
|
5
|
+
:pickup_time, :pickup_pincode, :pickup_city, :tin,
|
6
|
+
:pickup_phone, :pickup_country, :pickup_name
|
7
|
+
]
|
8
|
+
|
9
|
+
|
10
|
+
define_class_methods(@@attributes, @attributes)
|
11
|
+
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module CmClickpost
|
2
|
+
class Shipment
|
3
|
+
attr_accessor :pickup_address, :drop_address, :order_details, :product_details, :products, :gst_info, :additional_info, :return_address
|
4
|
+
include CmClickpost::Concerns::Helpers
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@pickup_address = nil
|
8
|
+
@drop_address = nil
|
9
|
+
@order_details = nil
|
10
|
+
@product_details = nil
|
11
|
+
@products = []
|
12
|
+
@gst_info = nil
|
13
|
+
@additional_info = nil
|
14
|
+
@return_address = nil
|
15
|
+
end
|
16
|
+
|
17
|
+
def pickup_address(**args)
|
18
|
+
@pickup_address = CmClickpost::PickupAddress.new(args) if args.present?
|
19
|
+
@pickup_address
|
20
|
+
end
|
21
|
+
|
22
|
+
def drop_address(**args)
|
23
|
+
@drop_address = CmClickpost::DropAddress.new(args) if args.present?
|
24
|
+
@drop_address
|
25
|
+
end
|
26
|
+
|
27
|
+
def order_details(**args)
|
28
|
+
@order_details = CmClickpost::Order.new(args) if args.present?
|
29
|
+
@order_details
|
30
|
+
end
|
31
|
+
|
32
|
+
def product_details(**args)
|
33
|
+
if args.present?
|
34
|
+
@product_details = CmClickpost::ProductInfo.new(args)
|
35
|
+
@products << @product_details
|
36
|
+
return @product_details
|
37
|
+
end
|
38
|
+
@products
|
39
|
+
end
|
40
|
+
|
41
|
+
def gst_info(**args)
|
42
|
+
@gst_info = CmClickpost::GstInfo.new(args) if args.present?
|
43
|
+
@gst_info
|
44
|
+
end
|
45
|
+
|
46
|
+
def additional_info(**args)
|
47
|
+
@additional_info = CmClickpost::AdditionalInfo.new(args) if args.present?
|
48
|
+
@additional_info
|
49
|
+
end
|
50
|
+
|
51
|
+
def return_address(**args)
|
52
|
+
@return_address = CmClickpost::ReturnAddress.new(args) if args.present?
|
53
|
+
@return_address
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.track(waybill:, courier_partner_id:)
|
57
|
+
additional_params = "&waybill=#{waybill}&cp_id=#{courier_partner_id}"
|
58
|
+
CmClickpost.send_request(method: 'get', route_param: '/track-order/', api_version: ApiVersion::API_VERSIONS[:track_order], additional_params: additional_params)
|
59
|
+
end
|
60
|
+
|
61
|
+
def create_shipping_order
|
62
|
+
shipment_details = convert_to_json(@order_details)
|
63
|
+
shipment_details.store(:items, convert_to_json(@products))
|
64
|
+
|
65
|
+
additional = convert_to_json(@additional_info)
|
66
|
+
additional.store(:return_info, convert_to_json(@return_address))
|
67
|
+
|
68
|
+
request_payload = {
|
69
|
+
"pickup_info": convert_to_json(@pickup_address),
|
70
|
+
"drop_info": convert_to_json(@drop_address),
|
71
|
+
"shipment_details": shipment_details,
|
72
|
+
"gst_info": convert_to_json(@gst_info),
|
73
|
+
"additional": additional
|
74
|
+
}
|
75
|
+
CmClickpost.send_request(route_param: '/create-order/', api_version: ApiVersion::API_VERSIONS[:create_order], request_payload: request_payload)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
data/lib/cm_clickpost.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "cm_clickpost/base_payload"
|
4
|
+
require_relative "cm_clickpost/version"
|
5
|
+
require_relative 'cm_clickpost/configuration'
|
6
|
+
require_relative 'cm_clickpost/api_version'
|
7
|
+
require_relative 'cm_clickpost/concerns/helpers.rb'
|
8
|
+
require_relative 'cm_clickpost/pickup_address'
|
9
|
+
require_relative 'cm_clickpost/shipment'
|
10
|
+
require_relative "cm_clickpost/drop_address"
|
11
|
+
require_relative "cm_clickpost/order"
|
12
|
+
require_relative "cm_clickpost/product_info"
|
13
|
+
require_relative "cm_clickpost/gst_info"
|
14
|
+
require_relative "cm_clickpost/additional_info"
|
15
|
+
require_relative "cm_clickpost/return_address"
|
16
|
+
|
17
|
+
# Dir["../cm_clickpost/lib/cm_clickpost/concerns/*.rb"].each { |file| require file }
|
18
|
+
# Dir["../cm_clickpost/lib/cm_clickpost/*.rb"].each { |file| require file }
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
module CmClickpost
|
24
|
+
class << self
|
25
|
+
include CmClickpost::Concerns::Helpers
|
26
|
+
|
27
|
+
attr_accessor :configuration, :pickup_address
|
28
|
+
require 'net/http'
|
29
|
+
require 'uri'
|
30
|
+
require 'json'
|
31
|
+
|
32
|
+
BASE_URL = "https://www.clickpost.in/api/"
|
33
|
+
|
34
|
+
def setup(username, api_key, environment)
|
35
|
+
@configuration ||= Configuration.new(username, api_key, environment)
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
def send_request(method: 'post', route_param:, api_version: '', request_payload: '', additional_params: '')
|
40
|
+
query_params = "/?username=#{@configuration.username}&key=#{@configuration.api_key}"
|
41
|
+
uri = URI.parse(BASE_URL + api_version + route_param + query_params + additional_params)
|
42
|
+
headers = {'Content-Type': 'application/json' }
|
43
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
44
|
+
http.use_ssl = true
|
45
|
+
request = "Net::HTTP::#{method.classify}".constantize.new(uri.request_uri, headers)
|
46
|
+
request.body = request_payload.to_json
|
47
|
+
response = http.request(request)
|
48
|
+
result = JSON.parse(response.body)
|
49
|
+
if result['meta']['success'] == true
|
50
|
+
return result
|
51
|
+
else
|
52
|
+
raise Exception.new result['meta']['message']
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cm_clickpost
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jishnu De Sarkar
|
8
|
+
- Aditya Tiwari
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2022-06-07 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Clickpost wrapper
|
15
|
+
email:
|
16
|
+
- jishnu@commutatus.com
|
17
|
+
- taditya.tiwari007@gmail.com
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- README.md
|
23
|
+
- lib/cm_clickpost.rb
|
24
|
+
- lib/cm_clickpost/additional_info.rb
|
25
|
+
- lib/cm_clickpost/api_version.rb
|
26
|
+
- lib/cm_clickpost/base_payload.rb
|
27
|
+
- lib/cm_clickpost/concerns/helpers.rb
|
28
|
+
- lib/cm_clickpost/configuration.rb
|
29
|
+
- lib/cm_clickpost/drop_address.rb
|
30
|
+
- lib/cm_clickpost/gst_info.rb
|
31
|
+
- lib/cm_clickpost/order.rb
|
32
|
+
- lib/cm_clickpost/pickup_address.rb
|
33
|
+
- lib/cm_clickpost/product_info.rb
|
34
|
+
- lib/cm_clickpost/return_address.rb
|
35
|
+
- lib/cm_clickpost/shipment.rb
|
36
|
+
- lib/cm_clickpost/version.rb
|
37
|
+
homepage: https://github.com/commutatus/cm_clickpost
|
38
|
+
licenses:
|
39
|
+
- MIT
|
40
|
+
metadata:
|
41
|
+
homepage_uri: https://github.com/commutatus/cm_clickpost
|
42
|
+
source_code_uri: https://github.com/commutatus/cm_clickpost
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: 2.3.0
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
requirements: []
|
58
|
+
rubygems_version: 3.3.7
|
59
|
+
signing_key:
|
60
|
+
specification_version: 4
|
61
|
+
summary: Clickpost API integration
|
62
|
+
test_files: []
|