@@ -13,9 +13,11 @@ module Agents |
||
| 13 | 13 |
You can use this agent to retrieve tracking data. You have to provide a specific `get` request and its associated option. |
| 14 | 14 |
|
| 15 | 15 |
To get all trackings for your packages please enter `get` for key and `trackings` for the option. |
| 16 |
- To get tracking for a specific tracking number, add the extra options `slug`, `tracking_number` and set `single_tracking_request` to true. |
|
| 16 |
+ To get tracking for a specific tracking number, add the extra keys `slug`, `tracking_number` and its associated values. |
|
| 17 | 17 |
|
| 18 |
- To get the last checkpoint of a package set key to `get` and option to `last_checkpoint` plus provide `slug` and `tracking_number` |
|
| 18 |
+ Set `single_tracking_request` to true as well. |
|
| 19 |
+ |
|
| 20 |
+ To get the last checkpoint of a package set key to `get` and option to `last_checkpoint`. Please provide `slug` and `tracking_number` |
|
| 19 | 21 |
|
| 20 | 22 |
`slug` is a unique courier code. |
| 21 | 23 |
|
@@ -24,7 +26,7 @@ module Agents |
||
| 24 | 26 |
Required Options: |
| 25 | 27 |
|
| 26 | 28 |
* `api_key` - YOUR_API_KEY. |
| 27 |
- * `get/delete and its associated options` |
|
| 29 |
+ * `get and its associated options` |
|
| 28 | 30 |
MD |
| 29 | 31 |
|
| 30 | 32 |
event_description <<-MD |
@@ -0,0 +1,184 @@ |
||
| 1 |
+{
|
|
| 2 |
+ "meta": {
|
|
| 3 |
+ "code": 200 |
|
| 4 |
+ }, |
|
| 5 |
+ "data": {
|
|
| 6 |
+ "tracking": {
|
|
| 7 |
+ "id": "56e6d14a547de4720d9eca7a", |
|
| 8 |
+ "created_at": "2016-03-14T14:57:14+00:00", |
|
| 9 |
+ "updated_at": "2016-03-15T14:01:05+00:00", |
|
| 10 |
+ "last_updated_at": "2016-03-15T14:01:05+00:00", |
|
| 11 |
+ "tracking_number": "9361289684090010005054", |
|
| 12 |
+ "slug": "usps", |
|
| 13 |
+ "active": false, |
|
| 14 |
+ "android": [ |
|
| 15 |
+ |
|
| 16 |
+ ], |
|
| 17 |
+ "custom_fields": null, |
|
| 18 |
+ "customer_name": null, |
|
| 19 |
+ "delivery_time": 2, |
|
| 20 |
+ "destination_country_iso3": null, |
|
| 21 |
+ "emails": [ |
|
| 22 |
+ |
|
| 23 |
+ ], |
|
| 24 |
+ "expected_delivery": "2016-03-15", |
|
| 25 |
+ "ios": [ |
|
| 26 |
+ |
|
| 27 |
+ ], |
|
| 28 |
+ "note": null, |
|
| 29 |
+ "order_id": null, |
|
| 30 |
+ "order_id_path": null, |
|
| 31 |
+ "origin_country_iso3": "USA", |
|
| 32 |
+ "shipment_package_count": 1, |
|
| 33 |
+ "shipment_pickup_date": "2016-03-13T19:35:00", |
|
| 34 |
+ "shipment_delivery_date": "2016-03-15T08:59:00", |
|
| 35 |
+ "shipment_type": "Parcel Select", |
|
| 36 |
+ "shipment_weight": null, |
|
| 37 |
+ "shipment_weight_unit": null, |
|
| 38 |
+ "signed_by": null, |
|
| 39 |
+ "smses": [ |
|
| 40 |
+ |
|
| 41 |
+ ], |
|
| 42 |
+ "source": "api", |
|
| 43 |
+ "tag": "Delivered", |
|
| 44 |
+ "title": "9361289684090010005054", |
|
| 45 |
+ "tracked_count": 13, |
|
| 46 |
+ "unique_token": "EJjDgTkTl", |
|
| 47 |
+ "checkpoints": [ |
|
| 48 |
+ {
|
|
| 49 |
+ "slug": "usps", |
|
| 50 |
+ "city": "BALTIMORE", |
|
| 51 |
+ "created_at": "2016-03-14T14:57:14+00:00", |
|
| 52 |
+ "location": "BALTIMORE, MD, 21224", |
|
| 53 |
+ "country_name": null, |
|
| 54 |
+ "message": "Picked Up by Shipping Partner", |
|
| 55 |
+ "country_iso3": null, |
|
| 56 |
+ "tag": "InTransit", |
|
| 57 |
+ "checkpoint_time": "2016-03-13T19:35:00", |
|
| 58 |
+ "coordinates": [ |
|
| 59 |
+ |
|
| 60 |
+ ], |
|
| 61 |
+ "state": "MD", |
|
| 62 |
+ "zip": "21224" |
|
| 63 |
+ }, |
|
| 64 |
+ {
|
|
| 65 |
+ "slug": "usps", |
|
| 66 |
+ "city": "BALTIMORE", |
|
| 67 |
+ "created_at": "2016-03-14T14:57:14+00:00", |
|
| 68 |
+ "location": "BALTIMORE, MD, 21224", |
|
| 69 |
+ "country_name": null, |
|
| 70 |
+ "message": "Departed Shipping Partner Facility", |
|
| 71 |
+ "country_iso3": null, |
|
| 72 |
+ "tag": "InTransit", |
|
| 73 |
+ "checkpoint_time": "2016-03-13T23:16:00", |
|
| 74 |
+ "coordinates": [ |
|
| 75 |
+ |
|
| 76 |
+ ], |
|
| 77 |
+ "state": "MD", |
|
| 78 |
+ "zip": "21224" |
|
| 79 |
+ }, |
|
| 80 |
+ {
|
|
| 81 |
+ "slug": "usps", |
|
| 82 |
+ "city": "STOUGHTON", |
|
| 83 |
+ "created_at": "2016-03-15T08:00:54+00:00", |
|
| 84 |
+ "location": "STOUGHTON, MA, 02072", |
|
| 85 |
+ "country_name": null, |
|
| 86 |
+ "message": "Departed Shipping Partner Facility", |
|
| 87 |
+ "country_iso3": null, |
|
| 88 |
+ "tag": "InTransit", |
|
| 89 |
+ "checkpoint_time": "2016-03-15T00:11:00", |
|
| 90 |
+ "coordinates": [ |
|
| 91 |
+ |
|
| 92 |
+ ], |
|
| 93 |
+ "state": "MA", |
|
| 94 |
+ "zip": "02072" |
|
| 95 |
+ }, |
|
| 96 |
+ {
|
|
| 97 |
+ "slug": "usps", |
|
| 98 |
+ "city": null, |
|
| 99 |
+ "created_at": "2016-03-15T08:00:54+00:00", |
|
| 100 |
+ "location": null, |
|
| 101 |
+ "country_name": null, |
|
| 102 |
+ "message": "Pre-Shipment Info Sent to USPS", |
|
| 103 |
+ "country_iso3": null, |
|
| 104 |
+ "tag": "InfoReceived", |
|
| 105 |
+ "checkpoint_time": "2016-03-15T00:11:00", |
|
| 106 |
+ "coordinates": [ |
|
| 107 |
+ |
|
| 108 |
+ ], |
|
| 109 |
+ "state": null, |
|
| 110 |
+ "zip": null |
|
| 111 |
+ }, |
|
| 112 |
+ {
|
|
| 113 |
+ "slug": "usps", |
|
| 114 |
+ "city": "QUINCY", |
|
| 115 |
+ "created_at": "2016-03-15T10:00:57+00:00", |
|
| 116 |
+ "location": "QUINCY, MA, 02169", |
|
| 117 |
+ "country_name": null, |
|
| 118 |
+ "message": "Accepted at USPS Destination Facility", |
|
| 119 |
+ "country_iso3": null, |
|
| 120 |
+ "tag": "InTransit", |
|
| 121 |
+ "checkpoint_time": "2016-03-15T04:14:00", |
|
| 122 |
+ "coordinates": [ |
|
| 123 |
+ |
|
| 124 |
+ ], |
|
| 125 |
+ "state": "MA", |
|
| 126 |
+ "zip": "02169" |
|
| 127 |
+ }, |
|
| 128 |
+ {
|
|
| 129 |
+ "slug": "usps", |
|
| 130 |
+ "city": "QUINCY", |
|
| 131 |
+ "created_at": "2016-03-15T10:00:57+00:00", |
|
| 132 |
+ "location": "QUINCY, MA, 02169", |
|
| 133 |
+ "country_name": null, |
|
| 134 |
+ "message": "Arrived at Post Office", |
|
| 135 |
+ "country_iso3": null, |
|
| 136 |
+ "tag": "InTransit", |
|
| 137 |
+ "checkpoint_time": "2016-03-15T05:29:00", |
|
| 138 |
+ "coordinates": [ |
|
| 139 |
+ |
|
| 140 |
+ ], |
|
| 141 |
+ "state": "MA", |
|
| 142 |
+ "zip": "02169" |
|
| 143 |
+ }, |
|
| 144 |
+ {
|
|
| 145 |
+ "slug": "usps", |
|
| 146 |
+ "city": "QUINCY", |
|
| 147 |
+ "created_at": "2016-03-15T14:01:00+00:00", |
|
| 148 |
+ "location": "QUINCY, MA, 02169", |
|
| 149 |
+ "country_name": null, |
|
| 150 |
+ "message": "Sorting Complete", |
|
| 151 |
+ "country_iso3": null, |
|
| 152 |
+ "tag": "InTransit", |
|
| 153 |
+ "checkpoint_time": "2016-03-15T08:35:00", |
|
| 154 |
+ "coordinates": [ |
|
| 155 |
+ |
|
| 156 |
+ ], |
|
| 157 |
+ "state": "MA", |
|
| 158 |
+ "zip": "02169" |
|
| 159 |
+ }, |
|
| 160 |
+ {
|
|
| 161 |
+ "slug": "usps", |
|
| 162 |
+ "city": "QUINCY", |
|
| 163 |
+ "created_at": "2016-03-15T14:01:00+00:00", |
|
| 164 |
+ "location": "QUINCY, MA, 02169", |
|
| 165 |
+ "country_name": null, |
|
| 166 |
+ "message": "Delivered, Front Door/Porch", |
|
| 167 |
+ "country_iso3": null, |
|
| 168 |
+ "tag": "Delivered", |
|
| 169 |
+ "checkpoint_time": "2016-03-15T08:59:00", |
|
| 170 |
+ "coordinates": [ |
|
| 171 |
+ |
|
| 172 |
+ ], |
|
| 173 |
+ "state": "MA", |
|
| 174 |
+ "zip": "02169" |
|
| 175 |
+ } |
|
| 176 |
+ ], |
|
| 177 |
+ "tracking_account_number": null, |
|
| 178 |
+ "tracking_destination_country": null, |
|
| 179 |
+ "tracking_key": null, |
|
| 180 |
+ "tracking_postal_code": null, |
|
| 181 |
+ "tracking_ship_date": null |
|
| 182 |
+ } |
|
| 183 |
+ } |
|
| 184 |
+} |
@@ -3,12 +3,17 @@ require 'rails_helper' |
||
| 3 | 3 |
describe Agents::AftershipAgent do |
| 4 | 4 |
before do |
| 5 | 5 |
|
| 6 |
+ stub_request(:get, /trackings/).to_return( |
|
| 7 |
+ :body => File.read(Rails.root.join("spec/data_fixtures/aftership.json")),
|
|
| 8 |
+ :status => 200, |
|
| 9 |
+ :headers => {"Content-Type" => "text/json"}
|
|
| 10 |
+ ) |
|
| 11 |
+ |
|
| 6 | 12 |
@opts = {
|
| 7 | 13 |
"api_key" => '800deeaf-e285-9d62-bc90-j999c1973cc9', |
| 8 | 14 |
"get" => 'trackings', |
| 9 | 15 |
"slug" => 'usps', |
| 10 | 16 |
"tracking_number" => "9361289684090010005054" |
| 11 |
- |
|
| 12 | 17 |
} |
| 13 | 18 |
|
| 14 | 19 |
@checker = Agents::AftershipAgent.new(:name => "tectonic", :options => @opts) |
@@ -25,9 +30,16 @@ describe Agents::AftershipAgent do |
||
| 25 | 30 |
expect(@checker.send(:event_url)).to eq("https://api.aftership.com/v4/trackings")
|
| 26 | 31 |
end |
| 27 | 32 |
|
| 28 |
- it "should generate the correct single or checkpoint tracking url" do |
|
| 33 |
+ it "should generate the correct single tracking url" do |
|
| 34 |
+ @checker.options['single_tracking_request'] = true |
|
| 29 | 35 |
expect(@checker.send(:single_or_checkpoint_tracking_url)).to eq("https://api.aftership.com/v4/trackings/usps/9361289684090010005054")
|
| 30 | 36 |
end |
| 37 |
+ |
|
| 38 |
+ it "should generate the correct checkpoint tracking url" do |
|
| 39 |
+ @checker.options['get'] = 'last_checkpoint' |
|
| 40 |
+ @checker.options['last_checkpoint_request'] = true |
|
| 41 |
+ expect(@checker.send(:single_or_checkpoint_tracking_url)).to eq("https://api.aftership.com/v4/last_checkpoint/usps/9361289684090010005054")
|
|
| 42 |
+ end |
|
| 31 | 43 |
end |
| 32 | 44 |
|
| 33 | 45 |
describe "#that checker should be valid" do |
@@ -51,5 +63,10 @@ describe Agents::AftershipAgent do |
||
| 51 | 63 |
end |
| 52 | 64 |
end |
| 53 | 65 |
|
| 54 |
- describe '#check' |
|
| 66 |
+ describe '#check' do |
|
| 67 |
+ it "should check that initial run creates an event" do |
|
| 68 |
+ @checker.memory[:last_updated_at] = '2016-03-15T14:01:05+00:00' |
|
| 69 |
+ expect { @checker.check }.to change { Event.count }.by(1)
|
|
| 70 |
+ end |
|
| 71 |
+ end |
|
| 55 | 72 |
end |