Class: Io::Flow::V0::Clients::Webhooks

Inherits:
Object
  • Object
show all
Defined in:
lib/flow_commerce/flow_api_v0_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Webhooks

Returns a new instance of Webhooks.



3435
3436
3437
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3435

def initialize(client)
  @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Flow::V0::Client)
end

Instance Method Details

#delete_by_id(organization, id) ⇒ Object

Delete a webhook with the specified id



3479
3480
3481
3482
3483
3484
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3479

def delete_by_id(organization, id)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('id', id, String)
  r = @client.request("/#{CGI.escape(organization)}/webhooks/#{CGI.escape(id)}").delete
  nil
end

#get(organization, incoming = {}) ⇒ Object

Returns webhooks for an organization



3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3440

def get(organization, incoming={})
  HttpClient::Preconditions.assert_class('organization', organization, String)
  opts = HttpClient::Helper.symbolize_keys(incoming)
  query = {
    :id => (x = opts.delete(:id); x.nil? ? nil : HttpClient::Preconditions.assert_class('id', x, Array).map { |v| HttpClient::Preconditions.assert_class('id', v, String) }),
    :limit => HttpClient::Preconditions.assert_class('limit', (x = opts.delete(:limit); x.nil? ? 25 : x), Integer),
    :offset => HttpClient::Preconditions.assert_class('offset', (x = opts.delete(:offset); x.nil? ? 0 : x), Integer),
    :sort => HttpClient::Preconditions.assert_class('sort', (x = opts.delete(:sort); x.nil? ? "-created_at" : x), String)
  }.delete_if { |k, v| v.nil? }
  r = @client.request("/#{CGI.escape(organization)}/webhooks").with_query(query).get
  r.map { |x| ::Io::Flow::V0::Models::Webhook.new(x) }
end

#get_by_id(organization, id) ⇒ Object

Returns information about a specific webhook



3462
3463
3464
3465
3466
3467
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3462

def get_by_id(organization, id)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('id', id, String)
  r = @client.request("/#{CGI.escape(organization)}/webhooks/#{CGI.escape(id)}").get
  ::Io::Flow::V0::Models::Webhook.new(r)
end

#get_settings(organization) ⇒ Object

Returns the webhook settings for an organization



3487
3488
3489
3490
3491
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3487

def get_settings(organization)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  r = @client.request("/#{CGI.escape(organization)}/webhooks/settings").get
  ::Io::Flow::V0::Models::WebhookSettings.new(r)
end

#post(organization, webhook_form) ⇒ Object

Create a new webhook



3454
3455
3456
3457
3458
3459
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3454

def post(organization, webhook_form)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  (x = webhook_form; x.is_a?(::Io::Flow::V0::Models::WebhookForm) ? x : ::Io::Flow::V0::Models::WebhookForm.new(x))
  r = @client.request("/#{CGI.escape(organization)}/webhooks").with_json(webhook_form.to_json).post
  ::Io::Flow::V0::Models::Webhook.new(r)
end

#put_by_id(organization, id, webhook_form) ⇒ Object

Update an existing webhook



3470
3471
3472
3473
3474
3475
3476
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3470

def put_by_id(organization, id, webhook_form)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('id', id, String)
  (x = webhook_form; x.is_a?(::Io::Flow::V0::Models::WebhookForm) ? x : ::Io::Flow::V0::Models::WebhookForm.new(x))
  r = @client.request("/#{CGI.escape(organization)}/webhooks/#{CGI.escape(id)}").with_json(webhook_form.to_json).put
  ::Io::Flow::V0::Models::Webhook.new(r)
end

#put_settings(organization, webhook_settings) ⇒ Object

Updates the webhook settings for an organization



3494
3495
3496
3497
3498
3499
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3494

def put_settings(organization, webhook_settings)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  (x = webhook_settings; x.is_a?(::Io::Flow::V0::Models::WebhookSettings) ? x : ::Io::Flow::V0::Models::WebhookSettings.new(x))
  r = @client.request("/#{CGI.escape(organization)}/webhooks/settings").with_json(webhook_settings.to_json).put
  ::Io::Flow::V0::Models::WebhookSettings.new(r)
end