boxc-ruby 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/boxc.rb +340 -0
  3. metadata +44 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4f2daf8c7e29f3c2ac80ff339bf7c23da9564e73
4
+ data.tar.gz: b2b5aa24322258fbed1012e865718cd75bc61b7e
5
+ SHA512:
6
+ metadata.gz: dd1a160647be3659d2f7849ccb7bde613bb5377ea71c0e5be8b7245e9656248d97188feae83bbe6a338a48c6ce95d616dcfd71d3f72e2b588947b8458da1a701
7
+ data.tar.gz: bae8a78020164e9cc45c2a0a5793db5f7b90335cd192616f4c86bc11cf3228314335f0e0442e85505b679705d224df0b16e6a43564546d80155d21375f907841
@@ -0,0 +1,340 @@
1
+ require 'httparty'
2
+ require 'querystring'
3
+
4
+ class Boxc
5
+ # base url for all http requests
6
+ @@base_uri = 'https://api.boxc.com/v1'
7
+
8
+ # Initializer shortcut for testing
9
+ # I thought it was useful if you
10
+ # already have the access token
11
+ #
12
+ # @params token {string|number} (optional)
13
+
14
+ def initialize(token=nil)
15
+ @token = nil
16
+ end
17
+
18
+ # Sets access token as class variable
19
+ # essential for all requests
20
+
21
+ def setAccessToken(token)
22
+ @token = token
23
+ return 'Active Token: '+@token
24
+ end
25
+
26
+ # Get authorization URL
27
+ # @link https://api.boxc.com/v1/docs/oauth2#get
28
+ #
29
+ # @param {String} applicationID
30
+ # @param {String} returnURI
31
+ #
32
+ # @returns {String}
33
+
34
+ def getAuthorizationUrl(applicationID, returnURI)
35
+ query_string=QueryString.stringify({application_id: applicationID, return_uri: returnURI})
36
+ return @@base_uri+'/oauth/authorize?'+query_string
37
+ end
38
+
39
+ # Trying to create access token from nonce
40
+ # @link https://api.boxc.com/v1/docs/oauth2#post
41
+ #
42
+ # @param {String} applicationID
43
+ # @param {String} applicationSecret
44
+ # @param {String} nonce
45
+ #
46
+ # @returns {'access_token': {String}}
47
+ #
48
+ # nonce comes from the system with authorization redirect
49
+
50
+ def createAccessToken(applicationID, applicationSecret, nonce)
51
+ body={
52
+ "application_id": applicationID,
53
+ "application_secret": applicationSecret,
54
+ "nonce": nonce
55
+ }
56
+ return HTTParty.post(@@base_uri+'/oauth/access_token', :body => body.to_json)
57
+ end
58
+
59
+ # Retrieves a list of entry points
60
+ # @link https://api.boxc.com/v1/docs/entry-points#search
61
+ #
62
+ # @returns {[{address: string, country: string, city: string, id: string}, ... , ...]}
63
+ #
64
+ # also Retrieves an entry point
65
+ # @link https://api.boxc.com/v1/docs/entry-points#get
66
+ #
67
+ # @param {String} id
68
+ #
69
+ # @returns {address: string, country: string, city: string, id: string}
70
+
71
+ def getEntryPoints(id=false)
72
+ if !id
73
+ return HTTParty.get(@@base_uri+'/entry-points')
74
+ elsif id
75
+ return HTTParty.get(@@base_uri+'/entry-points/'+id)
76
+ end
77
+ end
78
+
79
+ # Estimate
80
+ # @link https://api.boxc.com/v1/docs/estimate#get
81
+ #
82
+ # @param {{country: string, entry_point: string, height: number, length: number, postal_code: string, weight: number, width: number}} args
83
+ # country The destined country in ISO 3166-1 alpha-2 format. Only US is accepted. Not required.
84
+ # entry_point The code for the drop off location. See Entry Points for a list of codes. Not required.
85
+ # height The height of the shipment in CM. Default is 1.
86
+ # length The length of the shipment in CM. Default is 15.
87
+ # postal_code The destined Postal Code or ZIP Code. Required for a more accurate estimate.
88
+ # weight The weight of the shipment in KG. Maximum: 11.363. Required
89
+ # width The width of the shipment in CM. Default is 10.
90
+ #
91
+ # @returns {currency: string, entry_point: string, oversize_fee: string, services: [{service: string, total_cost: string, transit_min: number, transit_max: number}], etc.}
92
+
93
+ def estimate(args)
94
+ query_string=QueryString.stringify(args)
95
+ return HTTParty.get(
96
+ @@base_uri+'/estimate?'+query_string,
97
+ :headers => {'Authorization' => 'Bearer '+@token}
98
+ )
99
+ end
100
+
101
+ # Retrieves a paginated list of invoices
102
+ # @link https://api.boxc.com/v1/docs/invoices#search
103
+ #
104
+ # @param {Object} args
105
+ # date_end The inclusive date to end the search in YYYY-MM-DD format. Default is "now".
106
+ # date_start The inclusive date to begin the search in YYYY-MM-DD format. Default is 1 year ago.
107
+ # limit The number of results to return. Max: 50. Default: 50.
108
+ # order The order of the results. Can be "asc" for ascending, or "desc" for descending. Default: desc.
109
+ # page The page number of the results. Default: 1.
110
+ #
111
+ # @returns {<Object>}
112
+
113
+ def getInvoices(args)
114
+ query_string=QueryString.stringify(args)
115
+ return HTTParty.get(@@base_uri+'/invoices?'+query_string, :headers => {'Authorization' => 'Bearer '+@token})
116
+ end
117
+
118
+ # Retrieves an invoice
119
+ # @link https://api.boxc.com/v1/docs/invoices#get
120
+ #
121
+ # @param {String} id
122
+ #
123
+ # @returns {<Object>}
124
+
125
+ def getInvoice(id)
126
+ return HTTParty.get(@@base_uri+'/invoice/'+id.to_s, :headers => {'Authorization' => 'Bearer '+@token})
127
+ end
128
+
129
+ # Retrieves a label
130
+ # @link https://api.boxc.com/v1/docs/labels#get
131
+ #
132
+ # @param {String|Number} id
133
+ #
134
+ # @returns {<Object>}
135
+
136
+ def getLabel(id)
137
+ return HTTParty.get(@@base_uri+'/labels/'+id.to_s, :headers => {'Authorization' => 'Bearer '+@token})
138
+ end
139
+
140
+ # Create Label
141
+ # @link https://api.boxc.com/v1/docs/labels#create
142
+ #
143
+ # @param label
144
+ #
145
+ # @returns {<Object>}
146
+
147
+ def createLabel(label)
148
+ return HTTParty.post(@@base_uri+'/labels', :body => {'label': label}.to_json, :headers => {'Authorization' => 'Bearer '+@token})
149
+ end
150
+
151
+ # Update label
152
+ # @link https://api.boxc.com/v1/docs/labels#update
153
+ #
154
+ # @param {String} id
155
+ # @param {Object} label
156
+ #
157
+ # @returns {<Object>}
158
+
159
+ def updateLabel(id, label)
160
+ return HTTParty.put(@@base_uri+'/labels/'+id.to_s, :body => label.to_json, :headers => {'Authorization' => 'Bearer '+@token})
161
+ end
162
+
163
+ # Cancels a label
164
+ # @link https://api.boxc.com/v1/docs/labels#cancel
165
+ #
166
+ # @param {String} id
167
+ #
168
+ # @returns {<Object>}
169
+
170
+ def cancelLabel(id)
171
+ return HTTParty.put(@@base_uri+'/labels/'+id.to_s+'/cancel', :headers => {'Authorization' => 'Bearer '+@token})
172
+ end
173
+
174
+ # Create manifest
175
+ # @link https://api.boxc.com/v1/docs/manifests#post
176
+ #
177
+ # @param {Object} manifest
178
+ #
179
+ # @returns {<Object>}
180
+
181
+ def createManifest(manifest)
182
+ return HTTParty.post(@@base_uri+'/manifests', :body => manifest.to_json, :headers => {'Authorization' => 'Bearer '+@token})
183
+ end
184
+
185
+ # Retrieve manifest
186
+ # @link https://api.boxc.com/v1/docs/manifests#get
187
+ #
188
+ # @param {string} id
189
+ #
190
+ # @returns {<Object>}
191
+
192
+ def getManifest(id)
193
+ return HTTParty.get(@@base_uri+'/manifests/'+id.to_s, :headers => {'Authorization' => 'Bearer '+@token})
194
+ end
195
+
196
+ # Get overpacks
197
+ # @link https://api.boxc.com/v1/docs/overpacks#search
198
+ #
199
+ # @param {Object} args
200
+ #
201
+ # @returns {<Object>}
202
+
203
+ def getOverpacks(args=nil)
204
+ if args == nil
205
+ return HTTParty.get(@@base_uri+'/overpacks', :headers => {'Authorization' => 'Bearer '+@token})
206
+ else
207
+ query_string=QueryString.stringify(args)
208
+ return HTTParty.get(@@base_uri+'/overpacks?'+query_string, :headers => {'Authorization' => 'Bearer '+@token})
209
+ end
210
+ end
211
+
212
+ # Retrieves an overpack
213
+ # @link https://api.boxc.com/v1/docs/overpacks#get
214
+ #
215
+ # @param {String} id
216
+ #
217
+ # @returns {<Object>}
218
+
219
+ def getOverpack(id)
220
+ return HTTParty.get(@@base_uri+'/overpacks/'+id.to_s, :headers => {'Authorization' => 'Bearer '+@token})
221
+ end
222
+
223
+ # Creates an overpack
224
+ # @link https://api.boxc.com/v1/docs/overpacks#create
225
+ #
226
+ # @param {Object} overpack
227
+ #
228
+ # @returns {<Object>}
229
+
230
+ def createOverpack(overpack)
231
+ return HTTParty.post(@@base_uri+'/overpacks', :body => overpack.to_json, :headers => {'Authorization' => 'Bearer '+@token})
232
+ end
233
+
234
+ # Updates an overpack
235
+ # @link https://api.boxc.com/v1/docs/overpacks#update
236
+ #
237
+ # @param {String} id
238
+ # @param {Object} overpack
239
+ #
240
+ # @returns {<Object>}
241
+
242
+ def updateOverpack(id, overpack)
243
+ return HTTParty.put(@@base_uri+'/overpacks/'+id.to_s, :body => overpack.to_json, :headers => {'Authorization' => 'Bearer '+@token})
244
+ end
245
+
246
+ # Deletes an overpack
247
+ # @link https://api.boxc.com/v1/docs/overpacks#delete
248
+ #
249
+ # @param {String} id
250
+ #
251
+ # @returns {<Object>}
252
+
253
+ def deleteOverpack(id)
254
+ return HTTParty.delete(@@base_uri+'/overpacks/'+id.to_s, :headers => {'Authorization' => 'Bearer '+@token})
255
+ end
256
+
257
+ # Retrieves a paginated list of shipments
258
+ # @link https://api.boxc.com/v1/docs/shipments#search
259
+ #
260
+ # @param {Object} args
261
+ #
262
+ # @returns {<Object>}
263
+
264
+ def getShipments(args=nil)
265
+ if args == nil
266
+ return HTTParty.get(@@base_uri+'/shipments', :headers => {'Authorization' => 'Bearer '+@token})
267
+ else
268
+ query_string=QueryString.stringify(args)
269
+ return HTTParty.get(@@base_uri+'/shipments?'+query_string, :headers => {'Authorization' => 'Bearer '+@token})
270
+ end
271
+ end
272
+
273
+ # Retrieves a shipment
274
+ # @link https://api.boxc.com/v1/docs/shipments#get
275
+ #
276
+ # @param {String} id
277
+ #
278
+ # @returns {Promise.<Object>}
279
+
280
+ def getShipment(id)
281
+ return HTTParty.get(@@base_uri+'/shipments/'+id.to_s, :headers => {'Authorization' => 'Bearer '+@token})
282
+ end
283
+
284
+ # Creates a shipment
285
+ # @link https://api.boxc.com/v1/docs/shipments#create
286
+ #
287
+ # @param {Object} shipment
288
+ #
289
+ # @returns {<Object>}
290
+
291
+ def createShipment(shipment)
292
+ return HTTParty.post(@@base_uri+'/shipments', :body => shipment.to_json, :headers => {'Authorization' => 'Bearer '+@token})
293
+ end
294
+
295
+ # Updates a shipment
296
+ # @link https://api.boxc.com/v1/docs/shipments#update
297
+ #
298
+ # @param {String} id
299
+ # @param {Object} shipment
300
+ #
301
+ # @returns {<Boolean>}
302
+
303
+ def updateShipment(id, shipment)
304
+ return HTTParty.put(@@base_uri+'/shipments/'+id.to_s, :body => shipment.to_json, :headers => {'Authorization' => 'Bearer '+@token})
305
+ end
306
+
307
+ # Deletes a shipment
308
+ # @link https://api.boxc.com/v1/docs/shipments#update
309
+ #
310
+ # @param {String} id
311
+ #
312
+ # @returns {<Boolean>}
313
+
314
+ def deleteShipment(id)
315
+ return HTTParty.delete(@@base_uri+'/shipments/'+id.to_s, :headers => {'Authorization' => 'Bearer '+@token})
316
+ end
317
+
318
+ # Retrieves this user
319
+ # @link https://api.boxc.com/v1/docs/users#get
320
+ #
321
+ # @returns {<Object>}
322
+
323
+ def getUser()
324
+ puts HTTParty.get(@@base_uri+'/users/me', :headers => {'Authorization' => 'Bearer '+@token})
325
+ end
326
+
327
+ # Updates this user
328
+ # @link https://api.boxc.com/v1/docs/users#update
329
+ #
330
+ # @param {Object} user
331
+ #
332
+ # @returns {<Object>}
333
+
334
+ def updateUser(user)
335
+ return HTTParty.put(@@base_uri+'/users/me', :body => user.to_json, :headers => {'Authorization' => 'Bearer '+@token})
336
+ end
337
+
338
+
339
+
340
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: boxc-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Alexander Schofield
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-04-19 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Gem to Interact with Boxc API
14
+ email: alex.schofield816@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/boxc.rb
20
+ homepage: http://rubygems.org/gems/boxc
21
+ licenses:
22
+ - GA
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.4.5.1
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: Third Party Boxc Ruby Gem
44
+ test_files: []