Class: EasyPost::Services::Report

Inherits:
Service
  • Object
show all
Defined in:
lib/easypost/services/report.rb

Constant Summary collapse

MODEL_CLASS =
EasyPost::Models::Report

Instance Method Summary collapse

Methods inherited from Service

#initialize

Constructor Details

This class inherits a constructor from EasyPost::Services::Service

Instance Method Details

#all(params = {}) ⇒ Object

Retrieve all Report objects



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/easypost/services/report.rb', line 24

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)
  url = "reports/#{type}"

  response = @client.make_request(:get, url, MODEL_CLASS, params)
  response.define_singleton_method(:type) { type }
  response
end

#create(params = {}) ⇒ Object

Create a Report



7
8
9
10
11
12
13
14
15
16
# 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}"

  @client.make_request(:post, url, MODEL_CLASS, params)
end

#get_next_page(collection, page_size = nil) ⇒ Object

Get next page of Report objects



38
39
40
41
# File 'lib/easypost/services/report.rb', line 38

def get_next_page(collection, page_size = nil)
  url = "reports/#{collection.type}"
  get_next_page_helper(collection, collection.reports, url, MODEL_CLASS, page_size)
end

#retrieve(id) ⇒ Object

Retrieve a Report



19
20
21
# File 'lib/easypost/services/report.rb', line 19

def retrieve(id)
  @client.make_request(:get, "reports/#{id}", MODEL_CLASS)
end