Class: Revolut::Api::Response::Transaction

Inherits:
Object
  • Object
show all
Defined in:
lib/revolut/api/response/transaction.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ Transaction

Returns a new instance of Transaction.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/revolut/api/response/transaction.rb', line 12

def initialize(hash = {})
  self.id                       =   hash.fetch("id", nil)
  self.leg_id                   =   hash.fetch("legId", nil)
  self.type                     =   hash.fetch("type", nil)
  self.state                    =   hash.fetch("state", nil)

  self.started_date             =   hash.fetch("startedDate", nil)
  self.started_date             =   ::Revolut::Api::Utilities.epoch_to_utc(self.started_date) unless self.started_date.nil?
  self.updated_date             =   hash.fetch("updatedDate", nil)
  self.updated_date             =   ::Revolut::Api::Utilities.epoch_to_utc(self.updated_date) unless self.updated_date.nil?
  self.completed_date           =   hash.fetch("completedDate", nil)
  self.completed_date           =   ::Revolut::Api::Utilities.epoch_to_utc(self.completed_date) unless self.completed_date.nil?

  self.currency                 =   hash.fetch("currency", nil)
  self.amount                   =   hash.fetch("amount", nil)
  self.amount                   =   ::Revolut::Api::Utilities.convert_from_integer_amount(self.currency, self.amount) if !self.currency.to_s.empty? && !self.amount.nil?

  self.fee                      =   hash.fetch("fee", nil)
  self.fee                      =   ::Revolut::Api::Utilities.convert_from_integer_amount(self.currency, self.fee) if !self.currency.to_s.empty? && !self.fee.nil?

  self.balance                  =   hash.fetch("balance", nil)
  self.balance                  =   ::Revolut::Api::Utilities.convert_from_integer_amount(self.currency, self.balance) if !self.currency.to_s.empty? && !self.balance.nil?

  self.description              =   hash.fetch("description", nil)

  self.rate                     =   hash.fetch("rate", nil)
  self.direction                =   hash.fetch("direction", nil)

  self.counterpart              =   {}
  self.counterpart[:currency]   =   hash.fetch("counterpart", {}).fetch("currency", nil)
  self.counterpart[:amount]     =   hash.fetch("counterpart", {}).fetch("amount", nil)
  self.counterpart[:amount]     =   ::Revolut::Api::Utilities.convert_from_integer_amount(self.counterpart[:currency], self.counterpart[:amount]) if !self.counterpart[:currency].to_s.empty? && !self.counterpart[:amount].nil?

  merchant_data                 =   hash.fetch("merchant", {})
  self.merchant                 =   ::Revolut::Api::Response::Merchant.new(merchant_data) if !merchant_data.empty?

  self.card                     =   {}
  self.card[:last_four]         =   hash.fetch("card", {}).fetch("lastFour", nil)
end

Instance Attribute Details

#amountObject

Returns the value of attribute amount.



8
9
10
# File 'lib/revolut/api/response/transaction.rb', line 8

def amount
  @amount
end

#balanceObject

Returns the value of attribute balance.



8
9
10
# File 'lib/revolut/api/response/transaction.rb', line 8

def balance
  @balance
end

#cardObject

Returns the value of attribute card.



10
11
12
# File 'lib/revolut/api/response/transaction.rb', line 10

def card
  @card
end

#completed_dateObject

Returns the value of attribute completed_date.



7
8
9
# File 'lib/revolut/api/response/transaction.rb', line 7

def completed_date
  @completed_date
end

#counterpartObject

Returns the value of attribute counterpart.



9
10
11
# File 'lib/revolut/api/response/transaction.rb', line 9

def counterpart
  @counterpart
end

#currencyObject

Returns the value of attribute currency.



8
9
10
# File 'lib/revolut/api/response/transaction.rb', line 8

def currency
  @currency
end

#descriptionObject

Returns the value of attribute description.



8
9
10
# File 'lib/revolut/api/response/transaction.rb', line 8

def description
  @description
end

#directionObject

Returns the value of attribute direction.



9
10
11
# File 'lib/revolut/api/response/transaction.rb', line 9

def direction
  @direction
end

#feeObject

Returns the value of attribute fee.



8
9
10
# File 'lib/revolut/api/response/transaction.rb', line 8

def fee
  @fee
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/revolut/api/response/transaction.rb', line 5

def id
  @id
end

#leg_idObject

Returns the value of attribute leg_id.



5
6
7
# File 'lib/revolut/api/response/transaction.rb', line 5

def leg_id
  @leg_id
end

#merchantObject

Returns the value of attribute merchant.



10
11
12
# File 'lib/revolut/api/response/transaction.rb', line 10

def merchant
  @merchant
end

#rateObject

Returns the value of attribute rate.



8
9
10
# File 'lib/revolut/api/response/transaction.rb', line 8

def rate
  @rate
end

#started_dateObject

Returns the value of attribute started_date.



7
8
9
# File 'lib/revolut/api/response/transaction.rb', line 7

def started_date
  @started_date
end

#stateObject

Returns the value of attribute state.



6
7
8
# File 'lib/revolut/api/response/transaction.rb', line 6

def state
  @state
end

#typeObject

Returns the value of attribute type.



6
7
8
# File 'lib/revolut/api/response/transaction.rb', line 6

def type
  @type
end

#updated_dateObject

Returns the value of attribute updated_date.



7
8
9
# File 'lib/revolut/api/response/transaction.rb', line 7

def updated_date
  @updated_date
end

Instance Method Details

#completed?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/revolut/api/response/transaction.rb', line 52

def completed?
  in_state?(:completed)
end

#in_state?(state) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/revolut/api/response/transaction.rb', line 60

def in_state?(state)
  self.state.downcase.strip.to_sym.eql?(state)
end

#pending?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/revolut/api/response/transaction.rb', line 56

def pending?
  in_state?(:pending)
end