lib/blurb/campaign.rb in blurb-0.1.2 vs lib/blurb/campaign.rb in blurb-0.2.0
- old
+ new
@@ -1,45 +1,45 @@
module Blurb
class Campaign < BaseResource
- def self.retrieve(campaign_id)
- get_request("/v1/campaigns/#{campaign_id}")
+ SPONSORED_PRODUCTS = "sp"
+ SPONSORED_BRANDS = "hsa"
+
+ def self.retrieve(campaign_id, campaign_type)
+ get_request("/v2/#{campaign_type}/campaigns/#{campaign_id}")
end
- def self.retrieve_extended(campaign_id)
- get_request("/v1/campaigns/extended/#{campaign_id}")
+ def self.retrieve_extended(campaign_id, campaign_type)
+ get_request("/v2/#{campaign_type}/campaigns/extended/#{campaign_id}")
end
- def self.list(params = {}, opts = {})
- get_request("/v1/campaigns?#{setup_url_params(params)}")
+ def self.list(campaign_type, params = {}, opts = {})
+ get_request("/v2/#{campaign_type}/campaigns?#{setup_url_params(params)}")
end
- def self.create(params = {}, opts = {})
+ def self.create(campaign_type, params = {}, opts = {})
# required argument checks
- if !params["name"] && !params["campaignType"] && !params["targetingType"] && !params["state"] && !params["dailyBudget"] && !params["startDate"]
- raise ArgumentError.new("params hash must contain name, campaignType, targetingType, state, dailyBudget and startDate")
+ 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 campaigns can be created through the api. Sponsored Brands campaigns must be created through the user interface") unless campaign_type = SPONSORED_PRODUCTS
- post_request("/v1/campaigns", [params])
+ post_request("/v2/#{campaign_type}/campaigns", [params])
end
- def self.create_bulk(campaign_array, opts = {})
- post_request("/v1/campaigns", campaign_array)
- end
+ # Deprecated in v2
+ # def self.create_bulk(campaign_array, opts = {})
+ # post_request("/v1/campaigns", campaign_array)
+ # end
private
def self.setup_url_params(params)
url_params = ""
url_params = "startIndex=#{params['startIndex']}" if params['startIndex']
if params['count']
url_params += "&" if url_params.size > 0
url_params += "count=#{params['count']}"
- end
-
- if params['campaignType']
- url_params += "&" if url_params.size > 0
- url_params += "campaignType=#{params['campaignType']}"
end
if params['stateFilter']
url_params += "&" if url_params.size > 0
url_params += "stateFilter=#{params['stateFilter']}"