class Blurb::Profile

Attributes

account[RW]
ad_groups[RW]
campaign_negative_keywords[RW]
history[RW]
portfolios[RW]
product_ads[RW]
profile_id[RW]
sd_ad_groups[RW]
sd_product_ads[RW]
suggested_keywords[RW]
targets[RW]

Public Class Methods

new(profile_id:, account:) click to toggle source
# File lib/blurb/profile.rb, line 27
def initialize(profile_id:, account:)
  @profile_id = profile_id
  @account = account

  @sp_campaigns = CampaignRequests.new(
    headers: headers_hash,
    base_url: @account.api_url,
    resource: "campaigns",
    campaign_type: CAMPAIGN_TYPE_CODES[:sp]
  )
  @sb_campaigns = CampaignRequests.new(
    headers: headers_hash,
    base_url: @account.api_url,
    resource: "campaigns",
    campaign_type: CAMPAIGN_TYPE_CODES[:sb],
    bulk_api_limit: 10
  )
  @sd_campaigns = CampaignRequests.new(
    headers: headers_hash,
    base_url: @account.api_url,
    resource: "campaigns",
    campaign_type: CAMPAIGN_TYPE_CODES[:sd],
    bulk_api_limit: 10
  )
  @sp_keywords = RequestCollectionWithCampaignType.new(
    headers: headers_hash,
    base_url: @account.api_url,
    resource: "keywords",
    campaign_type: CAMPAIGN_TYPE_CODES[:sp]
  )
  @sb_keywords = RequestCollectionWithCampaignType.new(
    headers: headers_hash,
    base_url: @account.api_url,
    resource: "keywords",
    campaign_type: CAMPAIGN_TYPE_CODES[:sb]
  )
  @sp_snapshots = SnapshotRequests.new(
    headers: headers_hash,
    base_url: @account.api_url,
    campaign_type: CAMPAIGN_TYPE_CODES[:sp]
  )
  @sb_snapshots = SnapshotRequests.new(
    headers: headers_hash,
    base_url: @account.api_url,
    campaign_type: CAMPAIGN_TYPE_CODES[:sb]
  )
  @sp_reports = ReportRequests.new(
    headers: headers_hash,
    base_url: @account.api_url,
    campaign_type: CAMPAIGN_TYPE_CODES[:sp]
  )
  @sd_reports = ReportRequests.new(
    headers: headers_hash,
    base_url: @account.api_url,
    campaign_type: CAMPAIGN_TYPE_CODES[:sd]
  )
  @sb_reports = ReportRequests.new(
    headers: headers_hash,
    base_url: @account.api_url,
    campaign_type: CAMPAIGN_TYPE_CODES[:sb]
  )
  @ad_groups = RequestCollection.new(
    headers: headers_hash,
    base_url: "#{@account.api_url}/v2/sp/adGroups"
  )
  @sd_ad_groups = RequestCollection.new(
    headers: headers_hash,
    base_url: "#{@account.api_url}/sd/adGroups"
  )
  @product_ads = RequestCollection.new(
    headers: headers_hash,
    base_url: "#{account.api_url}/v2/sp/productAds"
  )
  @sd_product_ads = RequestCollection.new(
    headers: headers_hash,
    base_url: "#{account.api_url}/sd/productAds"
  )
  @sp_negative_keywords = RequestCollectionWithCampaignType.new(
    headers: headers_hash,
    base_url: @account.api_url,
    resource: 'negativeKeywords',
    campaign_type: CAMPAIGN_TYPE_CODES[:sp]
  )
  @sb_negative_keywords = RequestCollectionWithCampaignType.new(
    headers: headers_hash,
    base_url: @account.api_url,
    resource: 'negativeKeywords',
    campaign_type: CAMPAIGN_TYPE_CODES[:sb]
  )
  @campaign_negative_keywords = RequestCollection.new(
    headers: headers_hash,
    base_url: "#{@account.api_url}/v2/sp/campaignNegativeKeywords"
  )
  @targets = RequestCollection.new(
    headers: headers_hash,
    base_url: "#{@account.api_url}/v2/sp/targets"
  )
  @portfolios = RequestCollection.new(
    headers: headers_hash,
    base_url: "#{@account.api_url}/v2/portfolios"
  )
  @suggested_keywords = SuggestedKeywordRequests.new(
    headers: headers_hash,
    base_url: "#{@account.api_url}/v2/sp"
  )
  @history = HistoryRequest.new(
    headers: headers_hash,
    base_url: @account.api_url
  )
end

Public Instance Methods

campaigns(campaign_type) click to toggle source
# File lib/blurb/profile.rb, line 138
def campaigns(campaign_type)
  return @sp_campaigns if campaign_type == :sp
  return @sb_campaigns if campaign_type == :sb || campaign_type == :hsa
  return @sd_campaigns if campaign_type == :sd
end
headers_hash(opts = {}) click to toggle source
# File lib/blurb/profile.rb, line 185
def headers_hash(opts = {})
  headers_hash = {
    "Authorization" => "Bearer #{@account.retrieve_token()}",
    "Content-Type" => "application/json",
    "Amazon-Advertising-API-Scope" => @profile_id,
    "Amazon-Advertising-API-ClientId" => @account.client.client_id
  }

  headers_hash["Content-Encoding"] = "gzip" if opts[:gzip]

  return headers_hash
end
keywords(campaign_type) click to toggle source
# File lib/blurb/profile.rb, line 144
def keywords(campaign_type)
  return @sp_keywords if campaign_type == :sp
  return @sb_keywords if campaign_type == :sb || campaign_type == :hsa
end
negative_keywords(campaign_type) click to toggle source
# File lib/blurb/profile.rb, line 149
def negative_keywords(campaign_type)
  return @sp_negative_keywords if campaign_type == :sp
  return @sb_negative_keywords if campaign_type == :sb || campaign_type == :hsa
end
profile_details() click to toggle source
# File lib/blurb/profile.rb, line 181
def profile_details
  @account.retrieve_profile(@profile_id)
end
reports(campaign_type) click to toggle source
# File lib/blurb/profile.rb, line 159
def reports(campaign_type)
  return @sp_reports if campaign_type == :sp
  return @sb_reports if campaign_type == :sb || campaign_type == :hsa
  return @sd_reports if campaign_type == :sd
end
request(api_path: "",request_type: :get, payload: nil, url_params: nil, headers: headers_hash) click to toggle source
# File lib/blurb/profile.rb, line 165
def request(api_path: "",request_type: :get, payload: nil, url_params: nil, headers: headers_hash)
  @base_url = @account.api_url

  url = "#{@base_url}#{api_path}"

  request = Request.new(
    url: url,
    url_params: url_params,
    request_type: request_type,
    payload: payload,
    headers: headers
  )

  request.make_request
end
snapshots(campaign_type) click to toggle source
# File lib/blurb/profile.rb, line 154
def snapshots(campaign_type)
  return @sp_snapshots if campaign_type == :sp
  return @sb_snapshots if campaign_type == :sb || campaign_type == :hsa
end