shipsurance 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,25 @@
1
+ config/credentials.example.yml
2
+ config/credentials.yml
3
+ init.rb
4
+ lib/extensions/hash.rb
5
+ lib/shipsurance/address.rb
6
+ lib/shipsurance/base.rb
7
+ lib/shipsurance/claim.rb
8
+ lib/shipsurance/person.rb
9
+ lib/shipsurance/record_shipment.rb
10
+ lib/shipsurance/response.rb
11
+ lib/shipsurance/shipsurance.rb
12
+ lib/shipsurance/validation.rb
13
+ lib/shipsurance/void_record_shipment.rb
14
+ lib/shipsurance.rb
15
+ Rakefile
16
+ README.rdoc
17
+ spec/lib/shipsurance/address_spec.rb
18
+ spec/lib/shipsurance/claim_spec.rb
19
+ spec/lib/shipsurance/person_spec.rb
20
+ spec/lib/shipsurance/record_shipment_spec.rb
21
+ spec/lib/shipsurance/validation_spec.rb
22
+ spec/lib/shipsurance/void_record_shipment_spec.rb
23
+ spec/spec.opts
24
+ spec/spec_helper.rb
25
+ Manifest
@@ -0,0 +1,22 @@
1
+ # Testing URL's
2
+
3
+ # Claim
4
+
5
+ # Test Url: http://dev.dsiins.com/dsiapp/api.net/dsi_claim.aspx
6
+ # Live Url: https://www.dsiins.com/api.net/dsi_claim.aspx
7
+
8
+ # Recorded Shipment
9
+
10
+ # Test Url: http://dev.dsiins.com/dsiapp/api.net/dsi_recordShipment.aspx
11
+ # Live Url: https://www.dsiins.com/api.net/dsi_recordShipment.aspx
12
+
13
+ # Validation API
14
+
15
+ # Test Url: http://dev.dsiins.com/dsiapp/api.net/dsi_Validation.aspx
16
+ # Live Url: https://www.dsiins.com/api.net/dsi_Validation.aspx
17
+
18
+ # Voided Recorded Shipments
19
+
20
+ # Test Url: http://dev.dsiins.com/dsiapp/api.net/dsi_voidRecordShipment.aspx
21
+ # Live Url: https://www.dsiins.com/api.net/dsi_voidRecordShipment.aspx
22
+
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('shipsurance', '0.1.0') do |p|
6
+ p.description = "Integration gem for the ShipSurance gem"
7
+ p.url = "http://www.ordercup.com"
8
+ p.author = "Tim Matheson"
9
+ p.email = "tim.matheson@ordercup.com"
10
+ p.ignore_pattern = ["tmp/*","script/*"]
11
+ p.development_dependencies = []
12
+ end
13
+
14
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
@@ -0,0 +1,13 @@
1
+ production:
2
+ username: ""
3
+ password: ""
4
+ ext_person_source_id: ""
5
+ ext_policy_id: ""
6
+ person_email: ""
7
+
8
+ development:
9
+ username: ""
10
+ password: ""
11
+ ext_person_source_id: ""
12
+ ext_policy_id: ""
13
+ person_email: ""
@@ -0,0 +1,21 @@
1
+ production:
2
+ username: "ordercup"
3
+ password: "ock88j67"
4
+ ext_policy_id: "311974"
5
+ ext_person_source_id: "38"
6
+ person_email: "aloke.nath@ordercup.com"
7
+
8
+ development:
9
+ username: "ordercup"
10
+ password: "ock88j67"
11
+ ext_policy_id: "311974"
12
+ ext_person_source_id: "38"
13
+ person_email: "aloke.nath@ordercup.com"
14
+
15
+ test:
16
+ username: "ordercup"
17
+ password: "ock88j67"
18
+ ext_policy_id: "311974"
19
+ ext_person_source_id: "38"
20
+ person_email: "aloke.nath@ordercup.com"
21
+
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'lib/shipsurance'
@@ -0,0 +1,22 @@
1
+ require 'cgi'
2
+
3
+ class Hash
4
+ def to_s
5
+ keys.each do |key|
6
+ self[parametize(key.to_s)] = CGI.escape(self[key].to_s)
7
+ delete(key)
8
+ end
9
+ self
10
+ end
11
+
12
+ def parametize(str)
13
+ if str.to_s == "ext_rs_void_reason_id"
14
+ "extRSVoidReasonId"
15
+ else
16
+ params = str.to_s.split("_")
17
+ params[0] + params[1..-1].map(&:titleize).join
18
+ end
19
+ end
20
+ end
21
+
22
+
@@ -0,0 +1,14 @@
1
+ RAILS_ENV = "development" #unless defined?(RAILS_ENV) #stub for dev
2
+ require 'rubygems'
3
+ require 'active_support'
4
+ require 'extensions/hash'
5
+ require 'shipsurance/shipsurance'
6
+ require 'shipsurance/base'
7
+ require 'shipsurance/claim'
8
+ require 'shipsurance/record_shipment'
9
+ require 'shipsurance/void_record_shipment'
10
+ require 'shipsurance/validation'
11
+ require 'shipsurance/person'
12
+ require 'shipsurance/address'
13
+ require 'shipsurance/response'
14
+
@@ -0,0 +1,14 @@
1
+ # Simple address object for API requests
2
+ module Shipsurance
3
+ class Address
4
+ attr_reader :attributes
5
+ attr_accessor :address_1, :address_2, :city, :state, :postal_code, :country
6
+
7
+ def initialize(attributes = {})
8
+ @attributes = attributes
9
+ attributes.map do |name, value|
10
+ instance_variable_set("@#{name.to_s}",value)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,107 @@
1
+ # Module for integrating with the Shipsurance API.
2
+ module Shipsurance
3
+ class Base
4
+ require 'net/http'
5
+ require 'yaml'
6
+ @@live_base_url = "https://www.dsiins.com/api.net"
7
+ @@test_base_url = "http://dev.dsiins.com/dsiapp/api.net"
8
+ @@errors = []
9
+
10
+ # Adds the request credentials to the request.
11
+ # This method should be called for every request that requires
12
+ # authentication to process the request.
13
+ def add_credentials(post = {})
14
+ post[:ext_person_source_id] = credentials[:ext_person_source_id]
15
+ post[:source_username] = credentials[:username]
16
+ post[:source_password] = credentials[:password]
17
+ post[:ext_policy_id] = credentials[:ext_policy_id]
18
+ post
19
+ end
20
+
21
+ # Adds a person to the request parameters
22
+ # Accepts a Shipsurance::Person object
23
+ def add_person(person, post = {})
24
+ post[:person_source_identifier] = person.source_identifier
25
+ post[:person_company] = person.company
26
+ post[:person_first_name] = person.first_name
27
+ post[:person_last_name] = person.last_name
28
+ post[:person_phone] = person.phone
29
+ post[:person_fax] = person.fax
30
+ post[:person_email] = person.email
31
+ post
32
+ end
33
+
34
+ # Adds the recorded shipment id to the parameters hash
35
+ def add_recorded_shipment_id(recorded_shipment_id, post = {})
36
+ post[:recorded_shipment_id] = recorded_shipment_id
37
+ post
38
+ end
39
+
40
+ # Commit the parameters to the API
41
+ # This processes the request, and returns the response
42
+ def commit(post)
43
+ add_credentials(post)
44
+ validate_request(post)
45
+ url = URI.parse(resource_url)
46
+ req = Net::HTTP::Post.new(url.path)
47
+ req.set_form_data(post.to_s)
48
+ res = Net::HTTP.new(url.host, url.port).start {|http| http.request(req) }
49
+ case res
50
+ when Net::HTTPSuccess#, Net::HTTPRedirection
51
+ Shipsurance::Response.new(res)
52
+ else
53
+ raise Shipsurance::RequestError, res.error!
54
+ end
55
+ end
56
+
57
+ # Used for debugging, alias to puts
58
+ def display(msg)
59
+ puts "=" * 15 + " REQUEST " + "=" * 15
60
+ puts msg
61
+ puts "=" * 15 + " EOF REQUEST " + "=" * 15
62
+ end
63
+
64
+ # Returns the correct url for the current resource
65
+ # Appends the correct path to the base_url
66
+ def resource_url
67
+ base_url + "/dsi_" + resource_name + ".aspx"
68
+ end
69
+
70
+ # Returns the resource name downcased as a string
71
+ def resource_name
72
+ resource_class.slice(0,1).downcase + resource_class.slice(1,resource_class.length)
73
+ end
74
+
75
+ # Returns the class name of the current class as a string
76
+ def resource_class
77
+ @resource_class ||= self.class.to_s.split(":").last
78
+ end
79
+
80
+ def base_url
81
+ return RAILS_ENV =~ /production/ ? @@live_base_url : @@test_base_url
82
+ end
83
+
84
+ # Returns an array of the required parameters for the current class.
85
+ def required
86
+ [:ext_person_source_id, :source_username, :source_password, :ext_policy_id]
87
+ end
88
+
89
+ private
90
+
91
+ def format_date(date, format = "%m/%d/%Y")
92
+ date.is_a?(Time) ? date.strftime(format) : date
93
+ end
94
+
95
+ def validate_request(post)
96
+ @@errors.clear
97
+ required.each do |key|
98
+ @@errors << "Missing required parameter #{key.to_s}" unless post.has_key?(key)
99
+ end
100
+ raise Shipsurance::RequestError, @@errors.join(", ") unless @@errors.empty?
101
+ end
102
+
103
+ def credentials
104
+ @credentials ||= YAML.load_file(File.dirname(__FILE__) + "/../../config/credentials.yml")[RAILS_ENV].symbolize_keys
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,132 @@
1
+ # FIELD REQUIRED VALUE MAX DESCRIPTION
2
+ # extPersonSourceId Required Varies by User The Source ID used to access the system
3
+ # sourceUsername Required Varies by User 50 The Username used to access the system
4
+ # sourcePassword Required Varies by User 50 The Password used to access the system
5
+ # extPolicyId Required String 10 DSI Policy Number
6
+ # personSourceIdentifier Required String 100 External Person identifier
7
+ # personCompany Optional String 150 Person Company name
8
+ # personFirstName Required String 50 Person First Name
9
+ # personLastName Required String 50 Person Last Name
10
+ # personPhone Optional String 50 Person Phone
11
+ # personFax Optional String 50 Person Fax
12
+ # personEmail Required String 50 Person Email
13
+ # recordedShipmentId Required String 36 DSI Recorded Shipment ID
14
+ # claimSourceIdentifier Optional String 50 External Transaction Identifier
15
+ # extCarrierId Required See Lookup Codes Carrier ID’s - Appendix 1
16
+ # carrierServiceName Optional Strinf 150 Carrier Service Name
17
+ # consigneeFullName Required String 100 Full Name of Consignee
18
+ # claimPaymentFullName Required String 15 Name to make the Claim Check Payable To
19
+ # claimPaymentAddress1 Required String 100 Claim Payment Address
20
+ # claimPaymentAddress2 Optional String 100 Claim Payment Address
21
+ # claimPaymentCity Required String 50 Claim Payment Address
22
+ # claimPaymentState Optional String 2 Claim Payment Address
23
+ # claimPaymentPostalCode Required String 100 Claim Payment Address
24
+ # claimPaymentCountry Required String 100 Claim Payment Address
25
+ # claimPaymentPhone Required String 100 Claim Payment Phone
26
+ # claimPaymentFax Optional String 50 Claim Payment Fax
27
+ # claimPaymentEmail Optional String 100 Claim Payment Email
28
+ # fileDate Required MM/DD/YYYY Date claim filed (Now)
29
+ # lossDiscoveredDate Required MM/DD/YYYY Date loss discovered
30
+ # extClaimTypeId Required 1 or 2 1 1 = Loss 2 = Damage
31
+ # claimDescription Required String 4000 Description of claim
32
+ # claimAmount Required Currency 8 Claim Amount (must be less than recorded shipment declared value)
33
+ # certifyCorrect Required 0 or 1 1 0 = No 1 = Yes (Must answer 1 to file)
34
+ module Shipsurance
35
+ class Claim < Base
36
+ def add_claim_source_identifier(claim_source_identifier, post = {})
37
+ post[:claim_source_identifier] = claim_source_identifier
38
+ post
39
+ end
40
+
41
+ def add_ext_carrier_id(id, post = {})
42
+ post[:ext_carrier_id] = id
43
+ post
44
+ end
45
+
46
+ def add_consignee_full_name(full_name, post = {})
47
+ post[:consignee_full_name] = full_name
48
+ post
49
+ end
50
+
51
+ def add_claim_payment_full_name(full_name, post = {})
52
+ post[:claim_payment_full_name] = full_name
53
+ post
54
+ end
55
+
56
+ def add_claim_payment_address(address, post = {})
57
+ add_claim_payment_address_1(address.address_1, post)
58
+ add_claim_payment_city(address.city, post)
59
+ add_claim_payment_postal_code(address.postal_code, post)
60
+ add_claim_payment_country(address.country, post)
61
+ post
62
+ end
63
+
64
+ def add_claim_payment_address_1(address_1, post = {})
65
+ post[:claim_payment_address_1] = address_1
66
+ post
67
+ end
68
+
69
+ def add_claim_payment_city(city, post = {})
70
+ post[:claim_payment_city] = city
71
+ post
72
+ end
73
+
74
+ def add_claim_payment_postal_code(postal_code, post = {})
75
+ post[:claim_payment_postal_code] = postal_code
76
+ post
77
+ end
78
+
79
+ def add_claim_payment_country(country, post = {})
80
+ post[:claim_payment_country] = country
81
+ post
82
+ end
83
+
84
+ def add_claim_payment_phone(phone, post = {})
85
+ post[:claim_payment_phone] = phone
86
+ post
87
+ end
88
+
89
+ def add_file_date(date, post = {})
90
+ post[:file_date] = date.strftime("%m/%d/%Y %H:%M %p")#format_date(date)
91
+ post
92
+ end
93
+
94
+ def add_loss_discovered_date(date, post = {})
95
+ post[:loss_discovered_date] = format_date(date)
96
+ post
97
+ end
98
+
99
+ def add_ext_claim_type_id(id, post = {})
100
+ post[:ext_claim_type_id] = id
101
+ post
102
+ end
103
+
104
+ def add_claim_description(description, post = {})
105
+ post[:claim_description] = description
106
+ post
107
+ end
108
+
109
+ def add_claim_amount(amount, post = {})
110
+ post[:claim_amount] = amount
111
+ post
112
+ end
113
+
114
+ def add_certify_correct(bool, post = {})
115
+ post[:certify_correct] = bool ? 1 : 0
116
+ end
117
+
118
+ def add_claim_shipment_date(date, post = {})
119
+ post[:claim_shipment_date] = format_date(date)
120
+ post
121
+ end
122
+
123
+ def required
124
+ super.push(:person_source_identifier, :person_first_name, :person_last_name,
125
+ :person_email, :recorded_shipment_id, :ext_carrier_id, :consignee_full_name,
126
+ :claim_payment_full_name, :claim_payment_address_1, :claim_payment_city,
127
+ :claim_payment_postal_code, :claim_payment_country, :claim_payment_phone, :file_date,
128
+ :loss_discovered_date, :ext_claim_type_id,:claim_description,:claim_amount, :certify_correct, :claim_shipment_date)
129
+ end
130
+ end
131
+ end
132
+
@@ -0,0 +1,14 @@
1
+ # Simple person object for API requests
2
+ module Shipsurance
3
+ class Person
4
+ attr_reader :attributes
5
+ attr_accessor :source_identifier, :company, :first_name, :last_name, :phone, :fax, :email
6
+
7
+ def initialize(attributes = {})
8
+ @attributes = attributes
9
+ attributes.map do |name, value|
10
+ instance_variable_set("@#{name.to_s}",value)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,216 @@
1
+ # FIELD REQUIRED VALUE MAX DESCRIPTION
2
+ # extPersonSourceId Required Varies by User The Source ID used to access the system
3
+ # sourceUsername Required Varies by User 50 The Username used to access the system
4
+ # sourcePassword Required Varies by User 50 The Password used to access the system
5
+ # extPolicyId Required String 10 Shipsurance Policy Number
6
+ # personSourceIdentifier Optional String 100 External Person identifier
7
+ # personCompany Optional String 150 Person Company name
8
+ # personFirstName Optional String 50 Person First Name
9
+ # personLastName Optional String 50 Person Last Name
10
+ # personPhone Optional String 50 Person Phone
11
+ # personFax Optional String 50 Person Fax
12
+ # personEmail Required String 50 Person Email
13
+ # recordSourceIdentifier Optional String 50 External Transaction Identifier
14
+ # extShipmentTypeId Required 1 or 2 1 1 = Parcel 2 = Cargo/Freight
15
+ # extCarrierId Required See Lookup Codes Carrier ID’s - Appendix 1
16
+ # carrierServiceName Required String 150 Class of shipping service
17
+ # referenceNumber Optional String 100 Reference Number
18
+ # trackingNumber Optional String 100 Tracking Number
19
+ # declaredValue Required Currency 8 Declared Value of the recorded shipment
20
+ # transactionDate Optional MM/DD/YYYY Date of Transaction - REMOVED
21
+ # shipmentDate Required MM/DD/YYYY Date of Shipment
22
+ # arrivalDate Optional MM/DD/YYYY Date of Shipment Arrival
23
+ # extCommodityCategoryId Optional See Lookup Codes Commodity Category - Appendix 1
24
+ # extCommodityTypeId Optional See Lookup Codes Commodity Type - Appendix 1
25
+ # extPackageTypeId Optional See Lookup Codes Package Type - Appendix 1
26
+ # packageCount Optional String 100 Number of packages
27
+ # containsGlass Optional 0 or 1 1 0 = No 1 = Yes
28
+ # packageDescription Required String 4000 Contents of shipment
29
+ # departureAddress1 Optional String 100 Parcel Departure Address
30
+ # departureAddress2 Optional String 100 Parcel Departure Address
31
+ # departureCity Optional String 50 Parcel Departure Address
32
+ # departureState Optional String 2 Parcel Departure Address
33
+ # departurePostalCode Optional String 100 Parcel Departure Address
34
+ # departureCountry Optional String 100 Parcel Departure Address
35
+ # consigneeFirstName Optional String 50 Recipient First Name- REMOVED
36
+ # consigneeLastName Optional String 50 Recipient Last Name- REMOVED
37
+ # consigneeFullName Optional String 150 Recipient Full Name
38
+ # destinationAddress1 Optional String 100 Parcel Destination Address
39
+ # destinationAddress2 Optional String 100 Parcel Destination Address
40
+ # destinationCity Optional String 50 Parcel Destination Address
41
+ # destinationState Optional String 2 Parcel Destination Address
42
+ # destinationPostalCode Optional String 100 Parcel Destination Address
43
+ # destinationCountry Optional String 100 Parcel Destination Address
44
+ # insuredCompany Optional String 150 Insured’s Company Name
45
+ module Shipsurance
46
+ class RecordShipment < Base
47
+ def add_tracking_number(number, post = {})
48
+ post[:tracking_number] = number
49
+ post
50
+ end
51
+
52
+ def add_reference_number(number, post = {})
53
+ post[:reference_number] = number
54
+ post
55
+ end
56
+
57
+ def add_carrier(id, service_name, post = {})
58
+ post[:ext_carrier_id] = id
59
+ post[:carrier_name] = service_name
60
+ post
61
+ end
62
+
63
+ def add_ext_shipment_type_id(ext_shipment_type_id, post = {})
64
+ post[:ext_shipment_type_id] = ext_shipment_type_id
65
+ post
66
+ end
67
+
68
+ def add_record_source_identifier(record_source_identifier, post = {})
69
+ post[:record_source_identifier] = record_source_identifier
70
+ post
71
+ end
72
+
73
+ def add_shipment_date(date, post = {})
74
+ post[:shipment_date] = format_date(date)
75
+ post
76
+ end
77
+
78
+ def add_arrival_date(date, post = {})
79
+ post[:arrival_date] = format_date(date)
80
+ post
81
+ end
82
+
83
+ def add_ext_commodity_category_id(category_id, post = {})
84
+ post[:ext_commodity_category_id] = category_id
85
+ post
86
+ end
87
+
88
+ def add_ext_package_type_id(ext_package_type_id, post = {})
89
+ post[:ext_package_type_id] = ext_package_type_id
90
+ post
91
+ end
92
+
93
+ def add_package_count(package_count, post = {})
94
+ post[:package_count] = package_count
95
+ post
96
+ end
97
+
98
+ # optional 0 = No, 1 = Yes
99
+ def add_contains_glass(contains_glass, post = {})
100
+ post[:contains_glass] = contains_glass
101
+ post
102
+ end
103
+
104
+ def add_package_description(package_description, post = {})
105
+ post[:package_description] = package_description
106
+ post
107
+ end
108
+
109
+ # Accepts a Shipsurance address object
110
+ # Adds the departure address to the request
111
+ def add_departure_address(address, post = {})
112
+ add_departure_address_1(address.address_1, post)
113
+ add_departure_address_2(address.address_2, post) if address.address_2
114
+ add_departure_city(address.city, post)
115
+ add_departure_state(address.state, post)
116
+ add_departure_postal_code(address.postal_code, post)
117
+ add_departure_country(address.country, post)
118
+ end
119
+
120
+ def add_departure_address_1(departure_address_1, post = {})
121
+ puts "Invoked #{add_departure_address_1}"
122
+ post[:departure_address_1] = departure_address_1
123
+ post
124
+ end
125
+
126
+ def add_departure_address_2(departure_address_2, post = {})
127
+ post[:departure_address_2] = departure_address_2
128
+ post
129
+ end
130
+
131
+ def add_departure_city(departure_city, post = {})
132
+ post[:departure_city] = departure_city
133
+ post
134
+ end
135
+
136
+ def add_departure_state(departure_state, post = {})
137
+ post[:departure_state] = departure_state
138
+ post
139
+ end
140
+
141
+ def add_departure_postal_code(departure_postal_code, post = {})
142
+ post[:departure_postal_code] = departure_postal_code
143
+ post
144
+ end
145
+
146
+ def add_departure_country(departure_country, post = {})
147
+ post[:departure_country] = departure_country
148
+ post
149
+ end
150
+
151
+ def add_consignee_first_name(consignee_first_name, post = {})
152
+ post[:consignee_first_name] = consignee_first_name
153
+ post
154
+ end
155
+
156
+ def add_consignee_last_name(consignee_last_name, post = {})
157
+ post[:consignee_last_name] = consignee_last_name
158
+ post
159
+ end
160
+
161
+ def add_consignee_full_name(consignee_full_name ,post = {})
162
+ post[:consignee_full_name] = consignee_full_name
163
+ post
164
+ end
165
+
166
+ # Accepts a Shipsurance address object
167
+ # Adds the destination address to the request
168
+ def add_destination_address(address, post = {})
169
+ add_destination_address_1(address.address_1, post)
170
+ add_destination_address_2(address.address_2, post) if address.address_2
171
+ add_destination_city(address.city, post)
172
+ add_destination_state(address.state, post)
173
+ add_destination_postal_code(address.postal_code, post)
174
+ add_destination_country(address.country, post)
175
+ end
176
+
177
+ def add_destination_address_1(destination_address_1, post = {})
178
+ post[:destination_address_1] = destination_address_1
179
+ post
180
+ end
181
+
182
+ def add_destination_address_2(destination_address_2, post = {})
183
+ post[:destination_address_2] = destination_address_2
184
+ post
185
+ end
186
+
187
+ def add_destination_city(destination_city, post = {})
188
+ post[:destination_city] = destination_city
189
+ post
190
+ end
191
+
192
+ def add_destination_state(destination_state, post = {})
193
+ post[:destination_state] = destination_state
194
+ post
195
+ end
196
+
197
+ def add_destination_postal_code(destination_postal_code, post = {})
198
+ post[:destination_postal_code] = destination_postal_code
199
+ post
200
+ end
201
+
202
+ def add_destination_country(destination_country, post = {})
203
+ post[:destination_country] = destination_country
204
+ post
205
+ end
206
+
207
+ def add_insured_company(insured_company, post = {})
208
+ post[:insured_company] = insured_company
209
+ post
210
+ end
211
+
212
+ def required
213
+ super.push(:ext_shipment_type_id, :ext_carrier_id, :carrier_service_name, :declared_value, :shipment_date, :person_email, :package_description)
214
+ end
215
+ end
216
+ end
@@ -0,0 +1,16 @@
1
+ module Shipsurance
2
+ class Response
3
+ attr_reader :code, :body, :api_response_code, :success, :recorded_shipment_id
4
+
5
+ def initialize(response)
6
+ response_arry = response.body.split(",")
7
+ @code, @api_response_code, @body, @recorded_shipment_id = response.code.to_i, response_arry[0].to_i, response_arry[1], response_arry[2]
8
+ @success = (@response_code == 1)
9
+ self
10
+ end
11
+
12
+ def parse(response)
13
+ response.body.split(",")
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module Shipsurance
2
+ class RequestError < StandardError; end;
3
+ end
@@ -0,0 +1,7 @@
1
+ module Shipsurance
2
+ class Validation < Base
3
+ def required
4
+ super.push(:validation_type)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Shipsurance
2
+ class VoidRecordShipment < Base
3
+ def required
4
+ super.push(:person_email,:recorded_shipment_id,:ext_rs_void_reason_id)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{shipsurance}
5
+ s.version = "0.1.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Tim Matheson"]
9
+ s.date = %q{2009-11-28}
10
+ s.description = %q{Integration gem for the ShipSurance gem}
11
+ s.email = %q{tim.matheson@ordercup.com}
12
+ s.extra_rdoc_files = ["lib/extensions/hash.rb", "lib/shipsurance/address.rb", "lib/shipsurance/base.rb", "lib/shipsurance/claim.rb", "lib/shipsurance/person.rb", "lib/shipsurance/record_shipment.rb", "lib/shipsurance/response.rb", "lib/shipsurance/shipsurance.rb", "lib/shipsurance/validation.rb", "lib/shipsurance/void_record_shipment.rb", "lib/shipsurance.rb", "README.rdoc"]
13
+ s.files = ["config/credentials.example.yml", "config/credentials.yml", "init.rb", "lib/extensions/hash.rb", "lib/shipsurance/address.rb", "lib/shipsurance/base.rb", "lib/shipsurance/claim.rb", "lib/shipsurance/person.rb", "lib/shipsurance/record_shipment.rb", "lib/shipsurance/response.rb", "lib/shipsurance/shipsurance.rb", "lib/shipsurance/validation.rb", "lib/shipsurance/void_record_shipment.rb", "lib/shipsurance.rb", "Rakefile", "README.rdoc", "spec/lib/shipsurance/address_spec.rb", "spec/lib/shipsurance/claim_spec.rb", "spec/lib/shipsurance/person_spec.rb", "spec/lib/shipsurance/record_shipment_spec.rb", "spec/lib/shipsurance/validation_spec.rb", "spec/lib/shipsurance/void_record_shipment_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "Manifest", "shipsurance.gemspec"]
14
+ s.has_rdoc = true
15
+ s.homepage = %q{http://www.ordercup.com}
16
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Shipsurance", "--main", "README.rdoc"]
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = %q{shipsurance}
19
+ s.rubygems_version = %q{1.3.2}
20
+ s.summary = %q{Integration gem for the ShipSurance gem}
21
+
22
+ if s.respond_to? :specification_version then
23
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
+ s.specification_version = 3
25
+
26
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
+ else
28
+ end
29
+ else
30
+ end
31
+ end
@@ -0,0 +1,52 @@
1
+ require File.dirname(__FILE__) + "/../../spec_helper"
2
+
3
+ describe Shipsurance::Address do
4
+ it "should accept all valid address attributes" do
5
+ address = Shipsurance::Address.new(valid_address_attributes)
6
+ address.attributes.should == valid_address_attributes
7
+ end
8
+
9
+ it "should mass assign the address_1 attribute" do
10
+ address = Shipsurance::Address.new(valid_address_attributes)
11
+ address.attributes[:address_1].should == valid_address_attributes[:address_1]
12
+ end
13
+
14
+ it "should mass assign the address_2 attribute" do
15
+ address = Shipsurance::Address.new(valid_address_attributes)
16
+ address.attributes[:address_2].should == valid_address_attributes[:address_2]
17
+ end
18
+
19
+ it "should mass assign the city attribute" do
20
+ address = Shipsurance::Address.new(valid_address_attributes)
21
+ address.attributes[:city].should == valid_address_attributes[:city]
22
+ end
23
+
24
+ it "should mass assign the country attribute" do
25
+ address = Shipsurance::Address.new(valid_address_attributes)
26
+ address.attributes[:country].should == valid_address_attributes[:country]
27
+ end
28
+
29
+ it "should mass assign the postal_code attribute" do
30
+ address = Shipsurance::Address.new(valid_address_attributes)
31
+ address.attributes[:postal_code].should == valid_address_attributes[:postal_code]
32
+ end
33
+
34
+ it "should mass assign the country attribute" do
35
+ address = Shipsurance::Address.new(valid_address_attributes)
36
+ address.attributes[:country].should == valid_address_attributes[:country]
37
+ end
38
+
39
+
40
+ private
41
+
42
+ def valid_address_attributes
43
+ {
44
+ :address_1 => "123 East St.",
45
+ :address_2 => "APT #3",
46
+ :city => "Rancho Santa Margarita",
47
+ :state => "CA",
48
+ :postal_code => 92688,
49
+ :country => "US"
50
+ }
51
+ end
52
+ end
@@ -0,0 +1,71 @@
1
+ require File.dirname(__FILE__) + "/../../spec_helper"
2
+
3
+ describe Shipsurance::Claim do
4
+ before(:each) do
5
+ @claim = Shipsurance::Claim.new
6
+ @address = Shipsurance::Address.new(address_attributes)
7
+ @shipment_id = Shipsurance::RecordShipment.new.commit(valid_record_shipment_params).recorded_shipment_id
8
+ end
9
+
10
+ context " a valid request" do
11
+ # TODO, there is some issue with this call
12
+ # It complains about fileDate not being set as DateTime but
13
+ # the API specifies it should be mm/dd/yyyy format.
14
+ # it "should return success" do
15
+ # post = @claim.add_person(person)
16
+ # @claim.add_recorded_shipment_id(@shipment_id,post)
17
+ # @claim.add_ext_carrier_id(1,post)
18
+ # @claim.add_consignee_full_name("Tim Matheson", post)
19
+ # @claim.add_claim_payment_full_name("Tim Matheson", post)
20
+ # @claim.add_claim_payment_address(@address, post)
21
+ # @claim.add_claim_payment_phone("9495551212", post)
22
+ # @claim.add_file_date(Time.now, post)
23
+ # @claim.add_loss_discovered_date(Time.now, post)
24
+ # @claim.add_claim_shipment_date(Time.now, post)
25
+ # @claim.add_ext_claim_type_id(1, post)
26
+ # @claim.add_claim_description("Test #{rand(9999)}", post)
27
+ # @claim.add_claim_amount(5.00, post)
28
+ # @claim.add_certify_correct(true, post)
29
+ # @claim.commit(post).success.should == true
30
+ # end
31
+ end
32
+
33
+ context " attributes" do
34
+ it "should add the claim_source_identifier" do
35
+ @claim.add_claim_source_identifier(1).has_key?(:claim_source_identifier).should == true
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ def http_get(domain,path,params)
42
+ require 'net/http'
43
+ return Net::HTTP.get(domain, "#{path}?".concat(params.collect { |k,v| '#{k}=#{CGI::escape(v.to_s)}' }.reverse.join('&'))) if not params.nil?
44
+ return Net::HTTP.get(domain, path)
45
+ end
46
+
47
+
48
+ def person
49
+ Shipsurance::Person.new({
50
+ :source_indentifier => 1,
51
+ :company => "OrderCup",
52
+ :first_name => "Tim",
53
+ :last_name => "Matheson",
54
+ :phone => "9495551212",
55
+ :fax => "9495551212",
56
+ :email => CREDENTIALS[:person_email]
57
+ })
58
+ end
59
+
60
+ def valid_record_shipment_params
61
+ {
62
+ :ext_shipment_type_id => 1,
63
+ :ext_carrier_id => 1,
64
+ :carrier_service_name => "UPS",
65
+ :declared_value => 50.00,
66
+ :shipment_date => Time.now.strftime("%m/%d/%Y"),
67
+ :person_email => CREDENTIALS[:person_email],
68
+ :package_description => "Test Description #{rand(9999999)}"
69
+ }
70
+ end
71
+ end
@@ -0,0 +1,57 @@
1
+ require File.dirname(__FILE__) + "/../../spec_helper"
2
+
3
+ describe Shipsurance::Person do
4
+ it "should accept all valid person attributes" do
5
+ person = Shipsurance::Person.new(valid_person_attributes)
6
+ person.attributes.should == valid_person_attributes
7
+ end
8
+
9
+ it "should mass assign the first_name attribute" do
10
+ person = Shipsurance::Person.new(valid_person_attributes)
11
+ person.attributes[:first_name].should == valid_person_attributes[:first_name]
12
+ end
13
+
14
+ it "should mass assign the last_name attribute" do
15
+ person = Shipsurance::Person.new(valid_person_attributes)
16
+ person.attributes[:last_name].should == valid_person_attributes[:last_name]
17
+ end
18
+
19
+ it "should mass assign the email attribute" do
20
+ person = Shipsurance::Person.new(valid_person_attributes)
21
+ person.attributes[:email].should == valid_person_attributes[:email]
22
+ end
23
+
24
+ it "should mass assign the source_identifier attribute" do
25
+ person = Shipsurance::Person.new(valid_person_attributes)
26
+ person.attributes[:source_identifier].should == valid_person_attributes[:source_identifier]
27
+ end
28
+
29
+ it "should mass assign the company attribute" do
30
+ person = Shipsurance::Person.new(valid_person_attributes)
31
+ person.attributes[:company].should == valid_person_attributes[:company]
32
+ end
33
+
34
+ it "should mass assign the phone attribute" do
35
+ person = Shipsurance::Person.new(valid_person_attributes)
36
+ person.attributes[:phone].should == valid_person_attributes[:phone]
37
+ end
38
+
39
+ it "should mass assign the fax attribute" do
40
+ person = Shipsurance::Person.new(valid_person_attributes)
41
+ person.attributes[:fax].should == valid_person_attributes[:fax]
42
+ end
43
+
44
+ private
45
+
46
+ def valid_person_attributes
47
+ {
48
+ :source_indentifier => 1,
49
+ :company => "Ordercup",
50
+ :first_name => "Tim",
51
+ :last_name => "Matheson",
52
+ :phone => "9495551212",
53
+ :fax => "9495551212",
54
+ :email => "tim.matheson@ordercup.com"
55
+ }
56
+ end
57
+ end
@@ -0,0 +1,114 @@
1
+ require File.dirname(__FILE__) + "/../../spec_helper"
2
+
3
+ describe Shipsurance::RecordShipment do
4
+ before(:each) do
5
+ @record_shipment = Shipsurance::RecordShipment.new
6
+ @address = Shipsurance::Address.new(address_attributes)
7
+ end
8
+
9
+ context " a valid request" do
10
+ it "should return a successful response given valid params" do
11
+ response = @record_shipment.commit(valid_request_params)
12
+ response.body.should == "The transaction was accepted."
13
+ end
14
+
15
+ it "should return a transaction key given valid params" do
16
+ response = @record_shipment.commit(valid_request_params)
17
+ response.recorded_shipment_id.should_not be_nil
18
+ end
19
+
20
+ it "should return a status code of 200 given valid params" do
21
+ response = @record_shipment.commit(valid_request_params)
22
+ response.code.should == 200
23
+ end
24
+
25
+ it "should return an api response code of 1 given valid params" do
26
+ response = @record_shipment.commit(valid_request_params)
27
+ response.api_response_code.should == 1
28
+ end
29
+ end
30
+
31
+ context " attributes" do
32
+ it "should add the tracking number" do
33
+ @record_shipment.add_tracking_number("1Z999999999999999").has_key?(:tracking_number).should == true
34
+ end
35
+
36
+ it "should add the reference number" do
37
+ @record_shipment.add_reference_number(123456).has_key?(:reference_number).should == true
38
+ end
39
+
40
+ it "should add the carrier" do
41
+ params = @record_shipment.add_carrier(1,"UPS")
42
+ params.has_key?(:carrier_name).should == true
43
+ params.has_key?(:ext_carrier_id).should == true
44
+ end
45
+
46
+ it "should add the ext_shipment_type_id" do
47
+ @record_shipment.add_ext_shipment_type_id(1).has_key?(:ext_shipment_type_id).should == true
48
+ end
49
+
50
+ it "should add the record_source_identifier" do
51
+ @record_shipment.add_record_source_identifier(123456).has_key?(:record_source_identifier).should == true
52
+ end
53
+
54
+ it "should add the recorded_shipment_id" do
55
+ @record_shipment.add_recorded_shipment_id(1).has_key?(:recorded_shipment_id).should == true
56
+ end
57
+
58
+ it "should add the shipment_date" do
59
+ params = @record_shipment.add_shipment_date(Time.now)
60
+ params.has_key?(:shipment_date).should == true
61
+ params[:shipment_date].should == Time.now.strftime("%m/%d/%Y")
62
+ end
63
+
64
+ it "should add the arrival_date" do
65
+ params = @record_shipment.add_arrival_date(Time.now)
66
+ params.has_key?(:arrival_date).should == true
67
+ params[:arrival_date].should == Time.now.strftime("%m/%d/%Y")
68
+ end
69
+
70
+ it "should add the ext_commodity_category_id" do
71
+ @record_shipment.add_ext_commodity_category_id(1).has_key?(:ext_commodity_category_id).should == true
72
+ end
73
+
74
+ it "should add the ext_package_type_id" do
75
+ @record_shipment.add_ext_package_type_id(1).has_key?(:ext_package_type_id).should == true
76
+ end
77
+
78
+ it "should add the package_count" do
79
+ @record_shipment.add_package_count(1).has_key?(:package_count).should == true
80
+ end
81
+
82
+ it "should add contains_glass" do
83
+ @record_shipment.add_contains_glass(1).has_key?(:contains_glass).should == true
84
+ end
85
+
86
+ it "should add the package_description" do
87
+ @record_shipment.add_package_description("Test Description").has_key?(:package_description).should == true
88
+ end
89
+
90
+ it "should add the departure_address" do
91
+ @record_shipment.should_receive(:add_departure_address_1).once.with(@address.address_1,{})
92
+ @record_shipment.should_receive(:add_departure_address_2).once.with(@address.address_2,{})
93
+ @record_shipment.should_receive(:add_departure_city).once.with(@address.city,{})
94
+ @record_shipment.should_receive(:add_departure_state).once.with(@address.state,{})
95
+ @record_shipment.should_receive(:add_departure_postal_code).once.with(@address.postal_code,{})
96
+ @record_shipment.should_receive(:add_departure_country).once.with(@address.country,{})
97
+ @record_shipment.add_departure_address(@address)
98
+ end
99
+ end
100
+
101
+ private
102
+
103
+ def valid_request_params
104
+ {
105
+ :ext_shipment_type_id => 1,
106
+ :ext_carrier_id => 1,
107
+ :carrier_service_name => "UPS",
108
+ :declared_value => 50.00,
109
+ :shipment_date => Time.now.strftime("%m/%d/%Y"),
110
+ :person_email => CREDENTIALS[:person_email],
111
+ :package_description => "Test Description #{rand(9999999)}"
112
+ }
113
+ end
114
+ end
@@ -0,0 +1,27 @@
1
+ require File.dirname(__FILE__) + "/../../spec_helper"
2
+
3
+ describe Shipsurance::Validation do
4
+ before :each do
5
+ @validation = Shipsurance::Validation.new
6
+ end
7
+
8
+ it "should return Accepted given a valid validation type" do
9
+ response = @validation.commit({ :validation_type => "activePolicy" })
10
+ response.body.should == "Accepted"
11
+ end
12
+
13
+ it "should return an api_response_code of 1 given a valid validation type" do
14
+ response = @validation.commit({ :validation_type => "activePolicy" })
15
+ response.api_response_code.should == 1
16
+ end
17
+
18
+ it "should return an error given an invalid validation type" do
19
+ response = @validation.commit({ :validation_type => "foo" })
20
+ response.body.should == "The validationType is not valid."
21
+ end
22
+
23
+ it "should return an api_response_code of 2 given an invalid validation type" do
24
+ response = @validation.commit({ :validation_type => "foo" })
25
+ response.api_response_code.should == 2
26
+ end
27
+ end
@@ -0,0 +1,4 @@
1
+ require File.dirname(__FILE__) + "/../../spec_helper"
2
+
3
+ describe Shipsurance::VoidRecordShipment do
4
+ end
@@ -0,0 +1,4 @@
1
+ --colour
2
+ --format progress
3
+ --loadby mtime
4
+ --reverse
@@ -0,0 +1,14 @@
1
+ require File.dirname(__FILE__) + "/../lib/shipsurance"
2
+
3
+ def address_attributes
4
+ {
5
+ :address_1 => "123 West street",
6
+ :address_2 => "APT #1",
7
+ :city => "Rancho Santa Margarita",
8
+ :state => "CA",
9
+ :postal_code => 92688,
10
+ :country => "US"
11
+ }
12
+ end
13
+
14
+ CREDENTIALS = YAML.load_file("config/credentials.yml")["test"].symbolize_keys
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shipsurance
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tim Matheson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-11-28 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Integration gem for the ShipSurance gem
17
+ email: tim.matheson@ordercup.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - lib/extensions/hash.rb
24
+ - lib/shipsurance/address.rb
25
+ - lib/shipsurance/base.rb
26
+ - lib/shipsurance/claim.rb
27
+ - lib/shipsurance/person.rb
28
+ - lib/shipsurance/record_shipment.rb
29
+ - lib/shipsurance/response.rb
30
+ - lib/shipsurance/shipsurance.rb
31
+ - lib/shipsurance/validation.rb
32
+ - lib/shipsurance/void_record_shipment.rb
33
+ - lib/shipsurance.rb
34
+ - README.rdoc
35
+ files:
36
+ - config/credentials.example.yml
37
+ - config/credentials.yml
38
+ - init.rb
39
+ - lib/extensions/hash.rb
40
+ - lib/shipsurance/address.rb
41
+ - lib/shipsurance/base.rb
42
+ - lib/shipsurance/claim.rb
43
+ - lib/shipsurance/person.rb
44
+ - lib/shipsurance/record_shipment.rb
45
+ - lib/shipsurance/response.rb
46
+ - lib/shipsurance/shipsurance.rb
47
+ - lib/shipsurance/validation.rb
48
+ - lib/shipsurance/void_record_shipment.rb
49
+ - lib/shipsurance.rb
50
+ - Rakefile
51
+ - README.rdoc
52
+ - spec/lib/shipsurance/address_spec.rb
53
+ - spec/lib/shipsurance/claim_spec.rb
54
+ - spec/lib/shipsurance/person_spec.rb
55
+ - spec/lib/shipsurance/record_shipment_spec.rb
56
+ - spec/lib/shipsurance/validation_spec.rb
57
+ - spec/lib/shipsurance/void_record_shipment_spec.rb
58
+ - spec/spec.opts
59
+ - spec/spec_helper.rb
60
+ - Manifest
61
+ - shipsurance.gemspec
62
+ has_rdoc: true
63
+ homepage: http://www.ordercup.com
64
+ licenses: []
65
+
66
+ post_install_message:
67
+ rdoc_options:
68
+ - --line-numbers
69
+ - --inline-source
70
+ - --title
71
+ - Shipsurance
72
+ - --main
73
+ - README.rdoc
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: "0"
81
+ version:
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: "1.2"
87
+ version:
88
+ requirements: []
89
+
90
+ rubyforge_project: shipsurance
91
+ rubygems_version: 1.3.2
92
+ signing_key:
93
+ specification_version: 3
94
+ summary: Integration gem for the ShipSurance gem
95
+ test_files: []
96
+