class EasyPost::Services::Report

Constants

MODEL_CLASS

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

Public Instance Methods

all(params = {}) click to toggle source

Retrieve all Report objects

# File lib/easypost/services/report.rb, line 27
def all(params = {})
  unless params[:type]
    raise ArgumentError, "Missing 'type' parameter in params" # TODO: replace the error in the error-handling overhaul PR
  end

  type = params.delete(:type)
  filters = {
    key: 'reports',
    type: type,
  }
  url = "reports/#{type}"
  response = get_all_helper(url, MODEL_CLASS, params, filters)
  response.define_singleton_method(:type) { type }

  response
end
create(params = {}) click to toggle source

Create a Report

# File lib/easypost/services/report.rb, line 7
def create(params = {})
  unless params[:type]
    raise ArgumentError, "Missing 'type' parameter in params" # TODO: replace the error in the error-handling overhaul PR
  end

  type = params.delete(:type)
  url = "reports/#{type}"
  response = @client.make_request(:post, url, params)

  EasyPost::InternalUtilities::Json.convert_json_to_object(response, MODEL_CLASS)
end
get_next_page(collection, page_size = nil) click to toggle source

Get next page of Report objects

# File lib/easypost/services/report.rb, line 45
def get_next_page(collection, page_size = nil)
  raise EasyPost::Errors::EndOfPaginationError.new unless more_pages?(collection)

  params = { before_id: collection.reports.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) click to toggle source

Retrieve a Report

# File lib/easypost/services/report.rb, line 20
def retrieve(id)
  response = @client.make_request(:get, "reports/#{id}")

  EasyPost::InternalUtilities::Json.convert_json_to_object(response, MODEL_CLASS)
end