odfl 1.0.1 → 1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 402041458682d35a2ded22ee864eb0c1629d6cea
4
- data.tar.gz: 587ac0e9c0f868a791fe1d66662b876582b0a9ee
3
+ metadata.gz: a30fc4c7716e4880cd056dd66644da31b423f577
4
+ data.tar.gz: 567fbdde1e965fab69de0fc2bf5a83d4941ab1e2
5
5
  SHA512:
6
- metadata.gz: dabcd7d96110493778034ba33a2e4049fc44691010c171b446dc9e30c41364ace0b3a469174d1241d9406cc3744297af69652122c3f6cc4dd031f209c61ab975
7
- data.tar.gz: ea57142ae55a0763f4ee78fdbe3108914afd8c582340363e5ac883e0be96bad466f6052a46e947620ca1a90525956f3f3a9cecc2ac8db8cc794c6b7cf190f1b3
6
+ metadata.gz: 3711ce543943439d54172926c2c9847fcf99c4463a4e292439163741903691ab830004415627360eb4d70117ec2ea69267c49a83c746a7407fc74cd4c4be3ada
7
+ data.tar.gz: 8e09d32f020b5e80cfc4f86aa83527102013b5b0b587338126218e9760a458db1f463e9cf036e261950753185249c4414503689eb22158ae14430238f5fdca16
data/.gitignore CHANGED
@@ -12,4 +12,5 @@
12
12
  *.so
13
13
  *.o
14
14
  *.a
15
+ *.gem
15
16
  mkmf.log
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.0
4
+ - 2.1.1
5
+ addons:
6
+ code_climate:
7
+ repo_token: d8ad7ffd449b9dd008e83ef3c79ccd033fd726d94ff1ae3597df674bea81b3c5
data/README.md CHANGED
@@ -1,6 +1,17 @@
1
1
  # Odfl
2
2
 
