iupick 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +29 -0
- data/README.md +145 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/iupick.rb +95 -0
- data/lib/iupick/shipment.rb +94 -0
- data/lib/iupick/version.rb +3 -0
- data/lib/iupick/waypoint.rb +49 -0
- metadata +13 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e65b0e7e4524d21a6542175eb7eeec47e8833ab
|
4
|
+
data.tar.gz: a8e4b556bd21e149d37982fadd908499f5ca55c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce2af8fb42811258c93636f5325201e1c3891dc6c9003b2276ef0174ea1172c61cc337c422f48a43eed1b847cbf5ef89a9205252e9aea162a8eff35e7eb14a2f
|
7
|
+
data.tar.gz: 669d22866cdc269d67b8578fb1fc5dc8ce7bc6e344ac428e6850f482f84b90aa24bd9f58d80e41e002f7d18a38e8f85dcf33a708cd3a069d46528b69ca7aa295
|
data/LICENSE
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
BSD 3-Clause License
|
2
|
+
|
3
|
+
Copyright (c) 2017, iupick
|
4
|
+
All rights reserved.
|
5
|
+
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
8
|
+
|
9
|
+
* Redistributions of source code must retain the above copyright notice, this
|
10
|
+
list of conditions and the following disclaimer.
|
11
|
+
|
12
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
13
|
+
this list of conditions and the following disclaimer in the documentation
|
14
|
+
and/or other materials provided with the distribution.
|
15
|
+
|
16
|
+
* Neither the name of the copyright holder nor the names of its
|
17
|
+
contributors may be used to endorse or promote products derived from
|
18
|
+
this software without specific prior written permission.
|
19
|
+
|
20
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
21
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
22
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
24
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
25
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
26
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
27
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
28
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
29
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
# Iupick
|
2
|
+
|
3
|
+
The iupick Ruby gem wraps the iupick API to facilitate access from applications written in ruby.
|
4
|
+
|
5
|
+
Keep in mind that this package requires iupick secret keys, contact
|
6
|
+
info@iupick.com for more information.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'iupick'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install iupick
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
Add your secret and public tokens as required.
|
27
|
+
|
28
|
+
Never expose your secret token.
|
29
|
+
|
30
|
+
Methods that require your secret_token should never be done from the front-end. Since this methods deal with sensitive information.
|
31
|
+
|
32
|
+
``` ruby
|
33
|
+
require 'iupick'
|
34
|
+
|
35
|
+
Iupick.secret_token = 'sk_sandbox_4bdcd3630417c5119029859c08a7b8d9d97dda79'
|
36
|
+
Iupick.public_token = '315cdf3ca4dd588ab8e6f7fa4b7aa433c641cadd'
|
37
|
+
Iupick.environment = 'sandbox'
|
38
|
+
```
|
39
|
+
|
40
|
+
## Waybills
|
41
|
+
|
42
|
+
The waybill generation occurs on three steps.
|
43
|
+
|
44
|
+
|
45
|
+
### Step 1.
|
46
|
+
|
47
|
+
Create a shipment on the iupick platform and receive a
|
48
|
+
shipment token.
|
49
|
+
|
50
|
+
``` ruby
|
51
|
+
shipment_token = Iupick::Shipment.create(length=8,width=8,height=8,weight=1.1)
|
52
|
+
```
|
53
|
+
|
54
|
+
### Step 2.
|
55
|
+
|
56
|
+
Fill the rest of the information required to generate a waybill,
|
57
|
+
and receive a confirmation token.
|
58
|
+
|
59
|
+
You can send a shipment either to an arbitrary direction or to one
|
60
|
+
of our waypoints; just replace the waypoint_id attribute for a recipient
|
61
|
+
address.
|
62
|
+
|
63
|
+
``` ruby
|
64
|
+
shipper_address = Iupick.create_address(
|
65
|
+
city='Querétaro',
|
66
|
+
line_one='Epigmenio Gonzáles 500',
|
67
|
+
postal_code=76130,
|
68
|
+
line_two='',
|
69
|
+
neighborhood='Momma'
|
70
|
+
)
|
71
|
+
|
72
|
+
shipper_contact = Iupick.create_person(
|
73
|
+
person_name='Tony Stark',
|
74
|
+
phone_number='555555555',
|
75
|
+
email_address='tony@fakemail.com',
|
76
|
+
title='CEO',
|
77
|
+
company_name='Stark Industries',
|
78
|
+
phone_extension='123'
|
79
|
+
)
|
80
|
+
|
81
|
+
|
82
|
+
recipient_contact = Iupick.create_person(
|
83
|
+
person_name='Steve Rogers',
|
84
|
+
phone_number='555555555',
|
85
|
+
email_address='steve@fakemail.com',
|
86
|
+
title='Agent',
|
87
|
+
company_name='SHIELD',
|
88
|
+
phone_extension='123'
|
89
|
+
)
|
90
|
+
|
91
|
+
confirmation_token = Iupick::Shipment.add_information(
|
92
|
+
shipment_token = shipment_token,
|
93
|
+
waypoint_id = 486,
|
94
|
+
shipper_address = shipper_address,
|
95
|
+
shipper_contact = shipper_contact,
|
96
|
+
recipient_contact = recipient_contact,
|
97
|
+
third_party_reference = 'I am a shipment'
|
98
|
+
)
|
99
|
+
```
|
100
|
+
|
101
|
+
### Step 3.
|
102
|
+
|
103
|
+
Generate your waybill with your confirmation token.
|
104
|
+
|
105
|
+
``` ruby
|
106
|
+
waybill_information = Iupick::Shipment.generate_waybill(
|
107
|
+
confirmation_token = confirmation_token
|
108
|
+
)
|
109
|
+
```
|
110
|
+
|
111
|
+
### Tracking your shipment
|
112
|
+
|
113
|
+
In order to track a shipment send the carrier and the tracking number.
|
114
|
+
|
115
|
+
``` ruby
|
116
|
+
tracking_info = Iupick::Shipment.track(
|
117
|
+
carrier = carrier, tracking_number = tracking_number
|
118
|
+
)
|
119
|
+
```
|
120
|
+
|
121
|
+
### Waypoints
|
122
|
+
|
123
|
+
The Waypoints resource allows you to interact with all the delivery points from
|
124
|
+
our network that are available to your account.
|
125
|
+
|
126
|
+
To pull the full information for a single waypoint. Use `getWaypointInformation`
|
127
|
+
It requires the waypoint unique id.
|
128
|
+
|
129
|
+
``` ruby
|
130
|
+
waypoint = Iupick::Waypoints.get_waypoint_information(waypoint_id = 20)
|
131
|
+
```
|
132
|
+
|
133
|
+
To get a list of all the coordinates of available waypoints, use
|
134
|
+
`getWaypointsLite`.
|
135
|
+
|
136
|
+
``` ruby
|
137
|
+
waypoints = Iupick::Waypoints.get_waypoints_lite()
|
138
|
+
```
|
139
|
+
|
140
|
+
You can get all the waypoints close to a Postal Code with
|
141
|
+
`getPostalCodeWaypoints`.
|
142
|
+
|
143
|
+
``` ruby
|
144
|
+
cp_waypoints = Iupick::Waypoints.get_postal_code_waypoints(postal_code = 95710)
|
145
|
+
```
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "iupick"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/iupick.rb
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
# Version
|
2
|
+
require_relative "iupick/version"
|
3
|
+
|
4
|
+
# Dependencies
|
5
|
+
require 'unirest'
|
6
|
+
require 'json'
|
7
|
+
|
8
|
+
# API resources
|
9
|
+
require_relative "iupick/shipment"
|
10
|
+
require_relative "iupick/waypoint"
|
11
|
+
|
12
|
+
module Iupick
|
13
|
+
|
14
|
+
class << self
|
15
|
+
|
16
|
+
attr_accessor :secret_token, :public_token, :environment
|
17
|
+
|
18
|
+
# Initializes the address dictionary with
|
19
|
+
# the values to be passed.
|
20
|
+
# This returns a dictionary for versatility.
|
21
|
+
def create_address(
|
22
|
+
city,
|
23
|
+
line_one,
|
24
|
+
postal_code,
|
25
|
+
line_two='',
|
26
|
+
neighborhood=''
|
27
|
+
)
|
28
|
+
|
29
|
+
return {
|
30
|
+
'city': city,
|
31
|
+
'line_one': line_one,
|
32
|
+
'line_two': line_two,
|
33
|
+
'neighborhood': neighborhood,
|
34
|
+
'postal_code': postal_code
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
# Initializes the an empty address
|
39
|
+
def empty_address()
|
40
|
+
return create_address(
|
41
|
+
city = 'Empty',
|
42
|
+
line_one = 'Empty',
|
43
|
+
postal_code = 'Empty',
|
44
|
+
line_two = 'Empty',
|
45
|
+
neighborhood = 'Empty'
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Initializes the person_object with
|
50
|
+
# the values to be passed.
|
51
|
+
# This returns a dictionary for versatility.
|
52
|
+
def create_person(
|
53
|
+
person_name,
|
54
|
+
phone_number,
|
55
|
+
email_address,
|
56
|
+
title = '',
|
57
|
+
company_name = '',
|
58
|
+
phone_extension = ''
|
59
|
+
)
|
60
|
+
|
61
|
+
return {
|
62
|
+
'person_name': person_name,
|
63
|
+
'phone_number': phone_number,
|
64
|
+
'email_address': email_address,
|
65
|
+
'title': title,
|
66
|
+
'company_name': company_name,
|
67
|
+
'phone_extension': phone_extension
|
68
|
+
}
|
69
|
+
end
|
70
|
+
|
71
|
+
# Gets the base url, to be used for the API service.
|
72
|
+
def get_base_url()
|
73
|
+
if environment == 'development'
|
74
|
+
return 'http://localhost:8000/api/'
|
75
|
+
elsif environment == 'sandbox'
|
76
|
+
return 'https://sandbox.iupick.com/api/'
|
77
|
+
elsif environment == 'production'
|
78
|
+
return 'https://iupick.com/api/'
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# Returns the proper header either public or secret.
|
83
|
+
def generate_headers(auth)
|
84
|
+
if auth == 'public'
|
85
|
+
keyword = 'Token '
|
86
|
+
token = public_token
|
87
|
+
elsif auth == 'secret'
|
88
|
+
keyword = 'Secret '
|
89
|
+
token = secret_token
|
90
|
+
end
|
91
|
+
return {'Authorization': keyword + token}
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
module Iupick
|
2
|
+
# This is the class object for the shipments.
|
3
|
+
class Shipment
|
4
|
+
|
5
|
+
# Allows you to generate a token for the new shipment.
|
6
|
+
# Needs weight
|
7
|
+
# Needs Dimensions
|
8
|
+
# Receive a shipment id.
|
9
|
+
def self.create(length, width, height, weight)
|
10
|
+
url = Iupick.get_base_url() + 'create-shipment-token/'
|
11
|
+
headers = Iupick.generate_headers(auth = 'secret')
|
12
|
+
payload = {
|
13
|
+
'length': length.to_i,
|
14
|
+
'width': width.to_i,
|
15
|
+
'height': height.to_i,
|
16
|
+
'weight': weight.to_i
|
17
|
+
}
|
18
|
+
|
19
|
+
response = Unirest.post url,
|
20
|
+
headers: headers,
|
21
|
+
parameters: payload.to_json
|
22
|
+
decoded_response = response.body['shipment_token']
|
23
|
+
end
|
24
|
+
|
25
|
+
# This method allows you to fill the information required
|
26
|
+
# for the package, and receive a confirmation_token in exchange.
|
27
|
+
def self.add_information(
|
28
|
+
shipment_token,
|
29
|
+
waypoint_id,
|
30
|
+
shipper_address,
|
31
|
+
shipper_contact,
|
32
|
+
recipient_contact,
|
33
|
+
third_party_reference,
|
34
|
+
recipient_address = Iupick.empty_address()
|
35
|
+
)
|
36
|
+
|
37
|
+
waypoint_id = waypoint_id ? waypoint_id : nil;
|
38
|
+
recipient_address = recipient_address ?
|
39
|
+
recipient_address :
|
40
|
+
Iupick.emptyAddress();
|
41
|
+
|
42
|
+
|
43
|
+
if waypoint_id or recipient_address != Iupick.empty_address()
|
44
|
+
url = Iupick.get_base_url() +
|
45
|
+
'fill-shipment-information/' + shipment_token + '/'
|
46
|
+
headers = Iupick.generate_headers(auth = 'public')
|
47
|
+
payload = {
|
48
|
+
'waypoint': waypoint_id,
|
49
|
+
'shipper_address': shipper_address,
|
50
|
+
'shipper_contact': shipper_contact,
|
51
|
+
'recipient_address': recipient_address,
|
52
|
+
'recipient_contact': recipient_contact,
|
53
|
+
'third_party_reference': third_party_reference
|
54
|
+
}
|
55
|
+
|
56
|
+
response = Unirest.post url,
|
57
|
+
headers: headers,
|
58
|
+
parameters: payload.to_json
|
59
|
+
decoded_response = response.body['confirmation_token']
|
60
|
+
return decoded_response
|
61
|
+
end
|
62
|
+
return false
|
63
|
+
end
|
64
|
+
|
65
|
+
# Generates a waybill, once the information has been
|
66
|
+
# properly filled for the shipment.
|
67
|
+
def self.generate_waybill(confirmation_token)
|
68
|
+
url = Iupick.get_base_url() + 'generate-waybill/' + confirmation_token + '/'
|
69
|
+
headers = Iupick.generate_headers(auth = 'secret')
|
70
|
+
|
71
|
+
response = Unirest.post url,
|
72
|
+
headers: headers
|
73
|
+
decoded_response = response.body.to_json
|
74
|
+
return decoded_response
|
75
|
+
end
|
76
|
+
|
77
|
+
# Allows you to track the status of a shipment, with the
|
78
|
+
# tracking number and carrier.
|
79
|
+
def self.track(carrier, tracking_number)
|
80
|
+
url = Iupick.get_base_url() + 'track-shipment/'
|
81
|
+
payload = {
|
82
|
+
'carrier': carrier,
|
83
|
+
'tracking_number': tracking_number
|
84
|
+
}
|
85
|
+
headers = Iupick.generate_headers(auth = 'public')
|
86
|
+
response = Unirest.get url,
|
87
|
+
headers: headers,
|
88
|
+
parameters: payload
|
89
|
+
decoded_response = response.body['Message']
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Iupick
|
2
|
+
# This is the class object for the waypoints.
|
3
|
+
class Waypoints
|
4
|
+
|
5
|
+
# This method pulls the complete information for a single waypoint.
|
6
|
+
def self.get_waypoint_information(waypoint_id)
|
7
|
+
if waypoint_id
|
8
|
+
url = Iupick.get_base_url() + 'waypoints/' + waypoint_id.to_s + '/'
|
9
|
+
headers = Iupick.generate_headers(auth = 'public')
|
10
|
+
|
11
|
+
response = Unirest.get url,
|
12
|
+
headers: headers
|
13
|
+
decoded_response = response.body
|
14
|
+
return decoded_response
|
15
|
+
else
|
16
|
+
return {
|
17
|
+
'error': 'No es posible obtener la informacion del punto ' + waypoint_id.to_s
|
18
|
+
}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# This method allows you to pull the basic information required to plot
|
23
|
+
# the waypoints in a map
|
24
|
+
def self.get_waypoints_lite()
|
25
|
+
url = Iupick.get_base_url() + 'waypoints/lite/'
|
26
|
+
headers = Iupick.generate_headers(auth = 'public')
|
27
|
+
|
28
|
+
response = Unirest.get url,
|
29
|
+
headers: headers
|
30
|
+
|
31
|
+
decoded_response = response.body
|
32
|
+
return decoded_response
|
33
|
+
end
|
34
|
+
|
35
|
+
# This method allows you to pull the full information for waypoints in a
|
36
|
+
# certain postal code
|
37
|
+
def self.get_postal_code_waypoints(postal_code)
|
38
|
+
url = Iupick.get_base_url() + 'waypoints/postal-ids/' + postal_code.to_s + '/'
|
39
|
+
headers = Iupick.generate_headers(auth='public')
|
40
|
+
|
41
|
+
response = Unirest.get url,
|
42
|
+
headers: headers
|
43
|
+
|
44
|
+
decoded_response = response.body
|
45
|
+
return decoded_response
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iupick
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Franco Valencia
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.
|
19
|
+
version: '1.15'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.
|
26
|
+
version: '1.15'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,7 +44,15 @@ email:
|
|
44
44
|
executables: []
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
47
|
-
files:
|
47
|
+
files:
|
48
|
+
- LICENSE
|
49
|
+
- README.md
|
50
|
+
- bin/console
|
51
|
+
- bin/setup
|
52
|
+
- lib/iupick.rb
|
53
|
+
- lib/iupick/shipment.rb
|
54
|
+
- lib/iupick/version.rb
|
55
|
+
- lib/iupick/waypoint.rb
|
48
56
|
homepage: https://github.com/iupickmx/iupick-ruby
|
49
57
|
licenses:
|
50
58
|
- MIT
|