class Esignatur::Orders

esignatur order info collection representation. more info: api.esignatur.dk/Documentation/OrderInfo

Attributes

api[R]
scope[R]

Public Class Methods

new(scope: {}, api:) click to toggle source
# File lib/esignatur/orders.rb, line 12
def initialize(scope: {}, api:)
  @scope = scope
  @api = api
end

Public Instance Methods

all() click to toggle source
# File lib/esignatur/orders.rb, line 29
def all
  @all ||= begin
    response = api_get("OrderInfo/OrdersForAdministrator/#{creator_id}", headers: headers_for_all_query)
    response.json_body.fetch('SignOrders').map do |raw_order|
      order_attributes = raw_order.merge(id: raw_order.fetch('SignOrderId'))
      Esignatur::Order.new(attributes: order_attributes, api: api)
    end
  end
end
build() click to toggle source
# File lib/esignatur/orders.rb, line 21
def build
  Esignatur::Order.new(api: api)
end
create(attributes) click to toggle source
# File lib/esignatur/orders.rb, line 17
def create(attributes)
  build.create(attributes)
end
each(&block) click to toggle source
# File lib/esignatur/orders.rb, line 39
def each(&block)
  all.each(&block)
end
find(id) click to toggle source
# File lib/esignatur/orders.rb, line 43
def find(id)
  Esignatur::Order.new(attributes: { id: id }, api: api)
end
where(new_scope) click to toggle source
# File lib/esignatur/orders.rb, line 25
def where(new_scope)
  self.class.new(scope: scope.merge(new_scope), api: api)
end

Private Instance Methods

creator_id() click to toggle source
# File lib/esignatur/orders.rb, line 56
def creator_id
  scope.fetch(:creator_id) do
    raise(
      Esignatur::MissingAttributeError,
      'You need to specify creator_id in order to fech orders. ' \
      'You can do this with `esignatur.orders.where(creator_id: 123)`'
    )
  end
end
headers_for_all_query() click to toggle source
# File lib/esignatur/orders.rb, line 51
def headers_for_all_query
  modified_since = scope[:modified_since]&.iso8601
  modified_since ? { 'If-Modified-Since' => modified_since } : {}
end