|
1 | 1 | trackingmore-sdk-ruby |
2 | 2 | ================= |
3 | 3 |
|
4 | | -The Ruby SDK of Tr |
| 4 | +The Ruby SDK of Trackingmore API |
| 5 | + |
| 6 | +Contact: <manage@trackingmore.org> |
| 7 | + |
| 8 | +## Official document |
| 9 | + |
| 10 | +[Document](https://www.trackingmore.com/docs/trackingmore/d5ac362fc3cda-api-quick-start) |
| 11 | + |
| 12 | + |
| 13 | +## Index |
| 14 | +1. [Installation](https://github.com/TrackingMores/trackingmore-sdk-ruby#installation) |
| 15 | +2. [Testing](https://github.com/TrackingMores/trackingmore-sdk-ruby#testing) |
| 16 | +3. [Error Handling](https://github.com/TrackingMores/trackingmore-sdk-ruby#error-handling) |
| 17 | +4. SDK |
| 18 | + 1. [Couriers](https://github.com/TrackingMores/trackingmore-sdk-ruby#couriers) |
| 19 | + 2. [Trackings](https://github.com/TrackingMores/trackingmore-sdk-ruby#trackings) |
| 20 | + 3. [Air Waybill](https://github.com/TrackingMores/trackingmore-sdk-ruby#air-waybill) |
| 21 | + |
| 22 | + |
| 23 | +## Installation |
| 24 | + |
| 25 | +``` |
| 26 | +gem install trackingmore |
| 27 | +``` |
| 28 | + |
| 29 | +## Quick Start |
| 30 | + |
| 31 | +```ruby |
| 32 | +require 'trackingmore' |
| 33 | + |
| 34 | +TrackingMore.api_key = 'you api key' |
| 35 | + |
| 36 | +begin |
| 37 | + response = TrackingMore::Courier.get_all_couriers |
| 38 | + puts response |
| 39 | +rescue TrackingMore::TrackingMoreException => e |
| 40 | + puts "Caught Custom Exception: #{e.message}" |
| 41 | +end |
| 42 | + |
| 43 | +``` |
| 44 | + |
| 45 | +## Testing |
| 46 | +``` |
| 47 | +rspec |
| 48 | +``` |
| 49 | + |
| 50 | +## Error handling |
| 51 | + |
| 52 | +**Throw** by the new SDK client |
| 53 | + |
| 54 | +```ruby |
| 55 | +require 'trackingmore' |
| 56 | + |
| 57 | +TrackingMore.api_key = '' |
| 58 | + |
| 59 | +begin |
| 60 | + response = TrackingMore::Courier.get_all_couriers |
| 61 | + puts response |
| 62 | +rescue TrackingMore::TrackingMoreException => e |
| 63 | + puts "Caught Custom Exception: #{e.message}" |
| 64 | +end |
| 65 | + |
| 66 | +# API Key is missing |
| 67 | +``` |
| 68 | + |
| 69 | +**Throw** by the parameter validation in function |
| 70 | + |
| 71 | +```ruby |
| 72 | +require 'trackingmore' |
| 73 | + |
| 74 | +TrackingMore.api_key = 'you api key' |
| 75 | + |
| 76 | +begin |
| 77 | + params = {"tracking_number" => ""} |
| 78 | + response = TrackingMore::Courier.detect(params) |
| 79 | + puts response |
| 80 | +rescue TrackingMore::TrackingMoreException => e |
| 81 | + puts "Caught Custom Exception: #{e.message}" |
| 82 | +end |
| 83 | + |
| 84 | +# Tracking number cannot be empty |
| 85 | +``` |
| 86 | +## Examples |
| 87 | + |
| 88 | +## Couriers |
| 89 | +##### Return a list of all supported couriers. |
| 90 | +https://api.trackingmore.com/v4/couriers/all |
| 91 | +```ruby |
| 92 | +begin |
| 93 | + response = TrackingMore::Courier.get_all_couriers |
| 94 | + puts response |
| 95 | +rescue TrackingMore::TrackingMoreException => e |
| 96 | + puts "Caught Custom Exception: #{e.message}" |
| 97 | +end |
| 98 | +``` |
| 99 | + |
| 100 | +##### Return a list of matched couriers based on submitted tracking number. |
| 101 | +https://api.trackingmore.com/v4/couriers/detect |
| 102 | +```ruby |
| 103 | +begin |
| 104 | + params = {"tracking_number" => "92612903029511573030094547"} |
| 105 | + response = TrackingMore::Courier.detect(params) |
| 106 | + puts response |
| 107 | +rescue TrackingMore::TrackingMoreException => e |
| 108 | + puts "Caught Custom Exception: #{e.message}" |
| 109 | +end |
| 110 | +``` |
| 111 | + |
| 112 | +## Trackings |
| 113 | +##### Create a tracking. |
| 114 | +https://api.trackingmore.com/v4/trackings/create |
| 115 | +```ruby |
| 116 | +begin |
| 117 | + params = {"tracking_number" => "92612913029511573130094547","courier_code"=>"usps"} |
| 118 | + response = TrackingMore::Tracking.create_tracking(params) |
| 119 | + puts response |
| 120 | +rescue TrackingMore::TrackingMoreException => e |
| 121 | + puts "Caught Custom Exception: #{e.message}" |
| 122 | +end |
| 123 | +``` |
| 124 | + |
| 125 | +##### Get tracking results of multiple trackings. |
| 126 | +https://api.trackingmore.com/v4/trackings/get |
| 127 | +```ruby |
| 128 | +begin |
| 129 | + # Perform queries based on various conditions |
| 130 | + # params = {"tracking_numbers" => "92612903029511573130094547","courier_code"=>"usps"} |
| 131 | + # params = {"tracking_numbers" => "92612903029511573130094547,92612903029511573030094548","courier_code"=>"usps"} |
| 132 | + params = {"created_date_min" => "2023-08-23T14:00:00+08:00","created_date_max"=>"2023-08-23T15:04:00+08:00"} |
| 133 | + response = TrackingMore::Tracking.get_tracking_results(params) |
| 134 | + puts response |
| 135 | +rescue TrackingMore::TrackingMoreException => e |
| 136 | + puts "Caught Custom Exception: #{e.message}" |
| 137 | +end |
| 138 | +``` |
| 139 | + |
| 140 | +##### Create multiple trackings (Max. 40 tracking numbers create in one call). |
| 141 | +https://api.trackingmore.com/v4/trackings/batch |
| 142 | +```ruby |
| 143 | +begin |
| 144 | + params = [{"tracking_number" => "92612903029611573130094547","courier_code"=>"usps"},{"tracking_number" => "92612903029711573130094547","courier_code"=>"usps"}] |
| 145 | + response = TrackingMore::Tracking.batch_create_trackings(params) |
| 146 | + puts response |
| 147 | +rescue TrackingMore::TrackingMoreException => e |
| 148 | + puts "Caught Custom Exception: #{e.message}" |
| 149 | +end |
| 150 | +``` |
| 151 | + |
| 152 | +##### Update a tracking by ID. |
| 153 | +https://api.trackingmore.com/v4/trackings/update/{id} |
| 154 | +```ruby |
| 155 | +begin |
| 156 | + params = {"customer_name" => "New name","note"=>"New tests order note"} |
| 157 | + id_string = '9a3aec583781c7096cf744d68287d3d1' |
| 158 | + response = TrackingMore::Tracking.update_tracking_by_id(id_string, params) |
| 159 | + puts response |
| 160 | +rescue TrackingMore::TrackingMoreException => e |
| 161 | + puts "Caught Custom Exception: #{e.message}" |
| 162 | +end |
| 163 | +``` |
| 164 | + |
| 165 | +##### Delete a tracking by ID. |
| 166 | +https://api.trackingmore.com/v4/trackings/delete/{id} |
| 167 | +```ruby |
| 168 | +begin |
| 169 | + id_string = '9a3aec583781c7096cf744d68287d3d1' |
| 170 | + response = TrackingMore::Tracking.delete_tracking_by_id(id_string) |
| 171 | + puts response |
| 172 | +rescue TrackingMore::TrackingMoreException => e |
| 173 | + puts "Caught Custom Exception: #{e.message}" |
| 174 | +end |
| 175 | +``` |
| 176 | + |
| 177 | +##### Retrack expired tracking by ID. |
| 178 | +https://api.trackingmore.com/v4/trackings/retrack/{id} |
| 179 | +```ruby |
| 180 | +begin |
| 181 | + id_string = '9a3aec583781c7096cf744d68287d3d1' |
| 182 | + response = TrackingMore::Tracking.retrack_tracking_by_id(id_string) |
| 183 | + puts response |
| 184 | +rescue TrackingMore::TrackingMoreException => e |
| 185 | + puts "Caught Custom Exception: #{e.message}" |
| 186 | +end |
| 187 | +``` |
| 188 | +## Air Waybill |
| 189 | +##### Create an air waybill. |
| 190 | +https://api.trackingmore.com/v4/awb |
| 191 | +```ruby |
| 192 | +begin |
| 193 | + params = {"awb_number" => "235-69030430"} |
| 194 | + response = TrackingMore::AirWaybill.create_an_air_waybill(params) |
| 195 | + puts response |
| 196 | +rescue TrackingMore::TrackingMoreException => e |
| 197 | + puts "Caught Custom Exception: #{e.message}" |
| 198 | +end |
| 199 | +``` |
| 200 | + |
| 201 | +## Response Code |
| 202 | + |
| 203 | +Trackingmore uses conventional HTTP response codes to indicate success or failure of an API request. In general, codes in the 2xx range indicate success, codes in the 4xx range indicate an error that resulted from the provided information (e.g. a required parameter was missing, a charge failed, etc.), and codes in the 5xx range indicate an TrackingMore's server error. |
| 204 | + |
| 205 | + |
| 206 | +Http CODE|META CODE|TYPE | MESSAGE |
| 207 | +----|-----|--------------|------------------------------- |
| 208 | +200 |200 | <code>Success</code> | Request response is successful |
| 209 | +400 |400 | <code>BadRequest</code> | Request type error. Please check the API documentation for the request type of this API. |
| 210 | +400 |4101 | <code>BadRequest</code> | Tracking No. already exists. |
| 211 | +400 |4102 | <code>BadRequest</code> | Tracking No. no exists. Please use 「Create a tracking」 API first to create shipment. |
| 212 | +400 |4103 | <code>BadRequest</code> | You have exceeded the shipment quantity of API call. The maximum quantity is 40 shipments per call. |
| 213 | +400 |4110 | <code>BadRequest</code> | The value of tracking_number is invalid. |
| 214 | +400 |4111 | <code>BadRequest</code> | Tracking_number is required. |
| 215 | +400 |4112 | <code>BadRequest</code> | Invalid Tracking ID. |
| 216 | +400 |4113 | <code>BadRequest</code> | Retrack is not allowed. You can only retrack an expired tracking. |
| 217 | +400 |4120 | <code>BadRequest</code> | The value of courier_code is invalid. |
| 218 | +400 |4121 | <code>BadRequest</code> | Cannot detect courier. |
| 219 | +400 |4122 | <code>BadRequest</code> | Missing or invalid value of the special required fields for this courier. |
| 220 | +400 |4130 | <code>BadRequest</code> | The format of Field name is invalid. |
| 221 | +400 |4160 | <code>BadRequest</code> | The awb_number is required or invaild format. |
| 222 | +400 |4161 | <code>BadRequest</code> | The awb airline does not support yet. |
| 223 | +400 |4190 | <code>BadRequest</code> | You are reaching the maximum quota limitation, please upgrade your current plan. |
| 224 | +401 |401 | <code>Unauthorized</code> | Authentication failed or has no permission. Please check and ensure your API Key is correct. |
| 225 | +403 |403 | <code>Forbidden</code> | Access prohibited. The request has been refused or access is not allowed. |
| 226 | +404 |404 | <code>NotFound</code> | Page does not exist. Please check and ensure your link is correct. |
| 227 | +429 |429 | <code>TooManyRequests</code>| Exceeded API request limits, please try again later. Please check the API documentation for the limit of this API. |
| 228 | +500 |511 | <code>ServerError</code> | Server error. Please contact us: service@trackingmore.org. |
| 229 | +500 |512 | <code>ServerError</code> | Server error. Please contact us: service@trackingmore.org. |
| 230 | +500 |513 | <code>ServerError</code> | Server error. Please contact us: service@trackingmore.org. |
0 commit comments