Class: KaChing::ApiV1::Lockings

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/ka_ching/api_v1/lockings.rb

Overview

Lockings Endpoint for the KaChing API V1

Instance Method Summary collapse

Constructor Details

#initialize(conn:, api_url:) ⇒ Lockings

Returns a new instance of Lockings.



13
14
15
16
# File 'lib/ka_ching/api_v1/lockings.rb', line 13

def initialize(conn:, api_url:)
  @conn = conn
  @api_url = api_url
end

Instance Method Details

#active(tenant_account_id:, year: nil, page: 1, per_page: 100) {|res| ... } ⇒ Object

Yields:

  • (res)


91
92
93
94
95
96
97
98
99
100
101
# File 'lib/ka_ching/api_v1/lockings.rb', line 91

def active(tenant_account_id:, year: nil, page: 1, per_page: 100)
  params = { page: page, per_page: per_page }
  body_params = { active: 'true' }
  body_params[:year] = year if year
  res = get(build_url(tenant_account_id: ), params) do |req|
    req.headers['Content-Type'] = 'application/json'
    req.body = body_params.to_json
  end
  yield res if block_given?
  JSON.parse(res.body)
end

#all(tenant_account_id:, page: 1, per_page: 10) {|res| ... } ⇒ Object

Yields:

  • (res)


67
68
69
70
71
72
73
# File 'lib/ka_ching/api_v1/lockings.rb', line 67

def all(tenant_account_id:, page: 1, per_page: 10)
  res = get(build_url(tenant_account_id: ), { page: page, per_page: per_page }) do |req|
    req.headers['Content-Type'] = 'application/json'
  end
  yield res if block_given?
  JSON.parse(res.body)
end

#inactive(tenant_account_id:, year: nil, page: 1, per_page: 100) {|res| ... } ⇒ Object

Yields:

  • (res)


103
104
105
106
107
108
109
110
111
112
113
# File 'lib/ka_ching/api_v1/lockings.rb', line 103

def inactive(tenant_account_id:, year: nil, page: 1, per_page: 100)
  params = { page: page, per_page: per_page }
  body_params = { inactive: 'true' }
  body_params[:year] = year if year
  res = get(build_url(tenant_account_id: ), params) do |req|
    req.headers['Content-Type'] = 'application/json'
    req.body = body_params.to_json
  end
  yield res if block_given?
  JSON.parse(res.body)
end

#lock!(tenant_account_id:, amount_cents_saldo_user_counted:, year: Date.today.year, month: Date.today.month, day: Date.today.day, context: {}) {|Faraday::Response| ... } ⇒ Hash

Locks the bookings for a specific day

Parameters:

  • action (String)

    should be “lock”

  • amount_cents_saldo_user_counted (Integer)

    what the user counted as saldo

  • year (Integer) (defaults to: Date.today.year)
  • month (Integer) (defaults to: Date.today.month)
  • day (Integer) (defaults to: Date.today.day)
  • context (Hash) (defaults to: {})

    object with additional information stored with the locking

Yields:

  • (Faraday::Response)

    The response from the server

Returns:

  • (Hash)

    the locking



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/ka_ching/api_v1/lockings.rb', line 31

def lock!(tenant_account_id:,
          amount_cents_saldo_user_counted:,
          year: Date.today.year,
          month: Date.today.month,
          day: Date.today.day,
          context: {})
  locking = {
    action: :lock,
    amount_cents_saldo_user_counted: amount_cents_saldo_user_counted,
    year: Integer(year),
    month: Integer(month),
    day: Integer(day),
    context: context
  }
  res = post(build_url(tenant_account_id: )) do |req|
    req.headers['Content-Type'] = 'application/json'
    req.body = locking.to_json
  end
  yield res if block_given?
  JSON.parse(res.body)
end

#of_year(tenant_account_id:, year:, page: 1, per_page: 100) {|Faraday::Response| ... } ⇒ Hash

Get all lockings for a given year

Yields:

  • (Faraday::Response)

    The response from the server

Returns:

  • (Hash)


81
82
83
84
85
86
87
88
89
# File 'lib/ka_ching/api_v1/lockings.rb', line 81

def of_year(tenant_account_id:, year:, page: 1, per_page: 100)
  res = get(build_url(tenant_account_id: ),
            { year: year, page: page, per_page: per_page }) do |req|
    req.headers['Content-Type'] = 'application/json'
    req.body = { year: year }.to_json
  end
  yield res if block_given?
  JSON.parse(res.body)
end

#unlock!(tenant_account_id:) {|Faraday::Response| ... } ⇒ Hash

Unlocks last locking

Yields:

  • (Faraday::Response)

    The response from the server

Returns:

  • (Hash)


59
60
61
62
63
64
65
# File 'lib/ka_ching/api_v1/lockings.rb', line 59

def unlock!(tenant_account_id:)
  res = delete(build_url(tenant_account_id: )) do |req|
    req.headers['Content-Type'] = 'application/json'
  end
  yield res if block_given?
  JSON.parse(res.body)
end