Class: DuffelAPI::Services::WebhooksService
- Inherits:
-
BaseService
- Object
- BaseService
- DuffelAPI::Services::WebhooksService
- Defined in:
- lib/duffel_api/services/webhooks_service.rb
Defined Under Namespace
Classes: PingResult
Constant Summary
Constants inherited from BaseService
BaseService::DEFAULT_ALL_PARAMS
Instance Method Summary collapse
-
#create(options = {}) ⇒ Resources::Webhook
Creates an webhook.
-
#ping(id, options = {}) ⇒ PingResult
Pings a webhook by ID.
-
#update(id, options = {}) ⇒ Resources::Webhook
Updates a webhook by ID.
Methods inherited from BaseService
Constructor Details
This class inherits a constructor from DuffelAPI::Services::BaseService
Instance Method Details
#create(options = {}) ⇒ Resources::Webhook
Creates an webhook
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/duffel_api/services/webhooks_service.rb', line 30 def create( = {}) path = "/air/webhooks" params = .delete(:params) || {} [:params] = {} [:params]["data"] = params begin response = make_request(:post, path, ) # Response doesn't raise any errors until #body is called response.tap(&:raw_body) end return if response.raw_body.nil? Resources::Webhook.new(unenvelope_body(response.parsed_body), response) end |
#ping(id, options = {}) ⇒ PingResult
Pings a webhook by ID
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/duffel_api/services/webhooks_service.rb', line 79 def ping(id, = {}) path = substitute_url_pattern("/air/webhooks/:id/actions/ping", "id" => id) params = .delete(:params) || {} [:params] = {} [:params]["data"] = params begin response = make_request(:post, path, ) # Response doesn't raise any errors until #body is called response.tap(&:raw_body) end rescue DuffelAPI::Errors::Error => e # We expect this API call to *ALWAYS* lead to an error being raised since # it returns a non-JSON 204 response even if it's successful. We just catch # that and bubble it up in a nicer way. if e.api_response.status_code == 204 PingResult.new(e.api_response) else raise e end end |
#update(id, options = {}) ⇒ Resources::Webhook
Updates a webhook by ID
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/duffel_api/services/webhooks_service.rb', line 55 def update(id, = {}) path = substitute_url_pattern("/air/webhooks/:id", "id" => id) params = .delete(:params) || {} [:params] = {} [:params]["data"] = params begin response = make_request(:patch, path, ) # Response doesn't raise any errors until #body is called response.tap(&:raw_body) end return if response.raw_body.nil? Resources::Webhook.new(unenvelope_body(response.parsed_body), response) end |