Class: AkamaiApi::CCU::Purge::Request

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/akamai_api/ccu/purge/request.rb

Overview

AkamaiApi::CCU::Purge encapsulates the behavior needed to purge a resource from Akamai via CCU.

Examples:

Remove a single ARL

AkamaiApi::CCU::Purge::Request.new.execute('http://foo.bar/t.txt')

Invalidate multiple CPCodes

AkamaiApi::CCU::Purge::Request.new(:invalidate, :cpcode).execute(12345, 12346)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(action = :remove, type = :arl, args = {}) ⇒ Request

Returns a new instance of Request.

Parameters:

  • action (String) (defaults to: :remove)

    type of clean action. See #action for allowed values

  • type (String) (defaults to: :arl)

    resource type. See #type for allowed values

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

    optional arguments

Options Hash (args):

  • :domain (String) — default: :production

    Domain type. See #domain for allowed values



29
30
31
32
33
# File 'lib/akamai_api/ccu/purge/request.rb', line 29

def initialize action = :remove, type=:arl, args = {}
  self.action = action
  self.type   = type
  self.domain = args[:domain] || :production
end

Instance Attribute Details

#action:invalidate, :remove

Clean action type.

Returns:

  • (:invalidate)

    when you want to simply mark resources as invalid

  • (:remove)

    when you want to force resources removal

Raises:



40
41
42
# File 'lib/akamai_api/ccu/purge/request.rb', line 40

def action
  @action
end

#domain:production, :staging

Domain type to target.

Returns:

  • (:production)

    production environment

  • (:staging)

    staging environment

Raises:



60
61
62
# File 'lib/akamai_api/ccu/purge/request.rb', line 60

def domain
  @domain
end

#type:cpcode, :arl

Resource type.

Returns:

  • (:cpcode)

    when request targets entire CPCode(s)

  • (:arl)

    when request targets single ARL(s)

Raises:



50
51
52
# File 'lib/akamai_api/ccu/purge/request.rb', line 50

def type
  @type
end

Instance Method Details

#execute(*items) ⇒ Response

Clean the requested resources.

Examples:

Clean a single resource

request.execute 'http://foo.bar/t.txt'

Clean multiple resources

request.execute '12345', '12346'

Parameters:

  • items (Array<String>)

    One or more resources to clean

Returns:

  • (Response)

    an object representing the received response

Raises:



74
75
76
77
78
# File 'lib/akamai_api/ccu/purge/request.rb', line 74

def execute *items
  items = Array.wrap(items.first) if items.length == 1
  response = self.class.post('/', basic_auth: AkamaiApi.auth, body: request_body(items))
  parse_response response
end

#request_body(items) ⇒ String

Request body to send to the API.

Parameters:

  • items (Array<String>)

    resources to clean

Returns:

  • (String)

    request body in JSON format



83
84
85
# File 'lib/akamai_api/ccu/purge/request.rb', line 83

def request_body items
  { type: type, action: action, domain: domain, objects: items }.to_json
end