Class: KaChing::ApiV1::Bookings
- Inherits:
-
Object
- Object
- KaChing::ApiV1::Bookings
- Extended by:
- Forwardable
- Defined in:
- lib/ka_ching/api_v1/bookings.rb
Overview
Bookings Endpoint for the KaChing API V1
Instance Method Summary collapse
-
#deposit!(tenant_account_id:, amount_cents:, year: Date.today.year, month: Date.today.month, day: Date.today.day, context: {}) {|Faraday::Response| ... } ⇒ Hash
Deposit money to the current tenant account.
-
#drop!(tenant_account_id:, booking_id:) {|Faraday::Response| ... } ⇒ Hash
drops/deletes a booking.
-
#initialize(conn:, api_url:) ⇒ Bookings
constructor
A new instance of Bookings.
-
#unlocked(tenant_account_id:) {|Faraday::Response| ... } ⇒ Hash
returns all unlocked bookings for a tenant.
-
#withdraw!(tenant_account_id:, amount_cents:, year: Date.today.year, month: Date.today.month, day: Date.today.day, context: {}) {|Faraday::Response| ... } ⇒ Hash
Withdraw money to the current tenant account.
Constructor Details
#initialize(conn:, api_url:) ⇒ Bookings
Returns a new instance of Bookings.
13 14 15 16 |
# File 'lib/ka_ching/api_v1/bookings.rb', line 13 def initialize(conn:, api_url:) @conn = conn @api_url = api_url end |
Instance Method Details
#deposit!(tenant_account_id:, amount_cents:, year: Date.today.year, month: Date.today.month, day: Date.today.day, context: {}) {|Faraday::Response| ... } ⇒ Hash
Deposit money to the current tenant account
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ka_ching/api_v1/bookings.rb', line 32 def deposit!(tenant_account_id:, amount_cents:, year: Date.today.year, month: Date.today.month, day: Date.today.day, context: {}) res = create!(tenant_account_id: tenant_account_id, booking: { action: :deposit, amount_cents: amount_cents, year: year, month: month, day: day, context: context }) yield res if block_given? JSON.parse(res.body) end |
#drop!(tenant_account_id:, booking_id:) {|Faraday::Response| ... } ⇒ Hash
drops/deletes a booking
93 94 95 96 97 98 99 100 101 |
# File 'lib/ka_ching/api_v1/bookings.rb', line 93 def drop!(tenant_account_id:, booking_id:) drop_url = "#{build_url(tenant_account_id: tenant_account_id)}/#{booking_id}" res = delete(drop_url) do |req| req.headers['Content-Type'] = 'application/json' req.body = { id: booking_id }.to_json end yield res if block_given? JSON.parse(res.body) end |
#unlocked(tenant_account_id:) {|Faraday::Response| ... } ⇒ Hash
returns all unlocked bookings for a tenant
112 113 114 115 116 117 118 119 |
# File 'lib/ka_ching/api_v1/bookings.rb', line 112 def unlocked(tenant_account_id:) unlocked_url = "#{build_url(tenant_account_id: tenant_account_id)}/unlocked" res = get(unlocked_url) do |req| req.headers['Content-Type'] = 'application/json' end yield res if block_given? JSON.parse(res.body) end |
#withdraw!(tenant_account_id:, amount_cents:, year: Date.today.year, month: Date.today.month, day: Date.today.day, context: {}) {|Faraday::Response| ... } ⇒ Hash
Withdraw money to the current tenant account
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/ka_ching/api_v1/bookings.rb', line 65 def withdraw!(tenant_account_id:, amount_cents:, year: Date.today.year, month: Date.today.month, day: Date.today.day, context: {}) res = create!(tenant_account_id: tenant_account_id, booking: { action: :withdraw, amount_cents: amount_cents, year: year, month: month, day: day, context: context }) yield res if block_given? JSON.parse(res.body) end |