Class: Fakturoid::Api::Expense

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/fakturoid/api/expense.rb

Instance Attribute Summary

Attributes included from Base

#client

Instance Method Summary collapse

Methods included from Base

#initialize, #perform_request

Instance Method Details

#all(params = {}) ⇒ Object



8
9
10
11
12
# File 'lib/fakturoid/api/expense.rb', line 8

def all(params = {})
  request_params = Utils.permit_params(params, :since, :updated_since, :page, :subject_id, :custom_id, :number, :variable_symbol, :status) || {}

  perform_request(HTTP_GET, "expenses.json", request_params: request_params)
end

#create(payload = {}) ⇒ Object



40
41
42
# File 'lib/fakturoid/api/expense.rb', line 40

def create(payload = {})
  perform_request(HTTP_POST, "expenses.json", payload: payload)
end

#delete(id) ⇒ Object



49
50
51
52
# File 'lib/fakturoid/api/expense.rb', line 49

def delete(id)
  Utils.validate_numerical_id(id)
  perform_request(HTTP_DELETE, "expenses/#{id}.json")
end

#download_attachment(expense_id, id) ⇒ Object



27
28
29
30
31
# File 'lib/fakturoid/api/expense.rb', line 27

def download_attachment(expense_id, id)
  Utils.validate_numerical_id(expense_id)
  Utils.validate_numerical_id(id)
  perform_request(HTTP_GET, "expenses/#{expense_id}/attachments/#{id}/download")
end

#find(id) ⇒ Object



22
23
24
25
# File 'lib/fakturoid/api/expense.rb', line 22

def find(id)
  Utils.validate_numerical_id(id)
  perform_request(HTTP_GET, "expenses/#{id}.json")
end

#fire(id, event) ⇒ Object



33
34
35
36
37
38
# File 'lib/fakturoid/api/expense.rb', line 33

def fire(id, event)
  request_params = { event: event }

  Utils.validate_numerical_id(id)
  perform_request(HTTP_POST, "expenses/#{id}/fire.json", request_params: request_params)
end

#search(params = {}) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/fakturoid/api/expense.rb', line 14

def search(params = {})
  Utils.validate_search_query(query: params[:query], tags: params[:tags], allow_tags: true)

  request_params = Utils.permit_params(params, :query, :tags, :page)

  perform_request(HTTP_GET, "expenses/search.json", request_params: request_params)
end

#update(id, payload = {}) ⇒ Object



44
45
46
47
# File 'lib/fakturoid/api/expense.rb', line 44

def update(id, payload = {})
  Utils.validate_numerical_id(id)
  perform_request(HTTP_PATCH, "expenses/#{id}.json", payload: payload)
end