3
- TODO: Write a gem description
3
+ Get Old Dominion Freight Line Shipping Quotes
4
+
5
+ [RDoc](http://rubydoc.info/gems/odfl)
6
+
7
+ [![Gem Version](https://badge.fury.io/rb/odfl.svg)](http://badge.fury.io/rb/odfl)
8
+ [![Code Climate](https://codeclimate.com/github/rmevans1/odfl-gem/badges/gpa.svg)](https://codeclimate.com/github/rmevans1/odfl-gem)
9
+ [![Test Coverage](https://codeclimate.com/github/rmevans1/odfl-gem/badges/coverage.svg)](https://codeclimate.com/github/rmevans1/odfl-gem)
10
+ [![Build Status](https://travis-ci.org/rmevans1/odfl-gem.svg?branch=master)](https://travis-ci.org/rmevans1/odfl-gem)
11
+
12
+ The gem allows you to retrieve shipping quotes from Old Dominion Freight Line.
13
+ A customer account is required to retrieve customer specific pricing. However,
14
+ an odfl account is not required to run rate quotes
4
15
 
5
16
  ## Installation
6
17
 
@@ -12,7 +23,7 @@ gem 'odfl'
12
23
 
13
24
  And then execute:
14
25
 
15
- $ bundle
26
+ $ bundle install
16
27
 
17
28
  Or install it yourself as:
18
29
 
@@ -20,12 +31,54 @@ Or install it yourself as:
20
31
 
21
32
  ## Usage
22
33
 
23
- TODO: Write usage instructions here
34
+ ``` ruby
35
+ require 'odfl'
36
+ require 'odfl_freight'
37
+
38
+ # create a new quote object
39
+ quote = Odfl.new
40
+ # create a new freight object
41
+ pallet = OdflFreight.new
42
+
43
+ # Set basic ODFL items for quote
44
+ quote.set_origin(20602)
45
+ quote.set_destination(90210)
46
+ quote.movement = "O"
47
+
48
+ # Create a basic shipment item
49
+ pallet.ratedClass = 70
50
+ pallet.weight = 1000
51
+ quote.addFreight(pallet.to_hash)
52
+
53
+ # Get rates
54
+ quote.get_rates
55
+ ```
56
+
57
+ ### Debugging
58
+
59
+ If you are having trouble getting quotes and need to see the request
60
+ and response it can be enable with the following
61
+
62
+ Attribute 1 turns logging on
63
+ Attribute 2 sets log level to :debug
64
+ Attribute 3 sets pretty_print_xml to true
65
+
66
+ ``` ruby
67
+ quote = Odfl.new(true, :debug, true)
68
+ ```
69
+
70
+
24
71
 
25
72
  ## Contributing
26
73
 
27
- 1. Fork it ( https://github.com/[my-github-username]/odfl/fork )
74
+ 1. Fork it ( https://github.com/rmevans1/odfl/fork )
28
75
  2. Create your feature branch (`git checkout -b my-new-feature`)
29
76
  3. Commit your changes (`git commit -am 'Add some feature'`)
30
77
  4. Push to the branch (`git push origin my-new-feature`)
31
78
  5. Create a new Pull Request
79
+
80
+ ## Disclaimer
81
+
82
+ It is your responsibility to make sure that the quotes that are returned are accurate. I have made
83
+ every effort possible to make sure the quotes are accurate. I assume no responsibility for any quotes
84
+ that come back cheaper than they should.
data/lib/odfl/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Odfl
2
- VERSION = "1.0.1"
2
+ VERSION = "1.1.0"
3
3
  end
data/lib/odfl.rb CHANGED
@@ -4,7 +4,8 @@ require 'savon'
4
4
  class Odfl
5
5
 
6
6
  attr_reader :originPostalCode, :originCountry, :destinationPostalCode, :destinationCountry,
7
- :totalCubicVolume, :cubicUnits, :pickupDateTime, :deliveryDateTime, :codAmount
7
+ :totalCubicVolume, :cubicUnits, :pickupDateTime, :deliveryDateTime, :codAmount,
8
+ :resultHash
8
9
  attr_accessor :client, :response, :request, :freight, :accessorials, :currencyFormat
9
10
 
10
11
  # 1 Character Alpha Either O (outbound) or I (inbound). Defaults to "O"
@@ -58,9 +59,9 @@ class Odfl
58
59
  # Customers first and last name
59
60
  attr_accessor :firstName, :lastName
60
61
 
61
- def initialize #:notnew: stops RDoc from seeing the initialize method
62
+ def initialize(log = false, log_level= :debug, pretty_print_xml = false) #:notnew: stops RDoc from seeing the initialize method
62
63
  @client = Savon.client(wsdl: 'https://www.odfl.com/wsRate_v3/services/Rate/wsdl/Rate.wsdl', ssl_verify_mode: :none,
63
- log: true, log_level: :debug, pretty_print_xml: true)
64
+ log: log, log_level: log_level, pretty_print_xml: pretty_print_xml)
64
65
  self.freight = Array.new
65
66
  self.accessorials = Array.new
66
67
  self.tariff = 559
@@ -173,46 +174,30 @@ class Odfl
173
174
  # Required for Expedited GTO rates
174
175
  #
175
176
  # ==== Attributes
176
- # * +month+ Pickup Month 1-12
177
- # * +day+ Pickup Day 1-31
178
- # * +year+ Pickup Year (4 digit year)
179
- # * +hour+ Pickup Hour 0-23
180
- # * +minute+ Pickup Minute 0-59
177
+ # * +month+ Pickup/Delivery Month 1-12
178
+ # * +day+ Pickup/Delivery Day 1-31
179
+ # * +year+ Pickup/Delivery Year (4 digit year)
180
+ # * +hour+ Pickup/Delivery Hour 0-23
181
+ # * +minute+ Pickup/Delivery Minute 0-59
182
+ # * +type+ The type of time to set either "pickup" or "delivery"
181
183
  #
182
184
  # ==== Usage
183
185
  # quote = Odfl.new
184
- # quote.setPickupDateTime(12,25,2014,12,30)
185
- def setPickupDateTime(month, day, year, hour, minute)
186
+ # quote.setPickupDeliveryDateTime(12,25,2014,12,30, "delivery")
187
+ def setPickupDeliveryDateTime(month, day, year, hour, minute, type)
186
188
  month = month<10 ? "0#{month}" : "#{month}"
187
189
  day = day<10 ? "0#{day}" : "#{day}"
188
190
  hour = hour<10 ? "0#{hour}" : "#{hour}"
189
191
  minute = minute<10 ? "0#{minute}" : "#{minute}"
190
192
  second = '00'
191
193
 
192
- @pickupDateTime = "#{year}-#{month}-#{day}T#{hour}:#{minute}:#{second}"
193
- end
194
-
195
- # Set the delivery date and time
196
- # Required for Expedited GTO rates
197
- #
198
- # ==== Attributes
199
- # * +month+ Delivery Month 1-12
200
- # * +day+ Delivery Day 1-31
201
- # * +year+ Delivery Year (4 digit year)
202
- # * +hour+ Delivery Hour 0-23
203
- # * +minute+ Delivery Minute 0-59
204
- #
205
- # ==== Usage
206
- # quote = Odfl.new
207
- # quote.setDeliveryDateTime(12,25,2014,12,30)
208
- def setDeliveryDateTime(month, day, year, hour, minute)
209
- month = month<10 ? "0#{month}" : "#{month}"
210
- day = day<10 ? "0#{day}" : "#{day}"
211
- hour = hour<10 ? "0#{hour}" : "#{hour}"
212
- minute = minute<10 ? "0#{minute}" : "#{minute}"
213
- second = '00'
194
+ date = "#{year}-#{month}-#{day}T#{hour}:#{minute}:#{second}"
214
195
 
215
- @deliveryDateTime = "#{year}-#{month}-#{day}T#{hour}:#{minute}:#{second}"
196
+ if type == 'delivery'
197
+ @deliveryDateTime = date
198
+ else
199
+ @pickupDateTime = date
200
+ end
216
201
  end
217
202
 
218
203
  # Set an amount for COD
@@ -265,5 +250,33 @@ class Odfl
265
250
  firstName: self.firstName,
266
251
  lastName: self.lastName
267
252
  })
253
+ processResult(@response)
254
+
255
+ if @resultHash[:success] == '1'
256
+ true
257
+ else
258
+ false
259
+ end
260
+ end
261
+
262
+ def getOriginatingServiceCenter
263
+ @resultHash[:originating_service_center]
264
+ end
265
+
266
+ def getDestinationServiceCenter
267
+ @resultHash[:destination_service_center]
268
+ end
269
+
270
+ def get_estimate
271
+ @resultHash[:rate_estimate]
272
+ end
273
+
274
+ def get_error
275
+ @resultHash[:error_messages][:string]
276
+ end
277
+
278
+ private
279
+ def processResult(result)
280
+ @resultHash = result.to_hash[:my_rate_response]
268
281
  end
269
282
  end
data/lib/odfl_freight.rb CHANGED
@@ -6,14 +6,4 @@ class OdflFreight
6
6
  instance_variables.each {|var| hash[var.to_s.delete("@")] = instance_variable_get(var) }
7
7
  hash
8
8
  end
9
-
10
- def to_soap_array
11
- result=Array.new
12
-
13
- instance_variables.each do |var|
14
- result.push({var.to_s.delete("@") => Integer(instance_variable_get(var))})
15
- end
16
-
17
- result
18
- end
19
9
  end
data/odfl.gemspec CHANGED
@@ -20,9 +20,10 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.required_ruby_version = '~> 2.1'
22
22
 
23
- spec.add_development_dependency "bundler", "~> 1.7"
24
- spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "bundler", ">= 1.6"
24
+ spec.add_development_dependency "rake", ">= 10.0"
25
25
  spec.add_development_dependency 'rspec'
26
+ spec.add_development_dependency 'codeclimate-test-reporter'
26
27
 
27
28
  spec.add_dependency 'savon', '~> 2.8'
28
29
  end
@@ -1,9 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Odfl do
4
- quote = Odfl.new
5
4
 
6
5
  it 'should set the origin zip code and country' do
6
+ quote = Odfl.new
7
7
  quote.set_origin(29579)
8
8
  expect(quote).not_to be_nil
9
9
  expect(quote.originPostalCode).to eq(29579)
@@ -11,6 +11,7 @@ describe Odfl do
11
11
  end
12
12
 
13
13
  it 'should set the destination zip code and country' do
14
+ quote = Odfl.new
14
15
  quote.set_destination(20602)
15
16
  expect(quote).not_to be_nil
16
17
  expect(quote.destinationPostalCode).to eq(20602)
@@ -18,9 +19,135 @@ describe Odfl do
18
19
  end
19
20
 
20
21
  it 'should set the movement of the shipment' do
22
+ quote = Odfl.new
21
23
  quote.movement = 'O'
22
24
  expect(quote).not_to be_nil
23
25
  expect(quote.movement).to eq('O')
24
26
  end
25
27
 
28
+ it 'should set the delivery date and time' do
29
+ quote = Odfl.new
30
+ quote.setPickupDeliveryDateTime(12,25,2014,12,30,'delivery')
31
+ expect(quote).not_to be_nil
32
+ expect(quote.deliveryDateTime).to eq('2014-12-25T12:30:00')
33
+ end
34
+
35
+ it 'should set the pickup date and time' do
36
+ quote = Odfl.new
37
+ quote.setPickupDeliveryDateTime(12,22,2014,12,30,'pickup')
38
+ expect(quote).not_to be_nil
39
+ expect(quote.pickupDateTime).to eq('2014-12-22T12:30:00')
40
+ end
41
+
42
+ it 'should add an accessorial' do
43
+ quote = Odfl.new
44
+ quote.addAccessorial('HYD')
45
+ expect(quote).not_to be_nil
46
+ expect(quote.accessorials.count).to eq(1)
47
+ end
48
+
49
+ it 'should not add a duplicate accessorial' do
50
+ quote = Odfl.new
51
+ quote.addAccessorial('HYD')
52
+ expect(quote).not_to be_nil
53
+ expect(quote.accessorials.count).to eq(1)
54
+ quote.addAccessorial('HYD')
55
+ expect(quote.accessorials.count).to eq(1)
56
+ end
57
+
58
+ it 'should set COD amount and add COD accessorial' do
59
+ quote = Odfl.new
60
+ quote.setCODAmount(1000.25)
61
+ expect(quote).not_to be_nil
62
+ expect(quote.codAmount).to eq(1000.25)
63
+ expect(quote.accessorials.include?('COD')).to be_truthy
64
+ end
65
+
66
+ it 'should set cubic volume and cubic volume units' do
67
+ quote = Odfl.new
68
+ quote.setCubicVolume(100)
69
+ expect(quote).not_to be_nil
70
+ expect(quote.totalCubicVolume).to eq(100)
71
+ expect(quote.cubicUnits).to eq('CF')
72
+ end
73
+
74
+ it 'should add a freight item' do
75
+ quote = Odfl.new
76
+ pallet = OdflFreight.new
77
+ pallet.ratedClass = 70
78
+ pallet.weight = 1000
79
+ quote.addFreight(pallet.to_hash)
80
+ expect(quote).not_to be_nil
81
+ expect(quote.freight.count).to eq(1)
82
+ end
83
+
84
+ it 'should return false for an invalid quote' do
85
+ quote = Odfl.new
86
+
87
+ quote.set_destination(90210)
88
+ result = quote.get_rates
89
+
90
+ expect(quote).not_to be_nil
91
+ expect(result).to be_falsey
92
+ end
93
+
94
+ it 'get_error function should return a string for the error message' do
95
+ quote = Odfl.new
96
+
97
+ quote.get_rates
98
+
99
+ expect(quote.get_error).to be_a_kind_of(String)
100
+ end
101
+
102
+ it 'should return a valid rate estimate for a valid quote' do
103
+ quote = Odfl.new
104
+
105
+ quote.set_origin(20602)
106
+ quote.set_destination(90210)
107
+
108
+ pallet = OdflFreight.new
109
+ pallet.ratedClass = 70
110
+ pallet.weight = 1000
111
+ quote.addFreight(pallet.to_hash)
112
+
113
+ result = quote.get_rates
114
+ expect(result).to be_truthy
115
+ rate = quote.get_estimate
116
+
117
+ expect(rate).to be_a_kind_of(Hash)
118
+
119
+ expect(Float(rate[:gross_freight_charge])).to be > 0
120
+ end
121
+
122
+ it 'should return a valid hash for originating service center' do
123
+ quote = Odfl.new
124
+ quote.set_origin(20602)
125
+ quote.set_destination(90210)
126
+
127
+ pallet = OdflFreight.new
128
+ pallet.ratedClass = 70
129
+ pallet.weight = 1000
130
+ quote.addFreight(pallet.to_hash)
131
+
132
+ result = quote.get_rates
133
+ expect(result).to be_truthy
134
+
135
+ expect(quote.getOriginatingServiceCenter).to be_a_kind_of(Hash)
136
+ end
137
+
138
+ it 'should return a valid hash for destination service center' do
139
+ quote = Odfl.new
140
+ quote.set_origin(20602)
141
+ quote.set_destination(90210)
142
+
143
+ pallet = OdflFreight.new
144
+ pallet.ratedClass = 70
145
+ pallet.weight = 1000
146
+ quote.addFreight(pallet.to_hash)
147
+
148
+ result = quote.get_rates
149
+ expect(result).to be_truthy
150
+
151
+ expect(quote.getDestinationServiceCenter).to be_a_kind_of(Hash)
152
+ end
26
153
  end
data/spec/spec_helper.rb CHANGED
@@ -1 +1,5 @@
1
- require 'odfl'
1
+ require "codeclimate-test-reporter"
2
+ CodeClimate::TestReporter.start
3
+
4
+ require 'odfl'
5
+ require 'odfl_freight'
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: odfl
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Evans
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-18 00:00:00.000000000 Z
11
+ date: 2014-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.7'
19
+ version: '1.6'
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.7'
26
+ version: '1.6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '10.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: codeclimate-test-reporter
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: savon
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -74,6 +88,7 @@ extensions: []
74
88
  extra_rdoc_files: []
75
89
  files:
76
90
  - ".gitignore"
91
+ - ".travis.yml"
77
92
  - Gemfile
78
93
  - LICENSE.txt
79
94
  - README.md
@@ -104,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
119
  version: '0'
105
120
  requirements: []
106
121
  rubyforge_project:
107
- rubygems_version: 2.4.4
122
+ rubygems_version: 2.4.5
108
123
  signing_key:
109
124
  specification_version: 4
110
125
  summary: Get freight quotes from Old Dominion Freight Line