Class: EasyPost::Report

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

Overview

A Report contains a csv that is a log of all the objects created within a certain time frame.

Instance Attribute Summary

Attributes inherited from EasyPostObject

#api_key, #name, #parent, #unsaved_values

Class Method Summary collapse

Methods inherited from Resource

class_name, #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 Report objects.



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/easypost/report.rb', line 17

def self.all(filters = {}, api_key = nil)
  url = "#{self.url}/#{filters[:type]}"

  response = EasyPost.make_request(:get, url, api_key, filters)
  collection = EasyPost::Util.convert_to_easypost_object(response, api_key)

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

  collection
end

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

Build the next page parameters.



35
36
37
38
39
40
41
42
43
# File 'lib/easypost/report.rb', line 35

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
  params[:type] = collection.type
  params
end

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

Create a Report.



6
7
8
9
10
11
12
13
14
# File 'lib/easypost/report.rb', line 6

def self.create(params = {}, api_key = nil)
  url = "#{self.url}/#{params[:type]}"

  wrapped_params = {}
  wrapped_params[class_name.to_sym] = params

  response = EasyPost.make_request(:post, url, api_key, params)
  EasyPost::Util.convert_to_easypost_object(response, api_key)
end

.get_next_page(collection, page_size = nil) ⇒ Object

Get the next page of addresses.



30
31
32
# File 'lib/easypost/report.rb', line 30

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