1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/rackspace/models/auto_scale/webhook.rb

105 lines
3.4 KiB
Ruby
Raw Normal View History

require 'fog/core/model'
module Fog
module Rackspace
class AutoScale
class Webhook < Fog::Model
# @!attribute [r] id
# @return [String] The webhook id
identity :id
# @!attribute [r] id
# @return [String] The group id (i.e. grand-parent)
attribute :group_id
# @!attribute [r] id
# @return [String] The policy id (i.e. parent)
attribute :policy_id
# @!attribute [r] name
# @return [String] The webhook name
attribute :name
# @!attribute [r] metadata
# @return [Hash] The metadata
attribute :metadata
# @!attribute [r] links
# @return [Array] The webhook links
attribute :links
# Creates webhook
# * requires attribute: :name
#
# @return [Boolean] returns true if webhook is being created
#
# @raise [Fog::Rackspace::AutoScale:::NotFound] - HTTP 404
# @raise [Fog::Rackspace::AutoScale:::BadRequest] - HTTP 400
# @raise [Fog::Rackspace::AutoScale:::InternalServerError] - HTTP 500
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
#
# @see Webhooks#create
# @see
def save
requires :name
options = {}
options['name'] = name unless name.nil?
options['metadata'] = metadata unless metadata.nil?
data = service.create_webhook(group_id, policy_id, options)
merge_attributes(data.body['webhooks'][0])
true
end
# Updates the webhook
#
# @return [Boolean] returns true if webhook has started updating
#
# @raise [Fog::Rackspace::AutoScale:::NotFound] - HTTP 404
# @raise [Fog::Rackspace::AutoScale:::BadRequest] - HTTP 400
# @raise [Fog::Rackspace::AutoScale:::InternalServerError] - HTTP 500
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
#
# @see http://docs.rackspace.com/cas/api/v1.0/autoscale-devguide/content/PUT_putWebhook_v1.0__tenantId__groups__groupId__policies__policyId__webhooks__webhookId__Webhooks.html
def update
requires :identity
options = {
'name' => name,
'metadata' => metadata
}
data = service.update_webhook(group_id, policy_id, identity, options)
merge_attributes(data.body)
end
# Destroy the webhook
#
# @return [Boolean] returns true if webhook has started deleting
#
# @raise [Fog::Rackspace::AutoScale:::NotFound] - HTTP 404
# @raise [Fog::Rackspace::AutoScale:::BadRequest] - HTTP 400
# @raise [Fog::Rackspace::AutoScale:::InternalServerError] - HTTP 500
# @raise [Fog::Rackspace::AutoScale:::ServiceError]
#
# @see http://docs.rackspace.com/cas/api/v1.0/autoscale-devguide/content/DELETE_deleteWebhook_v1.0__tenantId__groups__groupId__policies__policyId__webhooks__webhookId__Webhooks.html
def destroy
requires :identity
service.delete_webhook(group_id, policy_id, identity)
true
end
# Retrieves the URL for anonymously executing the policy webhook
# @return [String] the URL
def execution_url
requires :links
link = links.find { |l| l['rel'] == 'capability' }
link['href'] rescue nil
end
end
end
end
end