mxd_tracker 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f4834b2d5534280a2e128a54717dee90e928fd73
4
+ data.tar.gz: f0979778c3c86109586c1b84bd0a952e32590ffd
5
+ SHA512:
6
+ metadata.gz: 3d2d6a931a671aea7c4fb37c06c6d472e1b7f9b139e4fd259d5cfc46158d1a67cb1b4449201e7c2477cfe8ab5c916ed4b4a7ac3df450800eeceb23e6fca440e2
7
+ data.tar.gz: c9ec01700c1952b2b7ba4c9f1ef45d2791242bc7db107a742995adb53d74015be0fccfec3b9bd3ed51d2c510a28063c6b5cf6f580f4da7129534863ade82dba6
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mxd_tracker.gemspec
4
+ gemspec
5
+ group :development, :test do
6
+ gem 'bundler'
7
+ gem 'rake'
8
+ gem 'rspec'
9
+ gem 'vcr'
10
+ gem 'webmock'
11
+ gem 'pry'
12
+ gem 'binding_of_caller'
13
+ gem 'byebug'
14
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Eddie Salazar
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # MxdTracker
2
+
3
+ Mxd Tracker helps you find tracking information for MXD shipments. It's easy to use. Just call ```MxdTracker::Mxd.shipment_status```
4
+ ## Installation
5
+
6
+ Add this line to your application's Gemfile:
7
+
8
+ ```ruby
9
+ gem 'mxd_tracker'
10
+ ```
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install mxd_tracker
19
+
20
+ ## Usage
21
+
22
+ The shipment_status method expects a zipcode, and either a tracking\_number, phone\_number, order\_number, or waybill\_number as a hash.
23
+
24
+
25
+ tracking_hash = { zip_code: "34238", waybill_number: "12345" }
26
+ MxdTracker::Mxd.shipment_status(tracking_hash) =>
27
+ {
28
+ "error" => nil,
29
+ "current_status" => "Picked up date: 2015-07-31 04:00:00 UTC",
30
+ "waybill_number" => "12345",
31
+ "tracking_number" => "1111111",
32
+ "order_number" => "D58500",
33
+ "progress_details" => [
34
+ {
35
+ "date"=>"07/31/15",
36
+ "activity"=>"SHIPMENT DISPATCHED FROM ORIGIN",
37
+ "location"=>"WILSON, NC"
38
+ }
39
+ ],
40
+ "pick_up_address"=>"3905 Airport Dr NW WILSON, NC 27896",
41
+ "delivery_address"=>"4283 Express Lane Small Town, CA 55555"
42
+ }
43
+
44
+
45
+ ## Contributing
46
+
47
+ Bug reports and pull requests are welcome on GitHub at https://github.com/dotandbo/mxd-tracking. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
48
+
49
+
50
+ ## License
51
+
52
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
53
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "mxd_tracker"
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
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,170 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://www.homedirectusa.com/hdusaoms/trackShipmentByWbAndZipOnly.htm?wayBill=ZHLPRY&zip_code=34238
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip,deflate,identity
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Mechanize/2.7.3 Ruby/2.2.2p95 (http://github.com/sparklemotion/mechanize/)
16
+ Accept-Charset:
17
+ - ISO-8859-1,utf-8;q=0.7,*;q=0.7
18
+ Accept-Language:
19
+ - en-us,en;q=0.5
20
+ Host:
21
+ - www.homedirectusa.com
22
+ Connection:
23
+ - keep-alive
24
+ Keep-Alive:
25
+ - 300
26
+ response:
27
+ status:
28
+ code: 200
29
+ message: OK
30
+ headers:
31
+ Server:
32
+ - WebSphere Application Server/7.0
33
+ Cache-Control:
34
+ - no-store, no-cache
35
+ Content-Type:
36
+ - text/html;charset=ISO-8859-1
37
+ Date:
38
+ - Mon, 03 Aug 2015 21:15:18 GMT
39
+ Expires:
40
+ - Thu, 01 Dec 1994 16:00:00 GMT
41
+ Pragma:
42
+ - no-cache
43
+ Transfer-Encoding:
44
+ - chunked
45
+ Content-Language:
46
+ - en-US
47
+ Set-Cookie:
48
+ - JSESSIONID=0000C3T174oamvat3NIeFUfRxNy:-1; Path=/
49
+ - X-Mapping-ejobmchp=E09A51DBFFF681112B84446BEE73C4E0; path=/
50
+ body:
51
+ encoding: UTF-8
52
+ string: "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\r\n\r\n\r\n\r\n<html
53
+ xmlns=\"http://www.w3.org/1999/xhtml\">\r\n<head>\r\n<meta http-equiv=\"Content-Type\"
54
+ content=\"text/html; charset=utf-8\" />\r\n<meta http-equiv=\"pragma\" content=\"no-cache\"/>\r\n<meta
55
+ http-equiv=\"cache-control\" content=\"no-cache, max-age=0, must-revalidate,
56
+ no-store\"/>\r\n<meta http-equiv=\"expires\" content=\"0\"/>\r\n<title>Home
57
+ Direct USA</title>\r\n<link href=\"common/css/tracking.css\" rel=\"stylesheet\"
58
+ type=\"text/css\" />\r\n<!--[if IE 6]><script type=\"text/javascript\" src=\"common/js/jq-png-min.js\"></script><![endif]-->\r\n<script
59
+ type=\"text/javascript\" src=\"/hdusaoms/common/js/guesttracking.js\"></script>\r\n<head>\r\n\r\n</head>\r\n<body>\r\n\r\n<script
60
+ type=\"text/javascript\" >\r\nString.prototype.nthIndex = function (n, c)
61
+ {\r\n var index = -1;\r\n while (n-- > 0) {\r\n index++;\r\n
62
+ \ if (this.substring(index) == \"\") return -1; // don't run off the
63
+ end\r\n index += this.substring(index).indexOf(c);\r\n }\r\n return
64
+ index;\r\n}\r\n\r\n\r\n// get the base URL of the current page by taking everything
65
+ up to the third \"/\" in the URL\r\nfunction getBaseURL() {\r\n var url
66
+ = document.URL.substring(0, document.URL.nthIndex(3,\"/\") + 1);\r\n window.location.replace(url);\r\n}\r\n\r\n</script>\r\n<div
67
+ id=\"skip-link\"></div>\r\n \r\n\r\n\r\n \r\n \r\n \r\n\r\n\r\n\t \r\n<div
68
+ class=\"wrapper\">\r\n\t <!-- <div id=\"header\"><a href=\"#\" class=\"logo\"><img
69
+ src=\"common/images/hdlogo.png\" alt=\"\" /></a><span style=\"position: relative;left:
70
+ -210px;top:75px;color: #283c93\"><a href=\"http://uat.homedirectusa.com\"
71
+ style=\"text-decoration: none;font-size: 12px\"><b>HOME</b></a></span></div>\r\n\t
72
+ \ -->\r\n\t <div id=\"body_containerTrack\">\r\n\t \t<input type=\"hidden\"
73
+ id=\"wbType\" value='D'/>\r\n\t \t\t \r\n\t \t\r\n\t\t \t\r\n\t\t \t\r\n\t\t
74
+ \ \t\r\n\t\t \t\t \t\r\n\t \t\r\n\t <h2>Tracking</h2>\r\n\t <div
75
+ class=\"tracking_section\">\r\n\t <h3 class=\"first\">Tracking Details</h3>\r\n\t
76
+ \ <div class=\"tracking_details_sec\">\r\n\t <div class=\"tracking_details\"
77
+ id=\"tracking_div\">\r\n\t <div class=\"progress_details\">\r\n\t
78
+ \ \t<ul class=\"first\"><li class=\"first_bg\"></li><li class=\"second_bg\"></li><li
79
+ class=\"third_bg\"></li><li class=\"fourth_empty_bg active\"></li><li class=\"fifth_empty_bg
80
+ active\"></li></ul><ul><li class=\"head\"><font size=2.5>Order Processed</font></li><li><font
81
+ size=2.5>Picked Up</font></li><li class=\"last\"><font size=2.5>In Transit</font></li><li><font
82
+ size=2.5>Arrived at Delivery Terminal</font></li><li class=\"last\"><font
83
+ size=2.5>Delivered!</font></li></ul>\r\n\t <ul class=\"delivered\">\r\n\t
84
+ \ \t<li>Picked up date: Fri, 07/31/15</li>\r\n\t </ul>\r\n\t
85
+ \ </div>\r\n\t <h3>Order Reference Information</h3>\r\n\t
86
+ \ <div class=\"reference_information\">\r\n\t <div class=\"col\">\r\n\t
87
+ \ \t<table border=0>\r\n\t \t\t<tr>\r\n\t \t\t\t<td><p><font
88
+ color=\"black\">Waybill Number</font></p></td>\r\n\t \t\t\t<td
89
+ align=right><p><font color=\"black\">:</font></p></td>\r\n\t \t\t\t<td><p>ZHLPRY</p></td>\r\n\t
90
+ \ \t\t</tr>\r\n\t \t\t<tr>\r\n\t \t\t\t<td><p><font
91
+ color=\"black\">Tracking #</font></p></td>\r\n\t \t\t\t<td align=right><p><font
92
+ color=\"black\">:</font></p></td>\r\n\t \t\t\t<td><p>16113420</p></td>\r\n\t
93
+ \ \t\t</tr>\t \t\t\r\n\t \t</table>\r\n\t
94
+ \ <!-- \r\n\t <p><font color=\"black\">Waybill Number:&nbsp;</font>ZHLPRY</p>\r\n\t
95
+ \ <p><font color=\"black\">Tracking #&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</font>16113420</p>\r\n\t
96
+ \ -->\r\n\t </div>\r\n\t <div class=\"col2\">\r\n\t
97
+ \ <p><font color=\"black\">Order #:&nbsp;</font>D58500</p>\r\n\t
98
+ \ \r\n\t </div>\r\n\t <div class=\"col3\">\r\n\t
99
+ \ <p><font color=\"black\">Customer Care:&nbsp;</font>\r\n\t \t\t(866)711-3129\r\n\t
100
+ \ </p>\r\n\t\t <p><font color=\"black\">Location:&nbsp;</font>\r\n\t
101
+ \ \tWILSON, NC\r\n\t </p>\r\n\t </div>\r\n\t
102
+ \ </div>\r\n\t <h3>Items</h3>\r\n\t <table width=\"100%\"
103
+ border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"table_details\">\r\n\t
104
+ \ <thead>\r\n\t <tr>\r\n\t <td class=\"col1\">Line</td>\r\n\t
105
+ \ <td class=\"col2\">Quantity</td>\r\n\t <td
106
+ class=\"col3\">Description </td>\r\n\t <td class=\"col4\">Model</td>\r\n\t
107
+ \ <!-- td class=\"col5\">Serial</td-->\r\n\t <td
108
+ class=\"col6\" align=\"right\">Weight</td>\r\n\t <!-- td class=\"col7\"
109
+ align=\"right\">Cubes</td-->\r\n\t </tr>\r\n\t </thead>\r\n\t
110
+ \ \r\n\t\t <tbody>\r\n\t\t <tr>\r\n\t\t
111
+ \ <td class=\"col1\">1</td>\r\n\t\t <td class=\"col2\">1</td>\r\n\t\t
112
+ \ <td class=\"col3\">29232</td>\r\n\t\t <td class=\"col4\">4171</td>\r\n\t\t
113
+ \ <!-- td class=\"col5\"></td-->\r\n\t\t <td
114
+ class=\"col6\" align=\"right\">50.0</td>\r\n\t\t <!-- td class=\"col7\"
115
+ align=\"right\"></td-->\r\n\t\t </tr>\r\n\t\t </tbody>\r\n\t
116
+ \ \r\n\t </table>\r\n\t \r\n\t <h3>Order
117
+ Status</h3>\r\n\t <div class=\"order_status\" id=\"order_status_div\">\r\n
118
+ \ \t\t\r\n \t\t\r\n \t\t\t\r\n \t\t\r\n \t\t\t\r\n
119
+ \ \t\t\t\r\n\t\t\t\t\t\t\r\n \t\t\t\t \r\n\t\t\t \t
120
+ \r\n \t\t\t\t\r\n\t\t\t\t <div class='col'>\r\n\t\t \t\t\t<p><font
121
+ color=\"black\" style=\"text-transform:none\">Pick Up Address:</font><br/>\r\n\t\t
122
+ \ \t\t\t3905 Airport Dr NW<br/>WILSON,&nbsp;NC&nbsp;27896</p>\r\n\t\t\t\t\t
123
+ \ </div>\r\n \t\t\t\t\r\n \t\t\t\t\r\n \t\t\t\t\r\n\t\t\t
124
+ \ \t<div class='col right'>\r\n\t\t\t \r\n\t\t\t \r\n
125
+ \ \t\t\t\t\r\n\t\t\t \r\n\t\t\t \r\n\t\t\t \r\n
126
+ \ \t\t\r\n\t <p><font color=\"black\" style=\"text-transform:none\">Delivery
127
+ Address:</font><br/>\r\n\t 4283 Express Lane<br/>SARASOTA,&nbsp;FL&nbsp;34238</p>\r\n\t
128
+ \ <p><font color=\"black\" style=\"text-transform:none\">Local
129
+ Distribution Center:</font><br/>\r\n\t MXD GROUP (LAKELAND),
130
+ (866)711-1164\r\n\t <!--p><strong>Local Delivery Distribution
131
+ Center:</strong>Staffan Soderstrom</p-->\r\n\t </div>\r\n \t\t\t\r\n
132
+ \ \t\t\r\n\t\t\t \r\n \t\t\r\n \t\t\r\n\t
133
+ \ </div>\r\n\t <h3><span class=\"arrow\"><!-- a href=\"javascript:toggleProgressData()\"><img
134
+ src=\"common/images/arrow_up.jpg\" alt=\"\" id=\"shipProgressImg\"/></a--></span>Shipment
135
+ Progress</h3>\r\n\t <div id=\"progressTable\">\r\n\t <div
136
+ class=\"shipment_progress\" id=\"shipment_progress_div\">\r\n\t <table
137
+ width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"shipment_details_inner\">\r\n\t
138
+ \ <thead>\r\n\t <tr>\r\n\t <td
139
+ width=20%>Date</td>\r\n\t <td width=40%>Activity</td>\r\n\t
140
+ \ <td width=40%>Location</td>\r\n\t </tr>\r\n\t
141
+ \ </thead>\r\n\t </table>\r\n\t \r\n\t
142
+ \ <table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"
143
+ class=\"shipment_details_inner\">\r\n\t <tbody>\r\n\t <!--
144
+ \ Asked to remove this\r\n\t \t -->\r\n\t \r\n\t
145
+ \ \t\r\n\t\t \r\n\t \t\r\n\t <tr
146
+ class=\"last\">\r\n\t <td width=20%>07/31/15</td>\r\n\t <td
147
+ width=40%>\r\n\t \t\r\n\t\t \tSHIPMENT DISPATCHED
148
+ FROM ORIGIN\r\n\t \t\r\n\t \t\r\n\t </td>\r\n\t
149
+ \ <td width=40%>WILSON, NC</td>\r\n\t </tr>\r\n\t
150
+ \ \r\n\t </tbody>\r\n\t\t\t\t</table>\r\n\t\t\t\t</div>\r\n\t
151
+ \ </div>\r\n\t <h3><span class=\"arrow\"><!-- a href=\"javascript:toggleProgressData()\"><img
152
+ src=\"common/images/arrow_up.jpg\" alt=\"\" id=\"shipProgressImg\"/></a--></span>In
153
+ Transit</h3>\r\n\t <div id=\"progressTable\">\r\n\t <div class=\"shipment_progress\"
154
+ id=\"shipment_progress_div\">\r\n\t <table width=\"100%\" border=\"0\"
155
+ cellspacing=\"0\" cellpadding=\"0\" class=\"shipment_details_inner\">\r\n\t
156
+ \ <thead>\r\n\t <tr>\r\n\t <td
157
+ width=20%>Date</td>\r\n\t <td width=40%>Activity</td>\r\n\t
158
+ \ <td width=40%>Location</td>\r\n\t </tr>\r\n\t
159
+ \ </thead>\r\n\t <tbody>\r\n\t \r\n\t
160
+ \ </tbody>\r\n\t\t\t\t</table>\r\n\t\t\t\t</div>\r\n\t </div>\r\n\t
161
+ \ \r\n\t\t\t \r\n\t\t\t \r\n\t </div>\r\n\t \t\t\t
162
+ \ <span class=\"curv\">\r\n\t \t<img src=\"common/images/tracking_details_bottom.jpg\"
163
+ alt=\"\" />\r\n\t </span>\r\n\t \r\n\t </div>\r\n\t &nbsp;\r\n</div>\r\n\t</div><br/>\r\n\r\n\r\n\r\n\r\n\r\n\t\r\n\r\n\r\n<div
164
+ style=\"position:absolute; z-index: 1000;border: 0px solid red;visibility:
165
+ hidden;\" id=\"progressDiv\">\r\n<p style=\"text-shadow:1px -2px 0 rgba(0,0,0,1);font-weight:normal;color:#F2F211;background-color:#3657FF;letter-spacing:1pt;word-spacing:0pt;font-size:18px;text-align:left;font-family:lucida
166
+ sans unicode, lucida grande, sans-serif;line-height:1;\">\r\nSubmitting...please
167
+ wait...\r\n</p>\r\n</div>\r\n</body>\r\n</html>\r\n"
168
+ http_version:
169
+ recorded_at: Mon, 03 Aug 2015 21:15:18 GMT
170
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,55 @@
1
+ module MxdTracker
2
+ module Mxd
3
+
4
+ BASE_URL = "http://www.homedirectusa.com/hdusaoms/trackShipmentBy"
5
+
6
+ def self.shipment_status(tracking_hash={})
7
+ attribute_info = attribute_information(tracking_hash)
8
+ path = attribute_info[:path]
9
+ MxdTracker::Scraper.get_status(path, tracking_hash[:zip_code])
10
+ end
11
+
12
+ def self.attribute_information(tracking_hash)
13
+ raise "No ZipCode" if missing_key_attributes(tracking_hash)
14
+ zip_code = tracking_hash[:zip_code]
15
+ info = {}
16
+ info[:tracking_attribute] = get_tracking_attribute(tracking_hash)
17
+ value = tracking_hash[info[:tracking_attribute]]
18
+ info[:path] = construct_path(info[:tracking_attribute], value, zip_code)
19
+ info
20
+ end
21
+
22
+ private
23
+
24
+ def self.construct_path(tracking_attribute, value, zip_code)
25
+ if tracking_attribute == :tracking_number
26
+ "/trackShipmentByIdAndZipOnly.htm?trackingId=#{value}&zip_code=#{zip_code}"
27
+ elsif tracking_attribute == :waybill_number
28
+ "/trackShipmentByWbAndZipOnly.htm?wayBill=#{value}&zip_code=#{zip_code}"
29
+ elsif tracking_attribute == :order_number
30
+ "/trackShipmentByRefAndZip.htm?refno=#{value}&zip_code=#{zip_code}"
31
+ else
32
+ "/trackShipmentByPhoneAndZip.htm?zip=#{zip_code}&phone=#{value}"
33
+ end
34
+ end
35
+
36
+ def self.missing_key_attributes(tracking_hash)
37
+ tracking_hash.empty? || !tracking_hash.key?(:zip_code)
38
+ end
39
+
40
+ def self.get_tracking_attribute(tracking_hash)
41
+ if tracking_hash.key?(:tracking_number)
42
+ return :tracking_number
43
+ elsif tracking_hash.key?(:waybill_number)
44
+ return :waybill_number
45
+ elsif tracking_hash.key?(:order_number)
46
+ return :order_number
47
+ elsif tracking_hash.key?(:phone_number)
48
+ return :phone_number
49
+ else
50
+ raise "No valid attribute to search on"
51
+ end
52
+ end
53
+
54
+ end
55
+ end
@@ -0,0 +1,71 @@
1
+ require 'wombat'
2
+ require "sanitize"
3
+
4
+ module MxdTracker
5
+ module Scraper
6
+
7
+ def self.get_status(path, zip_code)
8
+ data = scrape(path)
9
+ sanitize_data(data, zip_code)
10
+ end
11
+
12
+ def self.sanitize_data(data, zip_code)
13
+ current_status = data["current_status"]
14
+ if current_status != "" && current_status.present? && !current_status.nil?
15
+ status = current_status.split(":").first.strip
16
+ date = current_status.split(": ").last.split(", ").last.strip
17
+ conv_date = convert_time_to_utc(date, zip_code)
18
+ data["current_status"] = "#{status}: #{conv_date}"
19
+ end
20
+ progress_detail = data["progress_detail"]
21
+ if progress_detail != "" && progress_detail.present? && !progress_detail.nil?
22
+ data["progress_details"].each do |progress_detail|
23
+ progress_detail["date"] = convert_time_to_utc(progress_detail['date'], zip_code)
24
+ end
25
+ end
26
+ if data["error"].nil? || data["error"] == ""
27
+ data["order_number"] = clean_up_strings(data["order_number"])
28
+ data["delivery_address"] = clean_up_strings(data["delivery_address"])
29
+ data["pick_up_address"] = clean_up_strings(data["pick_up_address"])
30
+ end
31
+ data
32
+ end
33
+
34
+ private
35
+ def self.clean_up_strings(str)
36
+ str.split.join(" ").split(":").last.gsub(/\A\p{Space}*/, '')
37
+ end
38
+
39
+ def self.convert_time_to_utc(date, zip_code)
40
+ MxdTracker::TimeConverter.convert_time_to_utc(date, zip_code)
41
+ end
42
+
43
+ def self.scrape(url_path)
44
+ tracked_page = Wombat.crawl do
45
+ base_url "http://www.homedirectusa.com/hdusaoms"
46
+ path url_path
47
+ error "css=#body_mxdcontainerTrack h3", :html
48
+ current_status "css=.progress_details .delivered", :html do |status|
49
+ Sanitize.fragment(status).strip
50
+ end
51
+ waybill_number "css=.reference_information .col tr:nth-child(1) td:nth-child(3) p", :html do |waybill|
52
+ Sanitize.fragment(waybill)
53
+ end
54
+ tracking_number "css=.reference_information .col tr:nth-child(2) td:nth-child(3) p", :html
55
+ order_number "css=.reference_information .col2 p"
56
+ progress_details "css=.shipment_details_inner tbody tr", :iterator do |details|
57
+ date "css=td:nth-child(1)"
58
+ activity "css=td:nth-child(2)"
59
+ location "css=td:nth-child(3)"
60
+ end
61
+ pick_up_address "css=#order_status_div .col p", :html do |address|
62
+ Sanitize.fragment(address).strip
63
+ end
64
+ delivery_address "css=#order_status_div .col.right p:nth-child(1)", :html do |address|
65
+ Sanitize.fragment(address).strip
66
+ end
67
+ end
68
+ end
69
+
70
+ end
71
+ end
@@ -0,0 +1,14 @@
1
+ require 'tzip'
2
+ require 'timeliness'
3
+
4
+ module MxdTracker
5
+ module TimeConverter
6
+
7
+ def self.convert_time_to_utc(date, zip_code)
8
+ time_zone = ActiveSupport::TimeZone.find_by_zipcode(zip_code)
9
+ date_time = Timeliness.parse(date, :zone => time_zone)
10
+ date_time.utc
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module MxdTracker
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,6 @@
1
+ require "mxd_tracker/version"
2
+ require "mxd_tracker/mxd"
3
+ require "mxd_tracker/scraper"
4
+ require "mxd_tracker/time_converter"
5
+
6
+ require 'active_support/all'
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mxd_tracker/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mxd_tracker"
8
+ spec.version = MxdTracker::VERSION
9
+ spec.authors = ["Eddie Salazar"]
10
+ spec.email = ["eddie.salazar@gmail.com"]
11
+
12
+ spec.summary = %q{Get tracking information for MXD}
13
+ spec.description = %q{This gem allows you to get shipment data for MXD carriers.}
14
+ spec.homepage = "https://github.com/dotandbo/mxd-tracking"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.10"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.3"
25
+ spec.add_development_dependency "wombat", "~> 2.4"
26
+ spec.add_development_dependency "sanitize", "~> 4.0"
27
+ spec.add_development_dependency "tzip", "~> 0.0.4"
28
+ spec.add_development_dependency "timeliness", "~>0.3"
29
+ spec.add_development_dependency "vcr", "~> 2.9"
30
+ spec.add_development_dependency "webmock", "~> 1.21"
31
+ spec.add_development_dependency 'binding_of_caller'
32
+ spec.add_development_dependency 'pry'
33
+ end
metadata ADDED
@@ -0,0 +1,215 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mxd_tracker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Eddie Salazar
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-08-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: wombat
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.4'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sanitize
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '4.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '4.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: tzip
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.0.4
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.0.4
97
+ - !ruby/object:Gem::Dependency
98
+ name: timeliness
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.3'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.3'
111
+ - !ruby/object:Gem::Dependency
112
+ name: vcr
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '2.9'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '2.9'
125
+ - !ruby/object:Gem::Dependency
126
+ name: webmock
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '1.21'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '1.21'
139
+ - !ruby/object:Gem::Dependency
140
+ name: binding_of_caller
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: pry
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ description: This gem allows you to get shipment data for MXD carriers.
168
+ email:
169
+ - eddie.salazar@gmail.com
170
+ executables: []
171
+ extensions: []
172
+ extra_rdoc_files: []
173
+ files:
174
+ - ".gitignore"
175
+ - ".rspec"
176
+ - ".travis.yml"
177
+ - CODE_OF_CONDUCT.md
178
+ - Gemfile
179
+ - LICENSE.txt
180
+ - README.md
181
+ - Rakefile
182
+ - bin/console
183
+ - bin/setup
184
+ - fixtures/vcr_cassettes/mxd_tracking_info.yml
185
+ - lib/mxd_tracker.rb
186
+ - lib/mxd_tracker/mxd.rb
187
+ - lib/mxd_tracker/scraper.rb
188
+ - lib/mxd_tracker/time_converter.rb
189
+ - lib/mxd_tracker/version.rb
190
+ - mxd_tracker.gemspec
191
+ homepage: https://github.com/dotandbo/mxd-tracking
192
+ licenses:
193
+ - MIT
194
+ metadata: {}
195
+ post_install_message:
196
+ rdoc_options: []
197
+ require_paths:
198
+ - lib
199
+ required_ruby_version: !ruby/object:Gem::Requirement
200
+ requirements:
201
+ - - ">="
202
+ - !ruby/object:Gem::Version
203
+ version: '0'
204
+ required_rubygems_version: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ requirements: []
210
+ rubyforge_project:
211
+ rubygems_version: 2.4.8
212
+ signing_key:
213
+ specification_version: 4
214
+ summary: Get tracking information for MXD
215
+ test_files: []