package_tracker 0.0.2

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,66 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe 'FedEx' do
4
+ before do
5
+ @valid_credentials = {:key => "1111", :password => "2222", :account => "3333", :meter => "4444"}
6
+ @invalid_credentials = {:key => "5555", :password => "6666", :account => "7777", :meter => "8888"}
7
+ @valid_tracking_number = "999999999999"
8
+ @invalid_tracking_number = "000000000000"
9
+
10
+ @client = PackageTracker::Client.new(:fedex => @valid_credentials)
11
+ @invalid_credentials_client = PackageTracker::Client.new(:fedex => @invalid_credentials)
12
+
13
+ stub_request(:post, "https://gateway.fedex.com/xml")
14
+ .with(:body => PackageTracker::Carriers::FedEx.send(:request_data, @valid_tracking_number, @valid_credentials))
15
+ .to_return(:body => File.new("spec/fixtures/responses/fedex/valid.xml"), :status => 200)
16
+
17
+ stub_request(:post, "https://gateway.fedex.com/xml")
18
+ .with(:body => PackageTracker::Carriers::FedEx.send(:request_data, @valid_tracking_number, @invalid_credentials))
19
+ .to_return(:body => File.new("spec/fixtures/responses/fedex/invalid_credentials.xml"), :status => 200)
20
+
21
+ stub_request(:post, "https://gateway.fedex.com/xml")
22
+ .with(:body => PackageTracker::Carriers::FedEx.send(:request_data, @invalid_tracking_number, @valid_credentials))
23
+ .to_return(:body => File.new("spec/fixtures/responses/fedex/invalid_tracking_number.xml"), :status => 200)
24
+
25
+ stub_request(:post, "https://gatewaybeta.fedex.com/xml")
26
+ .to_return(:body => File.new("spec/fixtures/responses/fedex/valid.xml"), :status => 200)
27
+ end
28
+
29
+ it 'should send requests to the test server in test mode' do
30
+ test_client = PackageTracker::Client.new(:fedex => @valid_credentials)
31
+ test_client.test_mode!
32
+ test_client.track(@valid_tracking_number)
33
+ WebMock.should have_requested(:post, "https://gatewaybeta.fedex.com/xml")
34
+ end
35
+
36
+ it 'should send requests to the live server in production mode' do
37
+ @client.track(@valid_tracking_number)
38
+ WebMock.should have_requested(:post, "https://gateway.fedex.com/xml")
39
+ end
40
+
41
+ it 'should raise an error with missing credentials' do
42
+ lambda { PackageTracker::Client.new(:fedex => {:key => "1111"}).track(@valid_tracking_number) }.should raise_error(PackageTracker::MissingCredentialsError)
43
+ lambda { PackageTracker::Client.new(:fedex => {:password => "2222"}).track(@valid_tracking_number) }.should raise_error(PackageTracker::MissingCredentialsError)
44
+ lambda { PackageTracker::Client.new(:fedex => {:account => "3333"}).track(@valid_tracking_number) }.should raise_error(PackageTracker::MissingCredentialsError)
45
+ lambda { PackageTracker::Client.new(:fedex => {:meter => "4444"}).track(@valid_tracking_number) }.should raise_error(PackageTracker::MissingCredentialsError)
46
+
47
+ lambda { @client.track(@valid_tracking_number) }.should_not raise_error(PackageTracker::MissingCredentialsError)
48
+ end
49
+
50
+ it 'should raise an error with invalid credentials' do
51
+ lambda { @invalid_credentials_client.track(@valid_tracking_number) }.should raise_error(PackageTracker::InvalidCredentialsError)
52
+ end
53
+
54
+ it 'should raise an error when an invalid tracking number is supplied' do
55
+ lambda { @client.track(@invalid_tracking_number) }.should raise_error(PackageTracker::InvalidTrackingNumberError)
56
+ end
57
+
58
+ it 'should return a response object' do
59
+ response = @client.track(@valid_tracking_number)
60
+ response.should be_an_instance_of(PackageTracker::Response)
61
+ end
62
+
63
+ it 'should return the correct number of statuses' do
64
+ @client.track(@valid_tracking_number).statuses.length.should == 8
65
+ end
66
+ end
@@ -0,0 +1,75 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe "UPS" do
4
+ before do
5
+ @valid_credentials = {:user_id => "1111", :password => "2222", :key => "3333"}
6
+ @invalid_credentials = {:user_id => "4444", :password => "5555", :key => "6666"}
7
+ @valid_tracking_number = "1ZA2552X0397250131"
8
+ @invalid_tracking_number = "1ZA2552X0397250132"
9
+
10
+ @client = PackageTracker::Client.new(:ups => @valid_credentials)
11
+ @invalid_credentials_client = PackageTracker::Client.new(:ups => @invalid_credentials)
12
+
13
+ stub_request(:post, "http://www.ups.com/ups.app/xml/Track")
14
+ .with(:body => PackageTracker::Carriers::UPS.send(:request_data, @valid_tracking_number, @valid_credentials))
15
+ .to_return(:body => File.new("spec/fixtures/responses/ups/valid.xml"), :status => 200)
16
+
17
+ stub_request(:post, "http://www.ups.com/ups.app/xml/Track")
18
+ .with(:body => PackageTracker::Carriers::UPS.send(:request_data, @valid_tracking_number, @invalid_credentials))
19
+ .to_return(:body => File.new("spec/fixtures/responses/ups/invalid_credentials.xml"), :status => 200)
20
+
21
+ stub_request(:post, "http://www.ups.com/ups.app/xml/Track")
22
+ .with(:body => PackageTracker::Carriers::UPS.send(:request_data, @invalid_tracking_number, @valid_credentials))
23
+ .to_return(:body => File.new("spec/fixtures/responses/ups/invalid_tracking_number.xml"), :status => 200)
24
+
25
+ stub_request(:post, "http://wwwcie.ups.com/ups.app/xml/Track")
26
+ .to_return(:body => File.new("spec/fixtures/responses/ups/valid.xml"), :status => 200)
27
+ end
28
+
29
+ it 'should send requests to the test server when in test mode' do
30
+ test_client = PackageTracker::Client.new(:ups => @valid_credentials)
31
+ test_client.test_mode!
32
+ test_client.track(@valid_tracking_number)
33
+ WebMock.should have_requested(:post, "http://wwwcie.ups.com/ups.app/xml/Track")
34
+ end
35
+
36
+ it 'should send requests to the live server when in production mode' do
37
+ @client.track(@valid_tracking_number)
38
+ WebMock.should have_requested(:post, "http://www.ups.com/ups.app/xml/Track")
39
+ end
40
+
41
+ it 'should handle missing credentials' do
42
+ lambda { PackageTracker::Client.new(:ups => {:user_id => "1111"}).track(@valid_tracking_number) }.should raise_error(PackageTracker::MissingCredentialsError)
43
+ lambda { PackageTracker::Client.new(:ups => {:password => "2222"}).track(@valid_tracking_number) }.should raise_error(PackageTracker::MissingCredentialsError)
44
+ lambda { PackageTracker::Client.new(:ups => {:key => "3333"}).track(@valid_tracking_number) }.should raise_error(PackageTracker::MissingCredentialsError)
45
+
46
+ lambda { @client.track("1ZA2552X0397250131") }.should_not raise_error(PackageTracker::MissingCredentialsError)
47
+ end
48
+
49
+ it 'should handle invalid credentials' do
50
+ lambda { @invalid_credentials_client.track("1ZA2552X0397250131") }.should raise_error(PackageTracker::InvalidCredentialsError)
51
+ end
52
+
53
+ it 'should handle invalid tracking numbers' do
54
+ lambda { @client.track(@invalid_tracking_number) }.should raise_error(PackageTracker::InvalidTrackingNumberError)
55
+ end
56
+
57
+ it 'should properly build the request body' do
58
+ @client.track(@valid_tracking_number)
59
+ # WebMock.should have_requested(:post, "http://www.ups.com/ups.app/xml/Track").with(:body => File.new("spec/fixtures/requests/ups/valid.xml").read)
60
+ pending "Not Exactly sure of the best way to test this"
61
+ end
62
+
63
+ it 'should return a response object' do
64
+ response = @client.track(@valid_tracking_number)
65
+ response.should be_an_instance_of(PackageTracker::Response)
66
+ end
67
+
68
+ it 'should return the correct number of status activities' do
69
+ @client.track(@valid_tracking_number).statuses.length.should == 13
70
+ end
71
+
72
+ it 'should be able to verify delivery' do
73
+ @client.track(@valid_tracking_number).delivered?.should == true
74
+ end
75
+ end
File without changes
@@ -0,0 +1 @@
1
+ <?xmlversion='1.0'?><AccessRequestxml:lang='en-US'><AccessLicenseNumber>6666</AccessLicenseNumber><UserId>4444</UserId><Password>5555</Password></AccessRequest><?xmlversion='1.0'?><TrackRequestxml:lang='en-US'><Request><TransactionReference><XpciVersion>1.0</XpciVersion></TransactionReference><RequestAction>Track</RequestAction><RequestOption>activity</RequestOption></Request><TrackingNumber>1ZA2552X0397250131</TrackingNumber></TrackRequest>
@@ -0,0 +1,17 @@
1
+ <?xml version='1.0'?>
2
+ <AccessRequest xml:lang='en-US'>
3
+ <AccessLicenseNumber>3333</AccessLicenseNumber>
4
+ <UserId>1111</UserId>
5
+ <Password>2222</Password>
6
+ </AccessRequest>
7
+ <?xml version='1.0'?>
8
+ <TrackRequest xml:lang='en-US'>
9
+ <Request>
10
+ <TransactionReference>
11
+ <XpciVersion>1.0</XpciVersion>
12
+ </TransactionReference>
13
+ <RequestAction>Track</RequestAction>
14
+ <RequestOption>activity</RequestOption>
15
+ </Request>
16
+ <TrackingNumber>1ZA2552X0397250132</TrackingNumber>
17
+ </TrackRequest>
@@ -0,0 +1,17 @@
1
+ <?xml version='1.0'?>
2
+ <AccessRequest xml:lang='en-US'>
3
+ <AccessLicenseNumber>3333</AccessLicenseNumber>
4
+ <UserId>1111</UserId>
5
+ <Password>2222</Password>
6
+ </AccessRequest>
7
+ <?xml version='1.0'?>
8
+ <TrackRequest xml:lang='en-US'>
9
+ <Request>
10
+ <TransactionReference>
11
+ <XpciVersion>1.0</XpciVersion>
12
+ </TransactionReference>
13
+ <RequestAction>Track</RequestAction>
14
+ <RequestOption>activity</RequestOption>
15
+ </Request>
16
+ <TrackingNumber>#{tracking_number}</TrackingNumber>
17
+ </TrackRequest>
@@ -0,0 +1,19 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <ns:TrackReply xmlns:ns="http://fedex.com/ws/track/v3">
3
+ <ns:HighestSeverity>ERROR</ns:HighestSeverity>
4
+ <ns:Notifications>
5
+ <ns:Severity>ERROR</ns:Severity>
6
+ <ns:Source>prof</ns:Source>
7
+ <ns:Code>1000</ns:Code>
8
+ <ns:Message>Authentication Failed</ns:Message>
9
+ </ns:Notifications>
10
+ <ns:TransactionDetail>
11
+ <ns:CustomerTransactionId>Package Tracker Ruby Gem</ns:CustomerTransactionId>
12
+ </ns:TransactionDetail>
13
+ <ns:Version>
14
+ <ns:ServiceId>trck</ns:ServiceId>
15
+ <ns:Major>3</ns:Major>
16
+ <ns:Intermediate>0</ns:Intermediate>
17
+ <ns:Minor>0</ns:Minor>
18
+ </ns:Version>
19
+ </ns:TrackReply>
@@ -0,0 +1,22 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <v3:TrackReply xmlns:v3="http://fedex.com/ws/track/v3">
3
+ <v3:HighestSeverity>ERROR</v3:HighestSeverity>
4
+ <v3:Notifications>
5
+ <v3:Severity>ERROR</v3:Severity>
6
+ <v3:Source>trck</v3:Source>
7
+ <v3:Code>9040</v3:Code>
8
+ <v3:Message>No information for the following shipments has been received by our system yet. Please try again or contact Customer Service at 1.800.Go.FedEx(R) 800.463.3339.</v3:Message>
9
+ <v3:LocalizedMessage>No information for the following shipments has been received by our system yet. Please try again or contact Customer Service at 1.800.Go.FedEx(R) 800.463.3339.</v3:LocalizedMessage>
10
+ </v3:Notifications>
11
+ <v3:TransactionDetail>
12
+ <v3:CustomerTransactionId>Package Tracker Ruby Gem</v3:CustomerTransactionId>
13
+ </v3:TransactionDetail>
14
+ <v3:Version>
15
+ <v3:ServiceId>trck</v3:ServiceId>
16
+ <v3:Major>3</v3:Major>
17
+ <v3:Intermediate>0</v3:Intermediate>
18
+ <v3:Minor>0</v3:Minor>
19
+ </v3:Version>
20
+ <v3:DuplicateWaybill>false</v3:DuplicateWaybill>
21
+ <v3:MoreData>false</v3:MoreData>
22
+ </v3:TrackReply>
@@ -0,0 +1,160 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <v3:TrackReply xmlns:v3="http://fedex.com/ws/track/v3">
3
+ <v3:HighestSeverity>SUCCESS</v3:HighestSeverity>
4
+ <v3:Notifications>
5
+ <v3:Severity>SUCCESS</v3:Severity>
6
+ <v3:Source>trck</v3:Source>
7
+ <v3:Code>0</v3:Code>
8
+ <v3:Message>Request was successfully processed.</v3:Message>
9
+ <v3:LocalizedMessage>Request was successfully processed.</v3:LocalizedMessage>
10
+ </v3:Notifications>
11
+ <v3:TransactionDetail>
12
+ <v3:CustomerTransactionId>Package Tracker Ruby Gem</v3:CustomerTransactionId>
13
+ </v3:TransactionDetail>
14
+ <v3:Version>
15
+ <v3:ServiceId>trck</v3:ServiceId>
16
+ <v3:Major>3</v3:Major>
17
+ <v3:Intermediate>0</v3:Intermediate>
18
+ <v3:Minor>0</v3:Minor>
19
+ </v3:Version>
20
+ <v3:DuplicateWaybill>false</v3:DuplicateWaybill>
21
+ <v3:MoreData>false</v3:MoreData>
22
+ <v3:TrackDetails>
23
+ <v3:TrackingNumber>9611804854517911563928</v3:TrackingNumber>
24
+ <v3:TrackingNumberUniqueIdentifier>12010~854517911563928</v3:TrackingNumberUniqueIdentifier>
25
+ <v3:StatusCode>DL</v3:StatusCode>
26
+ <v3:StatusDescription>Delivered</v3:StatusDescription>
27
+ <v3:CarrierCode>FDXG</v3:CarrierCode>
28
+ <v3:OtherIdentifiers>
29
+ <v3:Value>37371076</v3:Value>
30
+ <v3:Type>CUSTOMER_REFERENCE</v3:Type>
31
+ </v3:OtherIdentifiers>
32
+ <v3:OtherIdentifiers>
33
+ <v3:Value>Dn1M27rSR</v3:Value>
34
+ <v3:Type>GROUND_SHIPMENT_ID</v3:Type>
35
+ </v3:OtherIdentifiers>
36
+ <v3:ServiceInfo>FedEx Home Delivery</v3:ServiceInfo>
37
+ <v3:ServiceType>GROUND_HOME_DELIVERY</v3:ServiceType>
38
+ <v3:PackageWeight>
39
+ <v3:Units>LB</v3:Units>
40
+ <v3:Value>26.0</v3:Value>
41
+ </v3:PackageWeight>
42
+ <v3:Packaging>Package</v3:Packaging>
43
+ <v3:PackageSequenceNumber>1</v3:PackageSequenceNumber>
44
+ <v3:PackageCount>1</v3:PackageCount>
45
+ <v3:OriginLocationAddress>
46
+ <v3:City>PHOENIX</v3:City>
47
+ <v3:StateOrProvinceCode>AZ</v3:StateOrProvinceCode>
48
+ <v3:CountryCode>US</v3:CountryCode>
49
+ <v3:Residential>false</v3:Residential>
50
+ </v3:OriginLocationAddress>
51
+ <v3:ShipTimestamp>2010-11-30T00:00:00</v3:ShipTimestamp>
52
+ <v3:DestinationAddress>
53
+ <v3:City>SAN FRANCISCO</v3:City>
54
+ <v3:StateOrProvinceCode>CA</v3:StateOrProvinceCode>
55
+ <v3:CountryCode>US</v3:CountryCode>
56
+ <v3:Residential>false</v3:Residential>
57
+ </v3:DestinationAddress>
58
+ <v3:ActualDeliveryTimestamp>2010-12-03T10:32:38-08:00</v3:ActualDeliveryTimestamp>
59
+ <v3:ActualDeliveryAddress>
60
+ <v3:City>San Francisco</v3:City>
61
+ <v3:StateOrProvinceCode>CA</v3:StateOrProvinceCode>
62
+ <v3:CountryCode>US</v3:CountryCode>
63
+ <v3:Residential>false</v3:Residential>
64
+ </v3:ActualDeliveryAddress>
65
+ <v3:DeliverySignatureName>GELISABETH</v3:DeliverySignatureName>
66
+ <v3:SignatureProofOfDeliveryAvailable>true</v3:SignatureProofOfDeliveryAvailable>
67
+ <v3:Events>
68
+ <v3:Timestamp>2010-12-03T10:32:38-08:00</v3:Timestamp>
69
+ <v3:EventType>DL</v3:EventType>
70
+ <v3:EventDescription>Delivered</v3:EventDescription>
71
+ <v3:Address>
72
+ <v3:City>San Francisco</v3:City>
73
+ <v3:StateOrProvinceCode>CA</v3:StateOrProvinceCode>
74
+ <v3:PostalCode>94105</v3:PostalCode>
75
+ <v3:CountryCode>US</v3:CountryCode>
76
+ <v3:Residential>false</v3:Residential>
77
+ </v3:Address>
78
+ </v3:Events>
79
+ <v3:Events>
80
+ <v3:Timestamp>2010-12-03T03:22:00-08:00</v3:Timestamp>
81
+ <v3:EventType>OD</v3:EventType>
82
+ <v3:EventDescription>On FedEx vehicle for delivery</v3:EventDescription>
83
+ <v3:Address>
84
+ <v3:City>SOUTH SAN FRANCISCO</v3:City>
85
+ <v3:StateOrProvinceCode>CA</v3:StateOrProvinceCode>
86
+ <v3:PostalCode>94080</v3:PostalCode>
87
+ <v3:CountryCode>US</v3:CountryCode>
88
+ <v3:Residential>false</v3:Residential>
89
+ </v3:Address>
90
+ </v3:Events>
91
+ <v3:Events>
92
+ <v3:Timestamp>2010-12-02T21:23:25-08:00</v3:Timestamp>
93
+ <v3:EventType>AR</v3:EventType>
94
+ <v3:EventDescription>At local FedEx facility</v3:EventDescription>
95
+ <v3:Address>
96
+ <v3:City>SOUTH SAN FRANCISCO</v3:City>
97
+ <v3:StateOrProvinceCode>CA</v3:StateOrProvinceCode>
98
+ <v3:PostalCode>94080</v3:PostalCode>
99
+ <v3:CountryCode>US</v3:CountryCode>
100
+ <v3:Residential>false</v3:Residential>
101
+ </v3:Address>
102
+ </v3:Events>
103
+ <v3:Events>
104
+ <v3:Timestamp>2010-12-02T19:02:44-08:00</v3:Timestamp>
105
+ <v3:EventType>DP</v3:EventType>
106
+ <v3:EventDescription>Departed FedEx location</v3:EventDescription>
107
+ <v3:Address>
108
+ <v3:City>SACRAMENTO</v3:City>
109
+ <v3:StateOrProvinceCode>CA</v3:StateOrProvinceCode>
110
+ <v3:PostalCode>95824</v3:PostalCode>
111
+ <v3:CountryCode>US</v3:CountryCode>
112
+ <v3:Residential>false</v3:Residential>
113
+ </v3:Address>
114
+ </v3:Events>
115
+ <v3:Events>
116
+ <v3:Timestamp>2010-12-02T15:57:00-08:00</v3:Timestamp>
117
+ <v3:EventType>AR</v3:EventType>
118
+ <v3:EventDescription>Arrived at FedEx location</v3:EventDescription>
119
+ <v3:Address>
120
+ <v3:City>SACRAMENTO</v3:City>
121
+ <v3:StateOrProvinceCode>CA</v3:StateOrProvinceCode>
122
+ <v3:PostalCode>95824</v3:PostalCode>
123
+ <v3:CountryCode>US</v3:CountryCode>
124
+ <v3:Residential>false</v3:Residential>
125
+ </v3:Address>
126
+ </v3:Events>
127
+ <v3:Events>
128
+ <v3:Timestamp>2010-11-30T14:41:00-07:00</v3:Timestamp>
129
+ <v3:EventType>AR</v3:EventType>
130
+ <v3:EventDescription>Arrived at FedEx location</v3:EventDescription>
131
+ <v3:Address>
132
+ <v3:City>PHOENIX</v3:City>
133
+ <v3:StateOrProvinceCode>AZ</v3:StateOrProvinceCode>
134
+ <v3:PostalCode>85043</v3:PostalCode>
135
+ <v3:CountryCode>US</v3:CountryCode>
136
+ <v3:Residential>false</v3:Residential>
137
+ </v3:Address>
138
+ </v3:Events>
139
+ <v3:Events>
140
+ <v3:Timestamp>2010-11-30T09:53:00-07:00</v3:Timestamp>
141
+ <v3:EventType>PU</v3:EventType>
142
+ <v3:EventDescription>Picked up</v3:EventDescription>
143
+ <v3:Address>
144
+ <v3:City>PHOENIX</v3:City>
145
+ <v3:StateOrProvinceCode>AZ</v3:StateOrProvinceCode>
146
+ <v3:PostalCode>85043</v3:PostalCode>
147
+ <v3:CountryCode>US</v3:CountryCode>
148
+ <v3:Residential>false</v3:Residential>
149
+ </v3:Address>
150
+ </v3:Events>
151
+ <v3:Events>
152
+ <v3:Timestamp>2010-11-30T08:23:00-07:00</v3:Timestamp>
153
+ <v3:EventType>OC</v3:EventType>
154
+ <v3:EventDescription>Shipment information sent to FedEx</v3:EventDescription>
155
+ <v3:Address>
156
+ <v3:Residential>false</v3:Residential>
157
+ </v3:Address>
158
+ </v3:Events>
159
+ </v3:TrackDetails>
160
+ </v3:TrackReply>
@@ -0,0 +1,15 @@
1
+ <?xml version="1.0"?>
2
+ <TrackResponse>
3
+ <Response>
4
+ <TransactionReference>
5
+ <XpciVersion>1.0</XpciVersion>
6
+ </TransactionReference>
7
+ <ResponseStatusCode>0</ResponseStatusCode>
8
+ <ResponseStatusDescription>Failure</ResponseStatusDescription>
9
+ <Error>
10
+ <ErrorSeverity>Hard</ErrorSeverity>
11
+ <ErrorCode>250003</ErrorCode>
12
+ <ErrorDescription>Invalid Access License number</ErrorDescription>
13
+ </Error>
14
+ </Response>
15
+ </TrackResponse>
@@ -0,0 +1,15 @@
1
+ <?xml version="1.0"?>
2
+ <TrackResponse>
3
+ <Response>
4
+ <TransactionReference>
5
+ <XpciVersion>1.0</XpciVersion>
6
+ </TransactionReference>
7
+ <ResponseStatusCode>0</ResponseStatusCode>
8
+ <ResponseStatusDescription>Failure</ResponseStatusDescription>
9
+ <Error>
10
+ <ErrorSeverity>Hard</ErrorSeverity>
11
+ <ErrorCode>151018</ErrorCode>
12
+ <ErrorDescription>Invalid tracking number</ErrorDescription>
13
+ </Error>
14
+ </Response>
15
+ </TrackResponse>