yakit 0.0.1 → 0.0.2

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
  SHA1:
3
- metadata.gz: 222bd98af7cb8685f0d4c9b614028340c35880d1
4
- data.tar.gz: c0dd79897fafc51b7ad40f3c45f58450661dea2f
3
+ metadata.gz: 6a1a7d66c55c01e29ce9f73fd2fe0759cb132c77
4
+ data.tar.gz: 5dabec29d5913ddf1b763eaf31252b8f8e6b46f8
5
5
  SHA512:
6
- metadata.gz: 5fcfe2df4c841f014cb306b090d00e62da1da5fdb6ce18c7f7fb3541fdf0dcd6e9c358e88be01a1420b4fd0ebc516a6b54b6faffa72e544857cc4ad69d49e125
7
- data.tar.gz: 5d33f2081a17bd31b1800c6983b924391f4c7cb50297748dfd039ded3894b4d54530eb92ab525bcb9e50ed6b7d36fec73e87ff7d110fa4d055b99461e13153e4
6
+ metadata.gz: 784255c02f0bc6f7275a82eceff164a7d91a81d8342f8a5ffcccb436cc88f4a57b193759a4c940c66cf386156a6d0612ed3cc9dbdcc41d5efd2ee2dc6576425f
7
+ data.tar.gz: 4d72423f4b4209d7908583efda779431c4c877a66ffadf30db42695434b18f2a4d84b467a479f89e0dd9039b500d5e2dc9f9f2e16fc9da1de4598a11e27219d2
@@ -1,5 +1,6 @@
1
1
  require "yakit/version"
2
2
  require "yakit/exception"
3
+ require "yakit/y_ship"
3
4
  require "yakit/y_rate"
4
5
  require "yakit/client"
5
6
 
@@ -2,6 +2,7 @@ module Yakit
2
2
 
3
3
  class Client
4
4
  include YRate
5
+ include YShip
5
6
 
6
7
  attr_reader :username
7
8
  attr_reader :password
@@ -18,8 +19,8 @@ module Yakit
18
19
  private
19
20
 
20
21
  def raise_response_exception(response,message)
21
- if e.response.code.present? && [400,403,404,500,503,599].include?(e.response.code)
22
- case e.response.code
22
+ if response.code.present? && [400,403,404,500,503,599].include?(response.code)
23
+ case response.code
23
24
  when 401
24
25
  raise Unauthorized.new(response), message
25
26
  when 400
@@ -42,5 +43,106 @@ module Yakit
42
43
  end
43
44
  end
44
45
 
46
+
47
+ def send_get_request(url)
48
+
49
+ begin
50
+ response = RestClient::Request.execute(
51
+ method: :get,
52
+ url: url,
53
+ user: @username,
54
+ password:@password,
55
+ headers: {:Version => 2, :content_type => 'application/json'}
56
+ )
57
+ response_data = JSON.parse(response.body)
58
+ return response_data
59
+
60
+ rescue RestClient::ExceptionWithResponse => e
61
+ raise StandardException.new if e.response.blank?
62
+
63
+ if e.response.code.present? && [401,400,403,404,500,503,599].include?(e.response.code)
64
+ raise_response_exception(e.response,e.message)
65
+ else
66
+ raise OtherException.new(e.response), e.message
67
+ end
68
+ end
69
+
70
+ end
71
+
72
+ def send_post_request(url,data={})
73
+
74
+ begin
75
+ response = RestClient::Request.execute(
76
+ method: :post,
77
+ url: url,
78
+ user: @username,
79
+ password:@password,
80
+ headers: {:Version => 2, :content_type => 'application/json'},
81
+ payload: data.to_json
82
+ )
83
+ response_data = JSON.parse(response.body)
84
+ return response_data
85
+
86
+ rescue RestClient::ExceptionWithResponse => e
87
+ raise StandardException.new if e.response.blank?
88
+
89
+ if e.response.code.present? && [401,400,403,404,500,503,599].include?(e.response.code)
90
+ raise_response_exception(e.response,e.message)
91
+ else
92
+ raise OtherException.new(e.response), e.message
93
+ end
94
+ end
95
+ end
96
+
97
+ def send_delete_request(url,data={})
98
+
99
+ begin
100
+ response = RestClient::Request.execute(
101
+ method: :delete,
102
+ url: url,
103
+ user: @username,
104
+ password:@password,
105
+ headers: {:Version => 2, :content_type => 'application/json'},
106
+ payload: data.to_json
107
+ )
108
+ response_data = JSON.parse(response.body)
109
+ return response_data
110
+
111
+ rescue RestClient::ExceptionWithResponse => e
112
+ raise StandardException.new if e.response.blank?
113
+
114
+ if e.response.code.present? && [401,400,403,404,500,503,599].include?(e.response.code)
115
+ raise_response_exception(e.response,e.message)
116
+ else
117
+ raise OtherException.new(e.response), e.message
118
+ end
119
+ end
120
+ end
121
+
122
+ def send_delete_request(url,data={})
123
+
124
+ begin
125
+ response = RestClient::Request.execute(
126
+ method: :put,
127
+ url: url,
128
+ user: @username,
129
+ password:@password,
130
+ headers: {:Version => 2, :content_type => 'application/json'},
131
+ payload: data.to_json
132
+ )
133
+ response_data = JSON.parse(response.body)
134
+ return response_data
135
+
136
+ rescue RestClient::ExceptionWithResponse => e
137
+ raise StandardException.new if e.response.blank?
138
+
139
+ if e.response.code.present? && [401,400,403,404,500,503,599].include?(e.response.code)
140
+ raise_response_exception(e.response,e.message)
141
+ else
142
+ raise OtherException.new(e.response), e.message
143
+ end
144
+ end
145
+ end
146
+
45
147
  end
