Skip to content

Commit

Permalink
Add webhook support to LightspeedRestaurantClient
Browse files Browse the repository at this point in the history
  • Loading branch information
chen-lightspeed committed Dec 4, 2024
1 parent 1599283 commit 1ffbd2d
Show file tree
Hide file tree
Showing 12 changed files with 461 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/lightspeed_restaurant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
require 'lightspeed_restaurant/receipt'
require 'lightspeed_restaurant/request'
require 'lightspeed_restaurant/version'
require 'lightspeed_restaurant/webhook'

module LightspeedRestaurantClient
class << self
Expand Down
2 changes: 1 addition & 1 deletion lib/lightspeed_restaurant/operations/list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def resource_path
def handle_list_response(response)
case response
when Hash
response['results']
response['results'] || response['data']
else
response
end
Expand Down
12 changes: 12 additions & 0 deletions lib/lightspeed_restaurant/operations/renew.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

module LightspeedRestaurantClient
module Operations
module Renew
def renew(id, configuration = nil)
response = JSON.parse(LightspeedRestaurantClient.post(default_resource_path + "/#{id}" + "/renew", {}, configuration))
new(response)
end
end
end
end
1 change: 1 addition & 0 deletions lib/lightspeed_restaurant/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
require 'lightspeed_restaurant/errors/invalid_request_error'
require 'lightspeed_restaurant/errors/not_found_error'
require 'lightspeed_restaurant/errors/rate_limit_error'
require 'lightspeed_restaurant/errors/unauthorized_error'
require 'uri'

module LightspeedRestaurantClient
Expand Down
24 changes: 24 additions & 0 deletions lib/lightspeed_restaurant/webhook.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

require 'lightspeed_restaurant/base'
require 'lightspeed_restaurant/operations/list'
require 'lightspeed_restaurant/operations/find'
require 'lightspeed_restaurant/operations/create'
require 'lightspeed_restaurant/operations/renew'

module LightspeedRestaurantClient
class Webhook < LightspeedRestaurantClient::Base
extend Operations::Create
extend Operations::List
extend Operations::Find
extend Operations::Renew

def self.resource_name
'Webhooks'
end

def self.default_resource_path
"/rest/v1/#{resource_name.downcase}/subscriptions"
end
end
end
31 changes: 31 additions & 0 deletions spec/fixtures/vcr_cassettes/webhook/create.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
http_interactions:
- request:
method: post
uri: http://staging-integration.posios.com/PosServer/rest/v1/webhooks/subscriptions
body:
encoding: UTF-8
string: '{"notificationUrl":"https://localhost","type":"RECEIPT_CREATED","timeToLiveInSeconds":900,"notificationEmail":"[email protected]"}'
headers:
Authorization:
- Bearer {ACCESS_TOKEN}
User-Agent:
- excon/0.91.0
Accept:
- "*/*"
Content-Type:
- application/json
response:
status:
code: 200
message: OK
headers:
Content-Type:
- application/json
Date:
- Thu, 17 Aug 2023 00:31:49 GMT
body:
encoding: UTF-8
string: '{"data":{"id":1921,"notificationUrl":"https://localhost","type":"RECEIPT_CREATED","renewalTime":"2023-08-17T00:31:49.123Z","expirationTime":"2023-08-18T00:31:49.123Z","timeToLiveInSeconds":900,"apiKey":"d4V9rULfWJlQqcvgJkk6jXhmC2HDqkPo"}}'
recorded_at: Thu, 17 Aug 2023 00:31:49 GMT
recorded_with: VCR 6.3.1
75 changes: 75 additions & 0 deletions spec/fixtures/vcr_cassettes/webhook/create_invalid.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions spec/fixtures/vcr_cassettes/webhook/find.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
http_interactions:
- request:
method: get
uri: http://staging-integration.posios.com/PosServer/rest/v1/webhooks/subscriptions/1920
body:
encoding: UTF-8
string: "{}"
headers:
Authorization:
- Bearer {ACCESS_TOKEN}
User-Agent:
- excon/0.91.0
Accept:
- "*/*"
Content-Type:
- application/json
response:
status:
code: 200
message: OK
headers:
Content-Type:
- application/json
Date:
- Wed, 16 Aug 2023 21:07:07 GMT
body:
encoding: UTF-8
string: '{"data":{"id":1920,"notificationUrl":"https://localhost","type":"RECEIPT_UPDATED","renewalTime":"2023-08-16T21:07:07.026Z","expirationTime":"2023-08-17T21:07:07.026Z","timeToLiveInSeconds":900,"apiKey":"cywAOYUFIDrEcsF61fEritN3mR1b7mPF"}}'
recorded_at: Wed, 16 Aug 2023 21:07:07 GMT
recorded_with: VCR 6.3.1
31 changes: 31 additions & 0 deletions spec/fixtures/vcr_cassettes/webhook/list.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
http_interactions:
- request:
method: get
uri: http://staging-integration.posios.com/PosServer/rest/v1/webhooks/subscriptions
body:
encoding: UTF-8
string: "{}"
headers:
Authorization:
- Bearer {ACCESS_TOKEN}
User-Agent:
- excon/0.91.0
Accept:
- "*/*"
Content-Type:
- application/json
response:
status:
code: 200
message: OK
headers:
Content-Type:
- application/json
Date:
- Wed, 16 Aug 2023 21:07:07 GMT
body:
encoding: UTF-8
string: '{"data":[{"id":1920,"notificationUrl":"https://localhost","type":"RECEIPT_UPDATED","renewalTime":"2023-08-16T21:07:07.026Z","expirationTime":"2023-08-17T21:07:07.026Z","timeToLiveInSeconds":900,"apiKey":"cywAOYUFIDrEcsF61fEritN3mR1b7mPF"},{"id":1921,"notificationUrl":"https://localhost","type":"RECEIPT_CREATED","renewalTime":"2023-08-17T00:31:49.123Z","expirationTime":"2023-08-18T00:31:49.123Z","timeToLiveInSeconds":900,"apiKey":"d4V9rULfWJlQqcvgJkk6jXhmC2HDqkPo"}]}'
recorded_at: Wed, 16 Aug 2023 21:07:07 GMT
recorded_with: VCR 6.3.1
79 changes: 79 additions & 0 deletions spec/fixtures/vcr_cassettes/webhook/renew.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 73 additions & 0 deletions spec/fixtures/vcr_cassettes/webhook/renew_invalid.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1ffbd2d

Please sign in to comment.