Module: QboApi::Entity

Included in:
QboApi
Defined in:
lib/qbo_api/entity.rb

Instance Method Summary collapse

Instance Method Details

#entity_path(entity) ⇒ Object



16
17
18
# File 'lib/qbo_api/entity.rb', line 16

def entity_path(entity)
  "#{realm_id}/#{singular(entity).downcase}"
end

#extract_entity_from_query(query, to_sym: false) ⇒ Object



84
85
86
87
88
# File 'lib/qbo_api/entity.rb', line 84

def extract_entity_from_query(query, to_sym: false)
  if m = query.match(/from\s+(\w+)(?:$|\s)/i)
    (to_sym ? underscore(m[1]).to_sym : m[1]) if m[1]
  end
end

#is_name_list_entity?(entity) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/qbo_api/entity.rb', line 48

def is_name_list_entity?(entity)
  name_list_entities.include?(singular(entity))
end

#is_transaction_entity?(entity) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/qbo_api/entity.rb', line 24

def is_transaction_entity?(entity)
  transaction_entities.include?(singular(entity))
end

#name_list_entitiesObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/qbo_api/entity.rb', line 52

def name_list_entities
  %w{
    Account
    Budget
    Class
    CompanyCurrency
    Customer
    Department
    Employee
    Item
    JournalCode
    PaymentMethod
    TaxAgency
    TaxCode
    TaxRate
    TaxService
    Term
    Vendor
  }
end

#singular(entity) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/qbo_api/entity.rb', line 4

def singular(entity)
  e = snake_to_camel(entity)
  case e
  when 'Classes', 'Class'
    'Class'
  when 'Entitlements', 'Preferences'
    e
  else
    e.chomp('s')
  end
end

#snake_to_camel(sym) ⇒ Object



20
21
22
# File 'lib/qbo_api/entity.rb', line 20

def snake_to_camel(sym)
  sym.to_s.split('_').collect(&:capitalize).join
end

#supporting_entitiesObject



73
74
75
76
77
78
79
80
81
82
# File 'lib/qbo_api/entity.rb', line 73

def supporting_entities
  %w{
    Attachable
    Batch
    CompanyInfo
    Entitlements
    ExchangeRate
    Preferences
  }
end

#transaction_entitiesObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/qbo_api/entity.rb', line 28

def transaction_entities
  %w{
    Bill
    BillPayment
    CreditMemo
    Deposit
    Estimate
    Invoice
    JournalEntry
    Payment
    Purchase
    PurchaseOrder
    RefundReceipt
    SalesReceipt
    TimeActivity
    Transfer
    VendorCredit
  }
end