Class: Esignatur::Orders

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/esignatur/orders.rb

Overview

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

Instance Method Summary collapse

Constructor Details

#initialize(scope: {}, api:) ⇒ Orders

Returns a new instance of Orders.



9
10
11
12
# File 'lib/esignatur/orders.rb', line 9

def initialize(scope: {}, api:)
  @scope = scope
  @api = api
end

Instance Method Details

#allObject



22
23
24
25
26
27
28
29
# File 'lib/esignatur/orders.rb', line 22

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.new(raw_order.fetch('SignOrderId'), response_body: raw_order, api: api)
    end
  end
end

#create(attributes) ⇒ Object



14
15
16
# File 'lib/esignatur/orders.rb', line 14

def create(attributes)
  Order.create(attributes, api: api)
end

#each(&block) ⇒ Object



31
32
33
# File 'lib/esignatur/orders.rb', line 31

def each(&block)
  all.each(&block)
end

#find(id) ⇒ Object



35
36
37
# File 'lib/esignatur/orders.rb', line 35

def find(id)
  Order.new(id, api: api)
end

#where(new_scope) ⇒ Object



18
19
20
# File 'lib/esignatur/orders.rb', line 18

def where(new_scope)
  self.class.new(scope: scope.merge(new_scope), api: api)
end