Class: EasyPost::Tracker

Inherits:
Resource show all
Defined in:
lib/easypost/tracker.rb

Overview

A Tracker object contains all of the tracking information for a package.

Instance Attribute Summary

Attributes inherited from EasyPostObject

#api_key, #name, #parent, #unsaved_values

Class Method Summary collapse

Methods inherited from Resource

class_name, create, #delete, each, get_next_page_exec, #refresh, retrieve, #save, url, #url

Methods inherited from EasyPostObject

#[], #[]=, #as_json, construct_from, #deconstruct_keys, #each, #id, #id=, #initialize, #inspect, #keys, #refresh_from, #to_hash, #to_json, #to_s, #values

Constructor Details

This class inherits a constructor from EasyPost::EasyPostObject

Class Method Details

.all(filters = {}, api_key = nil) ⇒ Object

Retrieve a list of Tracker objects.



14
15
16
17
18
19
20
21
# File 'lib/easypost/tracker.rb', line 14

def self.all(filters = {}, api_key = nil)
  collection = super(filters, api_key)

  # Store the filters used to retrieve the collection.
  collection.refresh_from({ tracking_code: filters[:tracking_code], carrier: filters[:carrier] }, api_key)

  collection
end

.build_next_page_params(collection, current_page_items, page_size = nil) ⇒ Object

Build the next page parameters.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/easypost/tracker.rb', line 29

def self.build_next_page_params(collection, current_page_items, page_size = nil)
  params = {}
  params[:before_id] = current_page_items.last.id
  unless page_size.nil?
    params[:page_size] = page_size
  end
  unless collection.tracking_code.nil?
    params[:tracking_code] = collection.tracking_code
  end
  unless collection.carrier.nil?
    params[:carrier] = collection.carrier
  end
  params
end

.create_list(params = {}, api_key = nil) ⇒ Object

Create multiple Tracker objects in bulk.



6
7
8
9
10
11
# File 'lib/easypost/tracker.rb', line 6

def self.create_list(params = {}, api_key = nil)
  url = "#{self.url}/create_list"
  new_params = { 'trackers' => params }
  EasyPost.make_request(:post, url, api_key, new_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.



24
25
26
# File 'lib/easypost/tracker.rb', line 24

def self.get_next_page(collection, page_size = nil)
  get_next_page_exec(method(:all), collection, collection.trackers, page_size)
end