Sha256: 9acbdadf1398c19f4779f8b3cc1979095d0817857851ea60ed50b21e7c584e77

Contents?: true

Size: 944 Bytes

Versions: 22

Compression:

Stored size: 944 Bytes

Contents

module Unit
  class Statement < APIResource
    path '/statements'

    attribute :period, Types::String

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

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

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

    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

    include ResourceOperations::List
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
unit-ruby-0.10.0 lib/unit-ruby/statement.rb
unit-ruby-0.9.0 lib/unit-ruby/statement.rb
unit-ruby-0.8.1 lib/unit-ruby/statement.rb
unit-ruby-0.8.0 lib/unit-ruby/statement.rb
unit-ruby-0.7.0 lib/unit-ruby/statement.rb
unit-ruby-0.6.0 lib/unit-ruby/statement.rb
unit-ruby-0.5.0 lib/unit-ruby/statement.rb
unit-ruby-0.4.3 lib/unit-ruby/statement.rb
unit-ruby-0.4.2 lib/unit-ruby/statement.rb
unit-ruby-0.4.1 lib/unit-ruby/statement.rb
unit-ruby-0.4.0 lib/unit-ruby/statement.rb
unit-ruby-0.3.7 lib/unit-ruby/statement.rb
unit-ruby-0.2.7 lib/unit-ruby/statement.rb
unit-ruby-0.2.6 lib/unit-ruby/statement.rb
unit-ruby-0.2.5 lib/unit-ruby/statement.rb
unit-ruby-0.2.4 lib/unit-ruby/statement.rb
unit-ruby-0.2.3 lib/unit-ruby/statement.rb
unit-ruby-0.2.2 lib/unit-ruby/statement.rb
unit-ruby-0.2.1 lib/unit-ruby/statement.rb
unit-ruby-0.2.0 lib/unit-ruby/statement.rb