amazon-ads 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +38 -18
- data/lib/amazon_ads/api.rb +52 -100
- data/lib/amazon_ads/apis/ad_associations.rb +29 -0
- data/lib/amazon_ads/apis/ad_extensions.rb +23 -0
- data/lib/amazon_ads/apis/ad_groups.rb +29 -0
- data/lib/amazon_ads/apis/ads.rb +29 -0
- data/lib/amazon_ads/apis/advertising_deal_targets.rb +23 -0
- data/lib/amazon_ads/apis/advertising_deals.rb +29 -0
- data/lib/amazon_ads/apis/brand_store_edition_publish_versions.rb +17 -0
- data/lib/amazon_ads/apis/brand_store_editions.rb +11 -0
- data/lib/amazon_ads/apis/brand_store_pages.rb +11 -0
- data/lib/amazon_ads/apis/brand_stores.rb +11 -0
- data/lib/amazon_ads/apis/branded_keywords_pricings.rb +11 -0
- data/lib/amazon_ads/apis/campaign_forecasts.rb +11 -0
- data/lib/amazon_ads/apis/campaigns.rb +29 -0
- data/lib/amazon_ads/apis/commitment_spends.rb +11 -0
- data/lib/amazon_ads/apis/commitments.rb +29 -0
- data/lib/amazon_ads/apis/keyword_reservation_validations.rb +11 -0
- data/lib/amazon_ads/apis/marketing_stream.rb +72 -0
- data/lib/amazon_ads/apis/profiles.rb +15 -15
- data/lib/amazon_ads/apis/recommendation_types.rb +11 -0
- data/lib/amazon_ads/apis/recommendations.rb +11 -0
- data/lib/amazon_ads/apis/reporting.rb +29 -0
- data/lib/amazon_ads/apis/targets.rb +29 -0
- data/lib/amazon_ads/lwa.rb +35 -60
- data/lib/amazon_ads/version.rb +1 -1
- data/lib/amazon_ads.rb +31 -22
- metadata +41 -18
- data/lib/amazon_ads/apis/sponsored_products.rb +0 -76
- data/lib/amazon_ads/client.rb +0 -38
- data/lib/amazon_ads/configuration.rb +0 -34
- data/lib/amazon_ads/errors.rb +0 -43
- data/sig/generated/amazon_ads/api.rbs +0 -61
- data/sig/generated/amazon_ads/apis/profiles.rbs +0 -20
- data/sig/generated/amazon_ads/apis/sponsored_products.rbs +0 -52
- data/sig/generated/amazon_ads/client.rbs +0 -28
- data/sig/generated/amazon_ads/configuration.rbs +0 -24
- data/sig/generated/amazon_ads/errors.rbs +0 -35
- data/sig/generated/amazon_ads/lwa.rbs +0 -39
- data/sig/generated/amazon_ads.rbs +0 -16
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module AmazonAds
|
|
4
|
+
# Amazon Marketing Stream
|
|
5
|
+
class MarketingStream < API
|
|
6
|
+
# Create a new subscription Note: trailing slash in request uri is not allowed
|
|
7
|
+
# @rbs client_request_token: String -- Unique value supplied by the caller used to track identical API requests. Should request be re-tried, the caller should supply the same value. We recommend using GUID.
|
|
8
|
+
# @rbs data_set_id: String -- Identifier of data set, callers can be subscribed to. Please refer to https://advertising.amazon.com/API/docs/en-us/amazon-marketing-stream/data-guide for the list of all data sets.
|
|
9
|
+
# @rbs destination_arn: String -- AWS ARN of the destination endpoint associated with the subscription. Supported destination types: - SQS
|
|
10
|
+
# @rbs notes: String -- Additional details associated with the subscription
|
|
11
|
+
#: (client_request_token: String, data_set_id: String, ?destination: untyped?, ?destination_arn: String?, ?notes: String?) -> HTTP::Response
|
|
12
|
+
def create_dsp_stream_subscription(client_request_token:, data_set_id:, destination: nil, destination_arn: nil, notes: nil)
|
|
13
|
+
request(:post, "/dsp/streams/subscriptions", json: { "clientRequestToken" => client_request_token, "dataSetId" => data_set_id, "destination" => destination, "destinationArn" => destination_arn, "notes" => notes }.compact, headers: { "Content-Type" => "application/vnd.amazonmarketingstreamsubscriptions.v1+json" })
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Create a new subscription Note: trailing slash in request uri is not allowed
|
|
17
|
+
# @rbs client_request_token: String -- Unique value supplied by the caller used to track identical API requests. Should request be re-tried, the caller should supply the same value. We recommend using GUID.
|
|
18
|
+
# @rbs data_set_id: String -- Identifier of data set, callers can be subscribed to. Please refer to https://advertising.amazon.com/API/docs/en-us/amazon-marketing-stream/data-guide for the list of all data sets.
|
|
19
|
+
# @rbs destination_arn: String -- AWS ARN of the destination endpoint associated with the subscription. Supported destination types: - SQS
|
|
20
|
+
# @rbs notes: String -- Additional details associated with the subscription
|
|
21
|
+
#: (client_request_token: String, data_set_id: String, ?destination: untyped?, ?destination_arn: String?, ?notes: String?) -> HTTP::Response
|
|
22
|
+
def create_stream_subscription(client_request_token:, data_set_id:, destination: nil, destination_arn: nil, notes: nil)
|
|
23
|
+
request(:post, "/streams/subscriptions", json: { "clientRequestToken" => client_request_token, "dataSetId" => data_set_id, "destination" => destination, "destinationArn" => destination_arn, "notes" => notes }.compact, headers: { "Content-Type" => "application/vnd.amazonmarketingstreamsubscriptions.v1+json" })
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Fetch a specific subscription by Id Note: trailing slash in request uri is not allowed
|
|
27
|
+
# @rbs subscription_id: String -- Unique subscription identifier
|
|
28
|
+
#: (String) -> HTTP::Response
|
|
29
|
+
def get_dsp_stream_subscription(subscription_id)
|
|
30
|
+
request(:get, "/dsp/streams/subscriptions/#{subscription_id}")
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Fetch a specific subscription by Id Note: trailing slash in request uri is not allowed
|
|
34
|
+
# @rbs subscription_id: String -- Unique subscription identifier
|
|
35
|
+
#: (String) -> HTTP::Response
|
|
36
|
+
def get_stream_subscription(subscription_id)
|
|
37
|
+
request(:get, "/streams/subscriptions/#{subscription_id}")
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# List subscriptions Note: trailing slash in request uri is not allowed
|
|
41
|
+
# @rbs max_results: Numeric -- desired number of entries in the response, defaults to maximum value
|
|
42
|
+
# @rbs starting_token: String -- Token which can be used to get the next page of results, if more entries exist
|
|
43
|
+
#: (?max_results: Numeric?, ?starting_token: String?) -> HTTP::Response
|
|
44
|
+
def list_dsp_stream_subscriptions(max_results: nil, starting_token: nil)
|
|
45
|
+
request(:get, "/dsp/streams/subscriptions", params: { "maxResults" => max_results, "startingToken" => starting_token }.compact)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# List subscriptions Note: trailing slash in request uri is not allowed
|
|
49
|
+
# @rbs max_results: Numeric -- desired number of entries in the response, defaults to maximum value
|
|
50
|
+
# @rbs starting_token: String -- Token which can be used to get the next page of results, if more entries exist
|
|
51
|
+
#: (?max_results: Numeric?, ?starting_token: String?) -> HTTP::Response
|
|
52
|
+
def list_stream_subscriptions(max_results: nil, starting_token: nil)
|
|
53
|
+
request(:get, "/streams/subscriptions", params: { "maxResults" => max_results, "startingToken" => starting_token }.compact)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Update an existing subscription Note: trailing slash in request uri is not allowed
|
|
57
|
+
# @rbs subscription_id: String -- Unique subscription identifier
|
|
58
|
+
# @rbs notes: String -- Additional details associated with the subscription
|
|
59
|
+
#: (String, ?notes: String?, ?status: untyped?) -> HTTP::Response
|
|
60
|
+
def update_dsp_stream_subscription(subscription_id, notes: nil, status: nil)
|
|
61
|
+
request(:put, "/dsp/streams/subscriptions/#{subscription_id}", json: { "notes" => notes, "status" => status }.compact, headers: { "Content-Type" => "application/vnd.amazonmarketingstreamsubscriptions.v1+json" })
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Update an existing subscription Note: trailing slash in request uri is not allowed
|
|
65
|
+
# @rbs subscription_id: String -- Unique subscription identifier
|
|
66
|
+
# @rbs notes: String -- Additional details associated with the subscription
|
|
67
|
+
#: (String, ?notes: String?, ?status: untyped?) -> HTTP::Response
|
|
68
|
+
def update_stream_subscription(subscription_id, notes: nil, status: nil)
|
|
69
|
+
request(:put, "/streams/subscriptions/#{subscription_id}", json: { "notes" => notes, "status" => status }.compact, headers: { "Content-Type" => "application/vnd.amazonmarketingstreamsubscriptions.v1+json" })
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# rbs_inline: enabled
|
|
4
|
-
|
|
5
3
|
module AmazonAds
|
|
6
4
|
# Amazon Ads API - Profiles
|
|
7
|
-
#
|
|
8
|
-
# @see https://advertising.amazon.com/API/docs/en-us/reference/profiles
|
|
9
5
|
class Profiles < API
|
|
6
|
+
# Gets a profile specified by identifier.
|
|
7
|
+
#: (Integer) -> HTTP::Response
|
|
8
|
+
def get_profile_by_id(profile_id)
|
|
9
|
+
request(:get, "/v2/profiles/#{profile_id}")
|
|
10
|
+
end
|
|
11
|
+
|
|
10
12
|
# Gets a list of profiles.
|
|
11
|
-
|
|
13
|
+
# @rbs api_program: String -- Filters response to include profiles that have permissions for the specified Advertising API program only. Setting `apiProgram=billing` filters the response to include only profiles to which the user and application associated with the access token have permission to view or edit billing information.
|
|
14
|
+
# @rbs access_level: String -- Filters response to include profiles that have specified permissions for the specified Advertising API program only. Currently, the only supported access level is `view` and `edit`. Setting `accessLevel=view` filters the response to include only profiles to which the user and application associated with the access token have view permission to the provided api program.
|
|
15
|
+
# @rbs profile_type_filter: String -- Filters response to include profiles that are of the specified types in the comma-delimited list. Default is all types. Note that this filter performs an inclusive AND operation on the types.
|
|
16
|
+
# @rbs valid_payment_method_filter: String -- Filter response to include profiles that have valid payment methods. Default is to include all profiles. Setting this filter to `true` returns only profiles with either no `validPaymentMethod` field, or the `validPaymentMethod` field set to `true`. Setting this to `false` returns profiles with the `validPaymentMethod` field set to `false` only.
|
|
17
|
+
#: (?api_program: String?, ?access_level: String?, ?profile_type_filter: String?, ?valid_payment_method_filter: String?) -> HTTP::Response
|
|
12
18
|
def list_profiles(api_program: nil, access_level: nil, profile_type_filter: nil, valid_payment_method_filter: nil)
|
|
13
|
-
get
|
|
19
|
+
request(:get, "/v2/profiles", params: { "apiProgram" => api_program, "accessLevel" => access_level, "profileTypeFilter" => profile_type_filter, "validPaymentMethodFilter" => valid_payment_method_filter }.compact)
|
|
14
20
|
end
|
|
15
21
|
|
|
16
22
|
# Update the daily budget for one or more profiles.
|
|
17
|
-
#: (?
|
|
18
|
-
def update_profiles(
|
|
19
|
-
put
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
# Gets a profile specified by identifier.
|
|
23
|
-
#: (Integer) -> untyped
|
|
24
|
-
def get_profile_by_id(profile_id)
|
|
25
|
-
get("/v2/profiles/#{profile_id}")
|
|
23
|
+
#: (?json: untyped) -> HTTP::Response
|
|
24
|
+
def update_profiles(json: {})
|
|
25
|
+
request(:put, "/v2/profiles", json: json)
|
|
26
26
|
end
|
|
27
27
|
end
|
|
28
28
|
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module AmazonAds
|
|
4
|
+
class RecommendationTypes < API
|
|
5
|
+
# Query RecommendationTypes
|
|
6
|
+
#: (?max_results: Integer?, ?next_token: String?) -> HTTP::Response
|
|
7
|
+
def sb_query_recommendation_type(max_results: nil, next_token: nil)
|
|
8
|
+
request(:post, "/adsApi/v1/query/recommendationTypes/sb", json: { "maxResults" => max_results, "nextToken" => next_token }.compact)
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module AmazonAds
|
|
4
|
+
class Recommendations < API
|
|
5
|
+
# Create recommendations
|
|
6
|
+
#: (?recommendations: Array[untyped]?) -> HTTP::Response
|
|
7
|
+
def sb_create_recommendation(recommendations: nil)
|
|
8
|
+
request(:post, "/adsApi/v1/create/recommendations/sb", json: { "recommendations" => recommendations }.compact)
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module AmazonAds
|
|
4
|
+
# Offline Report
|
|
5
|
+
class Reporting < API
|
|
6
|
+
# Creates a report request
|
|
7
|
+
# @rbs end_date: String -- YYYY-MM-DD format. The maximum lookback window supported depends on the selection of reportTypeId. Most report types support `95 days` as lookback window.
|
|
8
|
+
# @rbs name: String -- The name of the report.
|
|
9
|
+
# @rbs start_date: String -- YYYY-MM-DD format. The maximum lookback window supported depends on the selection of reportTypeId. Most report types support `95 days` as lookback window.
|
|
10
|
+
#: (configuration: untyped, end_date: String, start_date: String, ?name: String?) -> HTTP::Response
|
|
11
|
+
def create_async_report(configuration:, end_date:, start_date:, name: nil)
|
|
12
|
+
request(:post, "/reporting/reports", json: { "configuration" => configuration, "endDate" => end_date, "name" => name, "startDate" => start_date }.compact, headers: { "Content-Type" => "application/vnd.createasyncreportrequest.v3+json" })
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Deletes a report by id
|
|
16
|
+
# @rbs report_id: String -- The identifier of the requested report.
|
|
17
|
+
#: (String) -> HTTP::Response
|
|
18
|
+
def delete_async_report(report_id)
|
|
19
|
+
request(:delete, "/reporting/reports/#{report_id}")
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Gets a generation status of report by id
|
|
23
|
+
# @rbs report_id: String -- The identifier of the requested report.
|
|
24
|
+
#: (String) -> HTTP::Response
|
|
25
|
+
def get_async_report(report_id)
|
|
26
|
+
request(:get, "/reporting/reports/#{report_id}")
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module AmazonAds
|
|
4
|
+
class Targets < API
|
|
5
|
+
# Create target
|
|
6
|
+
#: (?targets: Array[untyped]?) -> HTTP::Response
|
|
7
|
+
def create_target(targets: nil)
|
|
8
|
+
request(:post, "/adsApi/v1/create/targets", json: { "targets" => targets }.compact)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# Delete target
|
|
12
|
+
#: (?target_ids: Array[untyped]?) -> HTTP::Response
|
|
13
|
+
def delete_target(target_ids: nil)
|
|
14
|
+
request(:post, "/adsApi/v1/delete/targets", json: { "targetIds" => target_ids }.compact)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# List target
|
|
18
|
+
#: (ad_product_filter: untyped, ?ad_group_id_filter: untyped?, ?campaign_id_filter: untyped?, ?keyword_filter: untyped?, ?marketplace_scope_filter: untyped?, ?match_type_filter: untyped?, ?max_results: Integer?, ?native_language_locale_filter: untyped?, ?negative_filter: untyped?, ?next_token: String?, ?product_id_filter: untyped?, ?state_filter: untyped?, ?target_id_filter: untyped?, ?target_type_filter: untyped?) -> HTTP::Response
|
|
19
|
+
def query_target(ad_product_filter:, ad_group_id_filter: nil, campaign_id_filter: nil, keyword_filter: nil, marketplace_scope_filter: nil, match_type_filter: nil, max_results: nil, native_language_locale_filter: nil, negative_filter: nil, next_token: nil, product_id_filter: nil, state_filter: nil, target_id_filter: nil, target_type_filter: nil)
|
|
20
|
+
request(:post, "/adsApi/v1/query/targets", json: { "adGroupIdFilter" => ad_group_id_filter, "adProductFilter" => ad_product_filter, "campaignIdFilter" => campaign_id_filter, "keywordFilter" => keyword_filter, "marketplaceScopeFilter" => marketplace_scope_filter, "matchTypeFilter" => match_type_filter, "maxResults" => max_results, "nativeLanguageLocaleFilter" => native_language_locale_filter, "negativeFilter" => negative_filter, "nextToken" => next_token, "productIdFilter" => product_id_filter, "stateFilter" => state_filter, "targetIdFilter" => target_id_filter, "targetTypeFilter" => target_type_filter }.compact)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Update target
|
|
24
|
+
#: (?targets: Array[untyped]?) -> HTTP::Response
|
|
25
|
+
def update_target(targets: nil)
|
|
26
|
+
request(:post, "/adsApi/v1/update/targets", json: { "targets" => targets }.compact)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
data/lib/amazon_ads/lwa.rb
CHANGED
|
@@ -1,84 +1,59 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# rbs_inline: enabled
|
|
4
|
-
|
|
5
3
|
require "http"
|
|
6
4
|
|
|
7
5
|
module AmazonAds
|
|
8
|
-
# Requests Login with Amazon (LWA) access tokens for the Amazon Ads API
|
|
9
|
-
#
|
|
10
|
-
#
|
|
11
|
-
# @see https://advertising.amazon.com/API/docs/en-us/info/api-overview
|
|
6
|
+
# Requests Login with Amazon (LWA) access tokens for the Amazon Ads API
|
|
7
|
+
# Stateless: each call to #request hits the token endpoint; the caller
|
|
8
|
+
# owns caching
|
|
12
9
|
class LWA
|
|
13
10
|
URL = "https://api.amazon.com/auth/o2/token" #: String
|
|
14
|
-
TOKEN_EXPIRY_BUFFER = 60 #: Integer
|
|
15
11
|
|
|
16
|
-
|
|
17
|
-
attr_reader :client_secret #: String
|
|
12
|
+
# The OAuth refresh token
|
|
18
13
|
attr_reader :refresh_token #: String
|
|
19
14
|
|
|
20
|
-
#: (
|
|
21
|
-
def
|
|
22
|
-
|
|
23
|
-
client_secret: ENV.fetch("AMAZON_ADS_CLIENT_SECRET"),
|
|
24
|
-
refresh_token: ENV.fetch("AMAZON_ADS_REFRESH_TOKEN")
|
|
25
|
-
)
|
|
26
|
-
@client_id = client_id
|
|
27
|
-
@client_secret = client_secret
|
|
28
|
-
@refresh_token = refresh_token
|
|
29
|
-
@access_token = nil #: String?
|
|
30
|
-
@expires_at = nil #: Time?
|
|
31
|
-
@mutex = Mutex.new
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
# Returns a valid access token, refreshing if necessary.
|
|
35
|
-
#: () -> String
|
|
36
|
-
def access_token
|
|
37
|
-
@mutex.synchronize do
|
|
38
|
-
refresh! if token_expired?
|
|
39
|
-
@access_token or raise AmazonAds::AuthenticationError, "Failed to obtain access token"
|
|
40
|
-
end
|
|
15
|
+
#: (refresh_token: String, ?http: untyped) -> Hash[String, untyped]
|
|
16
|
+
def self.request(...)
|
|
17
|
+
new(...).request
|
|
41
18
|
end
|
|
42
19
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
unless response.status.success?
|
|
49
|
-
body = begin
|
|
50
|
-
response.parse
|
|
51
|
-
rescue StandardError
|
|
52
|
-
{}
|
|
53
|
-
end
|
|
54
|
-
message = body["error_description"] || body["error"] || "Authentication failed"
|
|
55
|
-
raise AmazonAds::AuthenticationError.new(message, response: response)
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
data = response.parse
|
|
59
|
-
@access_token = data.fetch("access_token")
|
|
60
|
-
expires_in = data.fetch("expires_in", 3600)
|
|
61
|
-
@expires_at = Time.now + expires_in - TOKEN_EXPIRY_BUFFER
|
|
62
|
-
|
|
63
|
-
@access_token
|
|
20
|
+
#: (refresh_token: String, ?http: untyped) -> void
|
|
21
|
+
def initialize(refresh_token:, http: HTTP)
|
|
22
|
+
@refresh_token = refresh_token
|
|
23
|
+
@http = http
|
|
64
24
|
end
|
|
65
25
|
|
|
66
|
-
#
|
|
67
|
-
#: () ->
|
|
68
|
-
def
|
|
69
|
-
|
|
26
|
+
# Requests a fresh access token from LWA
|
|
27
|
+
#: () -> Hash[String, untyped]
|
|
28
|
+
def request
|
|
29
|
+
http.post(URL, form: params).parse
|
|
70
30
|
end
|
|
71
31
|
|
|
72
32
|
private
|
|
73
33
|
|
|
74
|
-
#: () ->
|
|
34
|
+
#: () -> HTTP::Client
|
|
35
|
+
def http
|
|
36
|
+
@http.use(:raise_error)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
#: () -> Hash[Symbol, String]
|
|
75
40
|
def params
|
|
76
41
|
{
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
42
|
+
grant_type: "refresh_token",
|
|
43
|
+
client_id:,
|
|
44
|
+
client_secret:,
|
|
45
|
+
refresh_token:,
|
|
81
46
|
}
|
|
82
47
|
end
|
|
48
|
+
|
|
49
|
+
#: () -> String
|
|
50
|
+
def client_id
|
|
51
|
+
AmazonAds.client_id!
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
#: () -> String
|
|
55
|
+
def client_secret
|
|
56
|
+
AmazonAds.client_secret!
|
|
57
|
+
end
|
|
83
58
|
end
|
|
84
59
|
end
|
data/lib/amazon_ads/version.rb
CHANGED
data/lib/amazon_ads.rb
CHANGED
|
@@ -1,37 +1,46 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# rbs_inline: enabled
|
|
4
|
-
|
|
5
3
|
require "zeitwerk"
|
|
6
4
|
|
|
7
5
|
loader = Zeitwerk::Loader.for_gem
|
|
8
6
|
loader.inflector.inflect("api" => "API", "lwa" => "LWA")
|
|
9
7
|
loader.collapse("#{__dir__}/amazon_ads/apis")
|
|
10
8
|
loader.ignore("#{__dir__}/generator")
|
|
11
|
-
loader.ignore("#{__dir__}/amazon_ads/errors.rb")
|
|
12
9
|
loader.setup
|
|
13
10
|
|
|
14
|
-
require_relative "amazon_ads/errors"
|
|
15
|
-
|
|
16
11
|
# Amazon Ads API client for Ruby
|
|
17
12
|
module AmazonAds
|
|
18
13
|
class << self
|
|
19
|
-
#
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
14
|
+
# Sets the client ID
|
|
15
|
+
attr_writer :client_id #: String?
|
|
16
|
+
|
|
17
|
+
# Sets the client secret
|
|
18
|
+
attr_writer :client_secret #: String?
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Returns the client ID
|
|
22
|
+
# Falls back to the `AMAZON_ADS_CLIENT_ID` env var
|
|
23
|
+
#: () -> String?
|
|
24
|
+
def self.client_id
|
|
25
|
+
@client_id || ENV["AMAZON_ADS_CLIENT_ID"]
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Returns the client ID or raises
|
|
29
|
+
#: () -> String
|
|
30
|
+
def self.client_id!
|
|
31
|
+
client_id or raise ArgumentError, "client id is required"
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Returns the client secret
|
|
35
|
+
# Falls back to the `AMAZON_ADS_CLIENT_SECRET` env var
|
|
36
|
+
#: () -> String?
|
|
37
|
+
def self.client_secret
|
|
38
|
+
@client_secret || ENV["AMAZON_ADS_CLIENT_SECRET"]
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Returns the client secret or raises
|
|
42
|
+
#: () -> String
|
|
43
|
+
def self.client_secret!
|
|
44
|
+
client_secret or raise ArgumentError, "client secret is required"
|
|
36
45
|
end
|
|
37
46
|
end
|
metadata
CHANGED
|
@@ -1,28 +1,42 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: amazon-ads
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Hakan Ensari
|
|
8
|
-
bindir:
|
|
8
|
+
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: cgi
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '0'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '0'
|
|
12
26
|
- !ruby/object:Gem::Dependency
|
|
13
27
|
name: http
|
|
14
28
|
requirement: !ruby/object:Gem::Requirement
|
|
15
29
|
requirements:
|
|
16
30
|
- - "~>"
|
|
17
31
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: '
|
|
32
|
+
version: '6.0'
|
|
19
33
|
type: :runtime
|
|
20
34
|
prerelease: false
|
|
21
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
36
|
requirements:
|
|
23
37
|
- - "~>"
|
|
24
38
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: '
|
|
39
|
+
version: '6.0'
|
|
26
40
|
- !ruby/object:Gem::Dependency
|
|
27
41
|
name: zeitwerk
|
|
28
42
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -47,21 +61,30 @@ files:
|
|
|
47
61
|
- README.md
|
|
48
62
|
- lib/amazon_ads.rb
|
|
49
63
|
- lib/amazon_ads/api.rb
|
|
64
|
+
- lib/amazon_ads/apis/ad_associations.rb
|
|
65
|
+
- lib/amazon_ads/apis/ad_extensions.rb
|
|
66
|
+
- lib/amazon_ads/apis/ad_groups.rb
|
|
67
|
+
- lib/amazon_ads/apis/ads.rb
|
|
68
|
+
- lib/amazon_ads/apis/advertising_deal_targets.rb
|
|
69
|
+
- lib/amazon_ads/apis/advertising_deals.rb
|
|
70
|
+
- lib/amazon_ads/apis/brand_store_edition_publish_versions.rb
|
|
71
|
+
- lib/amazon_ads/apis/brand_store_editions.rb
|
|
72
|
+
- lib/amazon_ads/apis/brand_store_pages.rb
|
|
73
|
+
- lib/amazon_ads/apis/brand_stores.rb
|
|
74
|
+
- lib/amazon_ads/apis/branded_keywords_pricings.rb
|
|
75
|
+
- lib/amazon_ads/apis/campaign_forecasts.rb
|
|
76
|
+
- lib/amazon_ads/apis/campaigns.rb
|
|
77
|
+
- lib/amazon_ads/apis/commitment_spends.rb
|
|
78
|
+
- lib/amazon_ads/apis/commitments.rb
|
|
79
|
+
- lib/amazon_ads/apis/keyword_reservation_validations.rb
|
|
80
|
+
- lib/amazon_ads/apis/marketing_stream.rb
|
|
50
81
|
- lib/amazon_ads/apis/profiles.rb
|
|
51
|
-
- lib/amazon_ads/apis/
|
|
52
|
-
- lib/amazon_ads/
|
|
53
|
-
- lib/amazon_ads/
|
|
54
|
-
- lib/amazon_ads/
|
|
82
|
+
- lib/amazon_ads/apis/recommendation_types.rb
|
|
83
|
+
- lib/amazon_ads/apis/recommendations.rb
|
|
84
|
+
- lib/amazon_ads/apis/reporting.rb
|
|
85
|
+
- lib/amazon_ads/apis/targets.rb
|
|
55
86
|
- lib/amazon_ads/lwa.rb
|
|
56
87
|
- lib/amazon_ads/version.rb
|
|
57
|
-
- sig/generated/amazon_ads.rbs
|
|
58
|
-
- sig/generated/amazon_ads/api.rbs
|
|
59
|
-
- sig/generated/amazon_ads/apis/profiles.rbs
|
|
60
|
-
- sig/generated/amazon_ads/apis/sponsored_products.rbs
|
|
61
|
-
- sig/generated/amazon_ads/client.rbs
|
|
62
|
-
- sig/generated/amazon_ads/configuration.rbs
|
|
63
|
-
- sig/generated/amazon_ads/errors.rbs
|
|
64
|
-
- sig/generated/amazon_ads/lwa.rbs
|
|
65
88
|
homepage: https://github.com/lineofflight/amazon-ads-ruby
|
|
66
89
|
licenses:
|
|
67
90
|
- MIT
|
|
@@ -77,14 +100,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
77
100
|
requirements:
|
|
78
101
|
- - ">="
|
|
79
102
|
- !ruby/object:Gem::Version
|
|
80
|
-
version: 3.
|
|
103
|
+
version: '3.3'
|
|
81
104
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
105
|
requirements:
|
|
83
106
|
- - ">="
|
|
84
107
|
- !ruby/object:Gem::Version
|
|
85
108
|
version: '0'
|
|
86
109
|
requirements: []
|
|
87
|
-
rubygems_version: 4.0.
|
|
110
|
+
rubygems_version: 4.0.16
|
|
88
111
|
specification_version: 4
|
|
89
112
|
summary: Amazon Ads API client for Ruby
|
|
90
113
|
test_files: []
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# rbs_inline: enabled
|
|
4
|
-
|
|
5
|
-
module AmazonAds
|
|
6
|
-
# Amazon Ads API - Sponsored Products
|
|
7
|
-
#
|
|
8
|
-
# @see https://advertising.amazon.com/API/docs/en-us/sponsored-products
|
|
9
|
-
class SponsoredProducts < API
|
|
10
|
-
# Gets a bid recommendation for an ad group. [PLANNED DEPRECATION 3/27/2024]
|
|
11
|
-
#: (Numeric) -> untyped
|
|
12
|
-
def get_ad_group_bid_recommendations(ad_group_id)
|
|
13
|
-
get("/v2/sp/adGroups/#{ad_group_id}/bidRecommendations")
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
# Gets a bid recommendation for a keyword. [PLANNED DEPRECATION 3/27/2024]
|
|
17
|
-
#: (Numeric) -> untyped
|
|
18
|
-
def get_keyword_bid_recommendations(keyword_id)
|
|
19
|
-
get("/v2/sp/keywords/#{keyword_id}/bidRecommendations")
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
# Gets bid recommendations for keywords. [PLANNED DEPRECATION 3/27/2024]
|
|
23
|
-
#: (?body: Hash[String, untyped]) -> untyped
|
|
24
|
-
def create_keyword_bid_recommendations(body: {})
|
|
25
|
-
post("/v2/sp/keywords/bidRecommendations", body: body)
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
# Gets suggested keywords for the specified ad group.
|
|
29
|
-
#: (Numeric, ?max_num_suggestions: Integer?, ?ad_state_filter: String?) -> untyped
|
|
30
|
-
def get_ad_group_suggested_keywords(ad_group_id, max_num_suggestions: nil, ad_state_filter: nil)
|
|
31
|
-
get("/v2/sp/adGroups/#{ad_group_id}/suggested/keywords", params: { "maxNumSuggestions" => max_num_suggestions, "adStateFilter" => ad_state_filter }.compact)
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
# Gets suggested keywords with extended data for the specified ad group.
|
|
35
|
-
#: (Numeric, ?max_num_suggestions: Integer?, ?suggest_bids: String?, ?ad_state_filter: String?) -> untyped
|
|
36
|
-
def get_ad_group_suggested_keywords_ex(ad_group_id, max_num_suggestions: nil, suggest_bids: nil, ad_state_filter: nil)
|
|
37
|
-
get("/v2/sp/adGroups/#{ad_group_id}/suggested/keywords/extended", params: { "maxNumSuggestions" => max_num_suggestions, "suggestBids" => suggest_bids, "adStateFilter" => ad_state_filter }.compact)
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
# Gets suggested keywords for the specified ASIN.
|
|
41
|
-
#: (String, ?max_num_suggestions: Integer?) -> untyped
|
|
42
|
-
def get_asin_suggested_keywords(asin_value, max_num_suggestions: nil)
|
|
43
|
-
get("/v2/sp/asins/#{asin_value}/suggested/keywords", params: { "maxNumSuggestions" => max_num_suggestions }.compact)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
# Gets suggested keyword for a specified list of ASINs.
|
|
47
|
-
#: (?body: Hash[String, untyped]) -> untyped
|
|
48
|
-
def bulk_get_asin_suggested_keywords(body: {})
|
|
49
|
-
post("/v2/sp/asins/suggested/keywords", body: body)
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
# Gets a list of bid recommendations for keyword, product, or auto targeting expressions.
|
|
53
|
-
#: (?body: Hash[String, untyped]) -> untyped
|
|
54
|
-
def get_bid_recommendations(body: {})
|
|
55
|
-
post("/v2/sp/targets/bidRecommendations", body: body)
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
# Request a snapshot
|
|
59
|
-
#: (String, ?body: Hash[String, untyped]) -> untyped
|
|
60
|
-
def request_snapshot(record_type, body: {})
|
|
61
|
-
post("/v2/sp/#{record_type}/snapshot", body: body)
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
# Get the status of a requested snapshot
|
|
65
|
-
#: (Numeric) -> untyped
|
|
66
|
-
def get_snapshot_status(snapshot_id)
|
|
67
|
-
get("/v2/sp/snapshots/#{snapshot_id}")
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
# Download requested snapshot
|
|
71
|
-
#: (Numeric) -> untyped
|
|
72
|
-
def download_snapshot(snapshot_id)
|
|
73
|
-
get("/v2/sp/snapshots/#{snapshot_id}/download")
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
end
|
data/lib/amazon_ads/client.rb
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# rbs_inline: enabled
|
|
4
|
-
|
|
5
|
-
module AmazonAds
|
|
6
|
-
# High-level client for Amazon Ads API.
|
|
7
|
-
# Provides convenient access to all API endpoints with automatic authentication.
|
|
8
|
-
class Client
|
|
9
|
-
attr_reader :lwa #: LWA
|
|
10
|
-
attr_reader :region #: Symbol
|
|
11
|
-
attr_reader :profile_id #: String?
|
|
12
|
-
|
|
13
|
-
#: (?region: Symbol, ?profile_id: String?, ?lwa: LWA?) -> void
|
|
14
|
-
def initialize(region: AmazonAds.configuration.region, profile_id: AmazonAds.configuration.profile_id, lwa: nil)
|
|
15
|
-
@lwa = lwa || AmazonAds.configuration.lwa
|
|
16
|
-
@region = region
|
|
17
|
-
@profile_id = profile_id
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
# Access Profiles API
|
|
21
|
-
#: () -> Profiles
|
|
22
|
-
def profiles
|
|
23
|
-
@profiles ||= Profiles.new(region: region, lwa: lwa, profile_id: profile_id)
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
# Access Sponsored Products API
|
|
27
|
-
#: () -> SponsoredProducts
|
|
28
|
-
def sponsored_products
|
|
29
|
-
@sponsored_products ||= SponsoredProducts.new(region: region, lwa: lwa, profile_id: profile_id)
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
# Creates a new client with a different profile ID
|
|
33
|
-
#: (String) -> Client
|
|
34
|
-
def with_profile(profile_id)
|
|
35
|
-
Client.new(region: region, profile_id: profile_id, lwa: lwa)
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# rbs_inline: enabled
|
|
4
|
-
|
|
5
|
-
module AmazonAds
|
|
6
|
-
# Configuration for the AmazonAds library.
|
|
7
|
-
# Centralizes settings for authentication and API access.
|
|
8
|
-
class Configuration
|
|
9
|
-
attr_accessor :client_id #: String?
|
|
10
|
-
attr_accessor :client_secret #: String?
|
|
11
|
-
attr_accessor :refresh_token #: String?
|
|
12
|
-
attr_accessor :region #: Symbol
|
|
13
|
-
attr_accessor :profile_id #: String?
|
|
14
|
-
|
|
15
|
-
#: () -> void
|
|
16
|
-
def initialize
|
|
17
|
-
@client_id = ENV["AMAZON_ADS_CLIENT_ID"]
|
|
18
|
-
@client_secret = ENV["AMAZON_ADS_CLIENT_SECRET"]
|
|
19
|
-
@refresh_token = ENV["AMAZON_ADS_REFRESH_TOKEN"]
|
|
20
|
-
@region = :na
|
|
21
|
-
@profile_id = nil
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
# Builds an LWA instance from the configuration.
|
|
25
|
-
#: () -> LWA
|
|
26
|
-
def lwa
|
|
27
|
-
LWA.new(
|
|
28
|
-
client_id: client_id || raise(ArgumentError, "client_id is required"),
|
|
29
|
-
client_secret: client_secret || raise(ArgumentError, "client_secret is required"),
|
|
30
|
-
refresh_token: refresh_token || raise(ArgumentError, "refresh_token is required"),
|
|
31
|
-
)
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|