Class: CapistranoPayload::Payload
- Inherits:
-
Object
- Object
- CapistranoPayload::Payload
- Defined in:
- lib/capistrano-payload/payload.rb
Constant Summary collapse
- ACTIONS =
Allowed actions
['deploy', 'rollback']
Constants included from Request
Request::CONTENT_TYPES, Request::OPEN_TIMEOUT, Request::TIMEOUT
Constants included from Format
Format::FORMATS, Format::FORMAT_METHODS
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
-
#deliver(url) ⇒ Object
Performs payload delivery.
-
#initialize(action, message, data, format = :json, params = {}) ⇒ Payload
constructor
Initialize a new Payload object.
Methods included from Request
Methods included from Format
#to_hash, #to_json, #to_xml, #to_yaml
Constructor Details
#initialize(action, message, data, format = :json, params = {}) ⇒ Payload
Initialize a new Payload object
action - Deployment action (deploy, rollback) message - Deployment message (optional) data - Payload data format - Payload format (:json, :form). Default: json params - Extra parameters to payload (api_key, etc.), default: {}
Could not contain 'capistrano' key. Will be removed if present.
Should be a hash
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/capistrano-payload/payload.rb', line 25 def initialize(action, , data, format=:json, params={}) @action = action @message = .strip @data = data.merge(:action => @action, :message => @message) @format = format.to_sym @params = params.kind_of?(Hash) ? params : {} unless ACTIONS.include?(@action) raise ConfigurationError, "Invalid payload action: #{action}." end # Check if we have an invalid format unless FORMATS.include?(@format) raise ConfigurationError, "Invalid payload format: #{format}." end # Check if we have 'payload' keys (string or symbolic) unless @params.empty? @params.delete(:payload) @params.delete('payload') end end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
9 10 11 |
# File 'lib/capistrano-payload/payload.rb', line 9 def action @action end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
11 12 13 |
# File 'lib/capistrano-payload/payload.rb', line 11 def data @data end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
12 13 14 |
# File 'lib/capistrano-payload/payload.rb', line 12 def format @format end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
10 11 12 |
# File 'lib/capistrano-payload/payload.rb', line 10 def @message end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
13 14 15 |
# File 'lib/capistrano-payload/payload.rb', line 13 def params @params end |
Instance Method Details
#deliver(url) ⇒ Object
Performs payload delivery
url - Target url
52 53 54 55 56 57 58 59 |
# File 'lib/capistrano-payload/payload.rb', line 52 def deliver(url) payload = self.send(FORMAT_METHODS[@format]) begin request(:post, url, {:payload => payload}.merge(@params), format) rescue Exception => ex raise DeliveryError, ex. end end |