Class: LendingClub::OrderCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/lending_club/client/order_collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(orders, aid) ⇒ OrderCollection

Returns a new instance of OrderCollection.



9
10
11
12
13
# File 'lib/lending_club/client/order_collection.rb', line 9

def initialize(orders, aid)
  @orders = []
  orders.each { |o| add(o) }
  @aid = Integer(aid)
end

Instance Attribute Details

#aidInteger (readonly)

Returns The member id of the account under management.

Returns:

  • (Integer)

    The member id of the account under management.



7
8
9
# File 'lib/lending_club/client/order_collection.rb', line 7

def aid
  @aid
end

#ordersArray<Order> (readonly)

Returns array of Orders.

Returns:

  • (Array<Order>)

    array of Orders



5
6
7
# File 'lib/lending_club/client/order_collection.rb', line 5

def orders
  @orders
end

Instance Method Details

#add(order) ⇒ Object

Raises:



38
39
40
41
42
43
# File 'lib/lending_club/client/order_collection.rb', line 38

def add(order)
  is_valid, error_message = validate(order)
  raise Error.new(error_message) unless is_valid
  @orders << order
  self
end

#to_hObject



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/lending_club/client/order_collection.rb', line 15

def to_h
  {
    'aid' => @aid,
    'orders' => @orders.map do |order|
      {
        'loanId' => order.loan_id,
        'requestedAmount' => order.requested_amount,
        'portfolioId' => order.portfolio_id
      }
    end
  }
end

#update_orders(response) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/lending_club/client/order_collection.rb', line 28

def update_orders(response)
  response['orderConfirmations'].each do |confirmation|
    order = lookup(confirmation['loanId'])
    order.order_instruct_id = Integer(confirmation['orderInstructId'])
    order.invested_amount = Integer(confirmation['investedAmount'])
    order.execution_status = confirmation['executionStatus']
  end
  self
end