46
148
  end
@@ -1,4 +1,4 @@
1
- module YakitSeller
1
+ module Yakit
2
2
 
3
3
  class StandardException < StandardError; end
4
4
  class Exception < StandardError
@@ -1,3 +1,3 @@
1
1
  module Yakit
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,123 @@
1
+ module Yakit
2
+ module YShip
3
+
4
+ def list_open_jobs
5
+ url = "#{@base_url}/api/yship/listOpenJobs"
6
+ send_get_request(url)
7
+ end
8
+
9
+ def get_job_detail(job_id)
10
+ url = "#{@base_url}/api/yship/jobDetail?jobId=#{job_id}"
11
+ send_get_request(url)
12
+ end
13
+
14
+ def get_quote_for_job(job_id)
15
+
16
+ url = "#{@base_url}/api/yship/quoteForJob?jobId=#{job_id}"
17
+ send_get_request(url)
18
+ end
19
+
20
+ def create_job
21
+ url = "#{@base_url}/api/yship/createJob"
22
+ send_post_request(url)
23
+ end
24
+
25
+ def close_job(job_id)
26
+ url = "#{@base_url}/api/yship/closeJob"
27
+ data = {"jobId" => job_id}
28
+ send_post_request(url,data)
29
+ end
30
+
31
+ def delete_job(job_id)
32
+ url = "#{@base_url}/api/yship/deleteJob"
33
+ data = {"jobId" => job_id}
34
+ send_delete_request(url,data)
35
+ end
36
+
37
+ def payment_for_job(data)
38
+ url = "#{@base_url}/api/yship/paymentForJob"
39
+ send_post_request(url,data)
40
+ end
41
+
42
+ def get_open_shipments
43
+ url = "#{@base_url}/api/yship/openShipments"
44
+ send_get_request(url)
45
+ end
46
+
47
+ def add_shipment(data)
48
+ url = "#{@base_url}/api/yship/addShipment"
49
+ send_post_request(url,data)
50
+ end
51
+
52
+ def update_shipment(data)
53
+ url = "#{@base_url}/api/yship/updateShipment"
54
+ send_post_request(url,data)
55
+ end
56
+
57
+ def get_shipment_details(shipment_id)
58
+ url = "#{@base_url}/api/yship/shipmentDetails?shipmentId=#{shipment_id}"
59
+ send_get_request(url)
60
+ end
61
+
62
+ def get_shipment_label(shipment_id,label_format="PDF")
63
+ url = "#{@base_url}/api/yship/shipmentLabel?shipmentId=#{shipment_id}&labelFormat=#{label_format}"
64
+ send_get_request(url)
65
+ end
66
+
67
+ def delete_shipment(shipment_id)
68
+ url = "#{@base_url}/api/yship/shipment"
69
+ data = {"shipmentId" => shipment_id}
70
+ send_delete_request(url,data)
71
+ end
72
+
73
+ def get_shipment_groups(job_id)
74
+ url = "#{@base_url}/api/yship/shipmentGroups?jobId=​#{job_id}"
75
+ send_get_request(url)
76
+ end
77
+
78
+ def create_container(job_id)
79
+ url = "#{@base_url}/api/yship/createContainer"
80
+ data = {"jobId" => job_id}
81
+ send_post_request(url,data)
82
+ end
83
+
84
+ def update_container(data)
85
+ url = "#{@base_url}/api/yship/updateContainer"
86
+ send_post_request(url,data)
87
+ end
88
+
89
+ def delete_container(container_id)
90
+ url = "#{@base_url}/api/yship/container"
91
+ data = {"containerId" => container_id}
92
+ send_delete_request(url,data)
93
+ end
94
+
95
+ def add_shipments_to_container(container_id,shipment_ids)
96
+ url = "#{@base_url}/api/yship/addShipmentsToContainer"
97
+ data = {"containerId" => container_id,"shipmentIds" => shipment_ids}
98
+ send_put_request(url,data)
99
+ end
100
+
101
+ def delete_shipments_from_container(container_id,shipment_ids)
102
+ url = "#{@base_url}/api/yship/deleteShipmentsFromContainer"
103
+ data = {"containerId" => container_id,"shipmentIds" => shipment_ids}
104
+ send_post_request(url,data)
105
+ end
106
+
107
+ def close_container(data)
108
+ url = "#{@base_url}/api/yship/closeContainer"
109
+ send_post_request(url,data)
110
+ end
111
+
112
+ def get_container_label(container_id,label_format="PDF")
113
+ url = "#{@base_url}/api/yship/containerLabel?containerId=#{container_id}&labelFormat=#{label_format}"
114
+ send_get_request(url)
115
+ end
116
+
117
+ def dispatch_job(job_id)
118
+ url = "#{@base_url}/api/yship/dispatchJob"
119
+ data = {"jobId" => job_id}
120
+ send_post_request(url,data)
121
+ end
122
+ end
123
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yakit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Atish Sahoo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-05-09 00:00:00.000000000 Z
11
+ date: 2017-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -89,6 +89,7 @@ files:
89
89
  - lib/yakit/exception.rb
90
90
  - lib/yakit/version.rb
91
91
  - lib/yakit/y_rate.rb
92
+ - lib/yakit/y_ship.rb
92
93
  - yakit.gemspec
93
94
  homepage: https://github.com/atish-sahoo/yakit
94
95
  licenses: