Sha256: a83f02e669c107313663bf6a06034a08863ddfb0846c1b6c3f636d9d2bba0371

Contents?: true

Size: 1.96 KB

Versions: 2

Compression:

Stored size: 1.96 KB

Contents

module Blurb
  class AdGroup < BaseResource

    URL_PARAMS = ['startIndex', 'campaignType', 'count', 'matchTypeFilter', 'name', 'state', 'campaignIdFilter', 'adGroupIdFilter']

    def retrieve(keyword_id, campaign_type)
      raise ArgumentError.new("adGroups interface is only supported for Sponsored Products") unless campaign_type == SPONSORED_PRODUCTS
      get_request("/v2/#{campaign_type}/adGroups/#{keyword_id}")
    end

    def retrieve_extended(keyword_id, campaign_type)
      raise ArgumentError.new("adGroups interface is only supported for Sponsored Products") unless campaign_type == SPONSORED_PRODUCTS
      get_request("/v2/#{campaign_type}/adGroups/extended/#{keyword_id}")
    end

    def list(campaign_type, params = {}, opts = {})
      raise ArgumentError.new("adGroups interface is only supported for Sponsored Products") unless campaign_type == SPONSORED_PRODUCTS
      get_request("/v2/#{campaign_type}/adGroups?#{setup_url_params(params, URL_PARAMS)}")
    end

    def list_extended(campaign_type, params = {}, opts = {})
      raise ArgumentError.new("adGroups interface is only supported for Sponsored Products") unless campaign_type == SPONSORED_PRODUCTS
      get_request("/v2/#{campaign_type}/adGroups/extended?#{setup_url_params(params, URL_PARAMS)}")
    end

    def create(campaign_type, params = {}, opts = {})
      # required argument checks
      if !params["name"] && !params["targetingType"] && !params["state"] && !params["dailyBudget"] && !params["startDate"]
        raise ArgumentError.new("params hash must contain name, targetingType, state, dailyBudget and startDate")
      end
      raise ArgumentError.new("Only sponsored product adGroups can be created through the api.  Sponsored Brands adGroups must be created through the user interface") unless campaign_type == SPONSORED_PRODUCTS

      post_request("/v2/#{campaign_type}/adGroups", [params])
    end

    def delete(keyword_id)
      delete_request("/v2/adGroups/#{keyword_id}")
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
blurb-0.3.2 lib/blurb/ad_group.rb
blurb-0.3.1 lib/blurb/ad_group.rb