Class: Unit::Statement

Inherits:
APIResource show all
Includes:
ResourceOperations::List
Defined in:
lib/unit-ruby/statement.rb

Instance Attribute Summary

Attributes inherited from APIResource

#id, #raw_data, #relationships, #type

Class Method Summary collapse

Methods included from ResourceOperations::List

included

Methods inherited from APIResource

#as_json_api, attribute, #attributes, belongs_to, build_resource_from_json_api, #clear_attributes!, connection, #dirty?, #dirty_attributes, has_many, #initialize, #mark_as_clean!, #mark_attribute_as_dirty, path, resource_path, #resource_type, resources_path, #schema, schema, #update_attribute, #update_resource_from_json_api

Constructor Details

This class inherits a constructor from Unit::APIResource

Class Method Details

.base_url(statement_id, response_type, customer_id) ⇒ Object



17
18
19
20
# File 'lib/unit-ruby/statement.rb', line 17

def self.base_url(statement_id, response_type, customer_id)
  "#{Unit::Connection.base_url}statements/#{statement_id}/#{response_type}" \
    "?filter[customerId]=#{customer_id}"
end

.html_for(statement_id:, customer_id:) ⇒ Object



12
13
14
15
# File 'lib/unit-ruby/statement.rb', line 12

def self.html_for(statement_id:, customer_id:)
  url = base_url(statement_id, :html, customer_id)
  statement_connection(url).get.body
end

.pdf_for(statement_id:, customer_id:) ⇒ Object



7
8
9
10
# File 'lib/unit-ruby/statement.rb', line 7

def self.pdf_for(statement_id:, customer_id:)
  url = base_url(statement_id, :pdf, customer_id)
  statement_connection(url).get.body
end

.statement_connection(url) ⇒ Object



22
23
24
25
26
27
# File 'lib/unit-ruby/statement.rb', line 22

def self.statement_connection(url)
  # Establishing a new connection to avoid having to alter the existing connection to support pdf / html responses
  Faraday.new(url) do |f|
    f.headers['Authorization'] = "Bearer #{Unit::Connection.api_key}"
  end
end