Class: AkamaiApi::ECCU::PublishRequest

Inherits:
BaseRequest show all
Defined in:
lib/akamai_api/eccu/publish_request.rb

Overview

PublishRequest is responsible of publishing a new ECCU request.

Examples:

content = File.read './publish.xml'
begin
  req = AkamaiApi::ECCU::PublishRequest.new 'http://foo.bar/t.txt'
  code = req.execute content, file_name: 'publish.xml', emails: '[email protected]'
  puts "Request enqueued with code #{code}"
rescue AkamaiApi::Unauthorized
  puts "Invalid login credentials"
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseRequest

#client, #client_call

Constructor Details

#initialize(property_name, args = {}) ⇒ PublishRequest

Returns a new instance of PublishRequest.

Parameters:

  • property_name (String)

    Digital property name

  • args (Hash<Symbol, String>) (defaults to: {})

    Additional arguments

Options Hash (args):

  • :type (String) — default: 'hostheader'

    Digital property type

  • :exact_match (true, false) — default: true

    Digital property match type



29
30
31
32
33
# File 'lib/akamai_api/eccu/publish_request.rb', line 29

def initialize property_name, args = {}
  @property_name = property_name
  @property_type = args.fetch(:type, 'hostheader')
  @property_exact_match = args.fetch(:exact_match, true) == true
end

Instance Attribute Details

#property_exact_matchtrue, false (readonly)

Returns Digital property match type (true if exact).

Returns:

  • (true, false)

    Digital property match type (true if exact)



23
24
25
# File 'lib/akamai_api/eccu/publish_request.rb', line 23

def property_exact_match
  @property_exact_match
end

#property_nameString (readonly)

Returns Digital property name.

Returns:

  • (String)

    Digital property name



19
20
21
# File 'lib/akamai_api/eccu/publish_request.rb', line 19

def property_name
  @property_name
end

#property_typeString (readonly)

Returns Digital property type.

Returns:

  • (String)

    Digital property type



21
22
23
# File 'lib/akamai_api/eccu/publish_request.rb', line 21

def property_type
  @property_type
end

Instance Method Details

#execute(content, args = {}) ⇒ Object

Publishes a new ECCU request

Parameters:

  • content (String)

    content of the ECCU request

  • args (Hash<Symbol, String>) (defaults to: {})

    Additional arguments

Options Hash (args):

  • :file_name (String) — default: ''

    file name to set in the request

  • :notes (String) — default: 'ECCU Request using AkamaiApi <VERSION>'

    notes of the ECCU request

  • :version (String) — default: ''

    request version number

  • :emails (String, Array<String>)

    emails to notify when the request has been completed



42
43
44
45
46
47
# File 'lib/akamai_api/eccu/publish_request.rb', line 42

def execute content, args = {}
  with_soap_error_handling do
    response = client_call :upload, message_tag: 'upload', message: request_body(content, args).to_s
    response[:file_id].to_i
  end
end

#request_body(content, args) ⇒ SoapBody (protected)

Creates the request body filling it with all necessary arguments

Returns:



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/akamai_api/eccu/publish_request.rb', line 53

def request_body content, args
  SoapBody.new.tap do |body|
    body.string :filename,               args.fetch(:file_name, '')
    body.text   :contents,               content
    body.string :notes,                  args.fetch(:notes, "ECCU Request using AkamaiApi #{AkamaiApi::VERSION}")
    body.string :versionString,          args.fetch(:version, '')
    if args[:emails]
      body.string :statusChangeEmail,    Array.wrap(args[:emails]).join(',')
    end
    body.string      :propertyName,           property_name
    body.string      :propertyType,           property_type
    body.boolean     :propertyNameExactMatch, property_exact_match
  end
end

#with_soap_error_handling(&block) ⇒ Object (protected)



68
69
70
71
72
73
# File 'lib/akamai_api/eccu/publish_request.rb', line 68

def with_soap_error_handling &block
  super
rescue Savon::SOAPFault => e
  e = AkamaiApi::ECCU::InvalidDomain if e.to_hash[:fault][:faultstring].include? 'You are not authorized to specify this digital property'
  raise e
end