Class: EasyPost::Report

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

Constant Summary collapse

REPORT_TYPES =
{ shprep: 'shipment', plrep: 'payment_log', trkrep: 'tracker' }

Instance Attribute Summary

Attributes inherited from EasyPostObject

#api_key, #name, #parent, #unsaved_values

Class Method Summary collapse

Methods inherited from Resource

class_name, #delete, #refresh, #save, url, #url

Methods inherited from EasyPostObject

#[], #[]=, #as_json, construct_from, #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



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

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

  if REPORT_TYPES.values.include?(filters[:type].to_s)
    url += "/#{filters[:type]}"
  else
    raise Error.new("Undetermined Report Type")
  end

  response, api_key = EasyPost.request(:get, url, api_key, filters)
  return EasyPost::Util::convert_to_easypost_object(response, api_key) if response
end

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



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

def self.create(params={}, api_key=nil)
  url = self.url
  wrapped_params = {}
  wrapped_params[class_name.to_sym] = params

  if REPORT_TYPES.values.include?(params[:type].to_s)
    url += "/#{params[:type]}"
  else
    raise Error.new("Undetermined Report Type")
  end

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

.retrieve(params, api_key = nil) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/easypost/report.rb', line 20

def self.retrieve(params, api_key=nil)
  url = self.url
  obj_id = params[:id].split("_")[0]

  if REPORT_TYPES.has_key?(obj_id.to_sym)
    url += "/#{REPORT_TYPES[obj_id.to_sym]}/#{params[:id]}"
  else
    raise Error.new("Undetermined Report Type")
  end

  response, api_key = EasyPost.request(:get, url, api_key, params)
  return EasyPost::Util::convert_to_easypost_object(response, api_key) if response
end