Class: EasyPost::Services::Tracker
- Defined in:
- lib/easypost/services/tracker.rb
Constant Summary collapse
Instance Method Summary collapse
-
#all(params = {}) ⇒ Object
Retrieve a list of Trackers.
-
#create(params = {}) ⇒ Object
Create a Tracker.
-
#create_list(params = {}) ⇒ Object
Create multiple Tracker objects in bulk.
-
#get_next_page(collection, page_size = nil) ⇒ Object
Get the next page of trackers.
-
#retrieve(id) ⇒ Object
Retrieve a Tracker.
Methods inherited from Service
Constructor Details
This class inherits a constructor from EasyPost::Services::Service
Instance Method Details
#all(params = {}) ⇒ Object
Retrieve a list of Trackers
22 23 24 25 26 27 28 29 30 |
# File 'lib/easypost/services/tracker.rb', line 22 def all(params = {}) filters = { key: 'trackers', tracking_code: params[:tracking_code], carrier: params[:carrier], } get_all_helper('trackers', MODEL_CLASS, params, filters) end |
#create(params = {}) ⇒ Object
Create a Tracker
7 8 9 10 11 12 |
# File 'lib/easypost/services/tracker.rb', line 7 def create(params = {}) wrapped_params = { tracker: params } response = @client.make_request(:post, 'trackers', wrapped_params) EasyPost::InternalUtilities::Json.convert_json_to_object(response, MODEL_CLASS) end |
#create_list(params = {}) ⇒ Object
Create multiple Tracker objects in bulk. DEPRECATED: Please use create
instead. This function will be removed in a future release.
34 35 36 37 38 39 |
# File 'lib/easypost/services/tracker.rb', line 34 def create_list(params = {}) wrapped_params = { 'trackers' => params } @client.make_request(:post, 'trackers/create_list', wrapped_params) true # This endpoint does not return a response so we return true here instead end |
#get_next_page(collection, page_size = nil) ⇒ Object
Get the next page of trackers.
42 43 44 45 46 47 48 49 50 |
# File 'lib/easypost/services/tracker.rb', line 42 def get_next_page(collection, page_size = nil) raise EasyPost::Errors::EndOfPaginationError.new unless more_pages?(collection) params = { before_id: collection.trackers.last.id } params[:page_size] = page_size unless page_size.nil? params.merge!(collection[EasyPost::InternalUtilities::Constants::FILTERS_KEY]).delete(:key) all(params) end |
#retrieve(id) ⇒ Object
Retrieve a Tracker
15 16 17 18 19 |
# File 'lib/easypost/services/tracker.rb', line 15 def retrieve(id) response = @client.make_request(:get, "trackers/#{id}") EasyPost::InternalUtilities::Json.convert_json_to_object(response, MODEL_CLASS) end |