class Akamai::Client::Papi

Public Instance Methods

add_rule(params, options = {}) click to toggle source
# File lib/akamai/client/papi.rb, line 126
def add_rule(params, options = {})
  params_indiff = params.with_indifferent_access
  rules = get_rule_tree(params_indiff[:property_id], params_indiff[:version], options)[:rules]
  unless params_indiff[:parent_node].blank?
    return add_rule_to_sub_node(params_indiff, rules, options)
  end
  rules[:children] << params_indiff[:rule]
  update_rule_tree(params_indiff[:property_id], params_indiff[:version], rules, options)
end
create_new_activation(params, options = {}) click to toggle source
# File lib/akamai/client/papi.rb, line 104
def create_new_activation(params, options = {})
  path = build_full_path(
    "properties/#{params[:property_id]}/activations",
    options
  )
  body = {
    notifyEmails: params[:notify_emails] ? params[:notify_emails] : [],
    network: params[:network], propertyVersion: params[:version],
    note: params[:note] ? params[:note] : "", acknowledgeWarnings: []
  }
  retry_create_activation(path, body)
end
create_property_version(property_id, from_version, from_etag, options = {}) click to toggle source
# File lib/akamai/client/papi.rb, line 95
def create_property_version(property_id, from_version, from_etag, options = {})
  path = build_full_path(
    "properties/#{property_id}/versions",
    options
  )
  body = { createFromVersion: from_version, createFromVersionEtag: from_etag }.to_json
  client.post(path, body).body.to_hash["versionLink"].split("/")[-1].to_i
end
get_custom_behavior(behavior_id) click to toggle source
# File lib/akamai/client/papi.rb, line 72
def get_custom_behavior(behavior_id)
  get("custom-behaviors", behavior_id: behavior_id)
end
get_latest_property_version(property_id, options = {}) click to toggle source
# File lib/akamai/client/papi.rb, line 87
def get_latest_property_version(property_id, options = {})
  path = build_full_path(
    "properties/#{property_id}/versions/latest",
    options
  )
  client.get(path).body.to_hash["versionLink"].split("/")[-1].to_i
end
get_property(property_id, contract_id, group_id) click to toggle source
# File lib/akamai/client/papi.rb, line 55
def get_property(property_id, contract_id, group_id)
  get(
    "properties/#{property_id}", contract_id: contract_id, group_id: group_id
  )
end
get_property_version(property_id, version, options = {}) click to toggle source
# File lib/akamai/client/papi.rb, line 76
def get_property_version(property_id, version, options = {})
  path = build_full_path(
    "properties/#{property_id}/versions/#{version}",
    options
  )
  response = client.get(path)
  transform_to_snakecase(
    response.body[:versions][:items]
  )[0]
end
get_rule_tree(property_id, version, options = {}) click to toggle source
# File lib/akamai/client/papi.rb, line 61
def get_rule_tree(property_id, version, options = {})
  path = build_full_path(
    "properties/#{property_id}/versions/#{version}/rules",
    options
  )
  response = client.get(path)
  transform_to_snakecase(
    response.body
  )
end
list_contracts() click to toggle source
# File lib/akamai/client/papi.rb, line 10
def list_contracts
  get(:contracts)
end
list_cp_codes(contract_id, group_id) click to toggle source
# File lib/akamai/client/papi.rb, line 22
def list_cp_codes(contract_id, group_id)
  get(:cpcodes, contract_id: contract_id, group_id: group_id)
end
list_custom_behaviors() click to toggle source
# File lib/akamai/client/papi.rb, line 14
def list_custom_behaviors
  get("custom-behaviors")
end
list_edge_hostnames(contract_id, group_id, options = {}) click to toggle source
# File lib/akamai/client/papi.rb, line 51
def list_edge_hostnames(contract_id, group_id, options = {})
  get(:edgeHostnames, {contract_id: contract_id, group_id: group_id}.merge(options))
end
list_groups() click to toggle source
# File lib/akamai/client/papi.rb, line 6
def list_groups
  get(:groups)
end
list_hostnames(property_id, property_version, options = {}) click to toggle source
# File lib/akamai/client/papi.rb, line 40
def list_hostnames(property_id, property_version, options = {})
  path = build_full_path(
    "properties/#{property_id}/versions/#{property_version}/hostnames",
    options
  )
  response = client.get(path)
  transform_to_snakecase(
    response.body[:hostnames][:items]
  )
end
list_products(contract_id) click to toggle source
# File lib/akamai/client/papi.rb, line 18
def list_products(contract_id)
  get(:products, contract_id: contract_id)
end
list_properties(contract_id, group_id) click to toggle source
# File lib/akamai/client/papi.rb, line 26
def list_properties(contract_id, group_id)
  get(:properties, contract_id: contract_id, group_id: group_id)
end
list_property_versions(property_id, options = {}) click to toggle source
# File lib/akamai/client/papi.rb, line 30
def list_property_versions(property_id, options = {})
  path = build_full_path(
    "properties/#{property_id}/versions", options
  )
  response = client.get(path)
  transform_to_snakecase(
    response.body[:versions][:items]
  )
end
update_rule_tree(property_id, version, rules, options = {}) click to toggle source
# File lib/akamai/client/papi.rb, line 117
def update_rule_tree(property_id, version, rules, options = {})
  path = build_full_path(
    "properties/#{property_id}/versions/#{version}/rules",
    options
  )
  body = { rules: rules }.to_json
  client.put(path, body)
end

Private Instance Methods

add_rule_to_sub_node(params, rules, options) click to toggle source
# File lib/akamai/client/papi.rb, line 138
def add_rule_to_sub_node(params, rules, options)
  separator = params[:separator] ? params[:separator] : ":"
  target_nodes = rules[:children]
  params[:parent_node].split(separator).each do |node|
    target_nodes = find_node(node, target_nodes)
  end
  raise(Error::DuplicateError) if target_nodes.select do |child|
                                    child[:name] == params[:rule][:name]
                                  end.present?
  target_nodes << params[:rule]
  update_rule_tree(params[:property_id], params[:version], rules, options)
end
base_path() click to toggle source
# File lib/akamai/client/papi.rb, line 170
def base_path
  "/papi/v1"
end
find_node(node, nodes) click to toggle source
# File lib/akamai/client/papi.rb, line 151
def find_node(node, nodes)
  parenet_node = nodes.select do |child|
    child[:name] == node
  end
  raise(Error::NoExistError) if parenet_node.blank?
  parenet_node[0][:children]
end
retry_create_activation(path, body, retry_num = 1) click to toggle source
# File lib/akamai/client/papi.rb, line 159
def retry_create_activation(path, body, retry_num = 1)
  client.post(path, body.to_json)
rescue Akamai::Core::Client::Error::AkamaiError => e
  raise(e) unless retry_num.positive?
  e.body[:warnings].each do |warning|
    body[:acknowledgeWarnings] << warning[:messageId]
  end
  retry_num -= 1
  retry
end