Class: Blurb::Profile

Inherits:
BaseClass show all
Defined in:
lib/blurb/profile.rb

Constant Summary

Constants inherited from BaseClass

BaseClass::CAMPAIGN_TYPE_CODES

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(profile_id:, account:) ⇒ Profile

Returns a new instance of Profile.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/blurb/profile.rb', line 27

def initialize(profile_id:, account:)
  @profile_id = profile_id
  @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: "#{.api_url}/v2/sp/productAds"
  )
  @sd_product_ads = RequestCollection.new(
    headers: headers_hash,
    base_url: "#{.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

Instance Attribute Details

#accountObject

Returns the value of attribute account.



13
14
15
# File 'lib/blurb/profile.rb', line 13

def 
  @account
end

#ad_groupsObject

Returns the value of attribute ad_groups.



13
14
15
# File 'lib/blurb/profile.rb', line 13

def ad_groups
  @ad_groups
end

#campaign_negative_keywordsObject

Returns the value of attribute campaign_negative_keywords.



13
14
15
# File 'lib/blurb/profile.rb', line 13

def campaign_negative_keywords
  @campaign_negative_keywords
end

#historyObject

Returns the value of attribute history.



13
14
15
# File 'lib/blurb/profile.rb', line 13

def history
  @history
end

#portfoliosObject

Returns the value of attribute portfolios.



13
14
15
# File 'lib/blurb/profile.rb', line 13

def portfolios
  @portfolios
end

#product_adsObject

Returns the value of attribute product_ads.



13
14
15
# File 'lib/blurb/profile.rb', line 13

def product_ads
  @product_ads
end

#profile_idObject

Returns the value of attribute profile_id.



13
14
15
# File 'lib/blurb/profile.rb', line 13

def profile_id
  @profile_id
end

#sd_ad_groupsObject

Returns the value of attribute sd_ad_groups.



13
14
15
# File 'lib/blurb/profile.rb', line 13

def sd_ad_groups
  @sd_ad_groups
end

#sd_product_adsObject

Returns the value of attribute sd_product_ads.



13
14
15
# File 'lib/blurb/profile.rb', line 13

def sd_product_ads
  @sd_product_ads
end

#suggested_keywordsObject

Returns the value of attribute suggested_keywords.



13
14
15
# File 'lib/blurb/profile.rb', line 13

def suggested_keywords
  @suggested_keywords
end

#targetsObject

Returns the value of attribute targets.



13
14
15
# File 'lib/blurb/profile.rb', line 13

def targets
  @targets
end

Instance Method Details

#campaigns(campaign_type) ⇒ Object



138
139
140
141
142
# 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 = {}) ⇒ Object



185
186
187
188
189
190
191
192
193
194
195
196
# 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) ⇒ Object



144
145
146
147
# 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) ⇒ Object



149
150
151
152
# 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_detailsObject



181
182
183
# File 'lib/blurb/profile.rb', line 181

def profile_details
  @account.retrieve_profile(@profile_id)
end

#reports(campaign_type) ⇒ Object



159
160
161
162
163
# 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) ⇒ Object



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# 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) ⇒ Object



154
155
156
157
# 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