bing_ads_ruby_sdk 1.5.2 → 1.7
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/Gemfile +1 -1
- data/README.md +84 -14
- data/bing_ads_ruby_sdk.gemspec +1 -1
- data/changelog.md +10 -0
- data/lib/bing_ads_ruby_sdk/errors/errors.rb +20 -16
- data/lib/bing_ads_ruby_sdk/oauth2/fs_store.rb +1 -1
- data/lib/bing_ads_ruby_sdk/services/campaign_management.rb +2 -3
- data/lib/bing_ads_ruby_sdk/string_utils.rb +2 -0
- data/lib/bing_ads_ruby_sdk/tasks/bing_ads_ruby_sdk.rake +5 -1
- data/lib/bing_ads_ruby_sdk/version.rb +1 -1
- data/lib/bing_ads_ruby_sdk.rb +5 -5
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ba09362c0df0c63b729b31a627ddd6708a1b187c37f392002471c4c05d6e448
|
4
|
+
data.tar.gz: 34db7cac452be374d8e4d305752b0fb5e0db09834710d17a718809c37733b3a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 62ee362cbad60084db481253ea12e7baf3203773dffb59c2a47c6831cd6add07c15e489f1e4b1aa87ed2a488eb19d718dcf232237ee11062f5da91f727217368
|
7
|
+
data.tar.gz: 7c89d9dc0508449d20e14263534658115d1736f3a2cd7e82ac54dc0274a954228929296795f0c6098e1c95f3a868ff47beb12eb34090cf3ef4adeb7ec8c98e2b
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -16,7 +16,8 @@ Or install it yourself as:
|
|
16
16
|
|
17
17
|
$ gem install bing_ads_ruby_sdk
|
18
18
|
|
19
|
-
##
|
19
|
+
## Usage
|
20
|
+
### Getting Started
|
20
21
|
|
21
22
|
In order to use Microsoft's advertising API you need to
|
22
23
|
[get your API credentials from MS](https://learn.microsoft.com/en-us/advertising/guides/get-started?view=bingads-13).
|
@@ -33,7 +34,6 @@ bin/rake bing_token:get['credentials.json',YOUR_DEVELOPER_TOKEN,YOUR_CLIENT_ID,Y
|
|
33
34
|
bin/rake bing_token:get['credentials.json',ABC1234,3431b6d0-a2ac-48e1-a1c5-1d0b82f3187f,SECRETVALUEHERE]
|
34
35
|
```
|
35
36
|
|
36
|
-
|
37
37
|
Then to use the api:
|
38
38
|
```ruby
|
39
39
|
store = ::BingAdsRubySdk::OAuth2::FsStore.new('my_token.json')
|
@@ -44,6 +44,22 @@ api = BingAdsRubySdk::Api.new(
|
|
44
44
|
)
|
45
45
|
```
|
46
46
|
|
47
|
+
### Configuration
|
48
|
+
```ruby
|
49
|
+
BingAdsRubySdk.configure do |conf|
|
50
|
+
conf.log = true
|
51
|
+
conf.logger.level = Logger::DEBUG
|
52
|
+
conf.pretty_print_xml = true
|
53
|
+
# to filter sensitive data before logging
|
54
|
+
conf.filters = ["AuthenticationToken", "DeveloperToken"]
|
55
|
+
|
56
|
+
# Optionally allow ActiveSupport::Notifications to be emitted by Excon.
|
57
|
+
# These notifications can then be sent on to your profiling system
|
58
|
+
# conf.instrumentor = ActiveSupport::Notifications
|
59
|
+
end
|
60
|
+
```
|
61
|
+
|
62
|
+
### Account creation and management
|
47
63
|
If you want to create an account using the API:
|
48
64
|
```ruby
|
49
65
|
api.customer_management.signup_customer(
|
@@ -54,7 +70,7 @@ api.customer_management.signup_customer(
|
|
54
70
|
```
|
55
71
|
|
56
72
|
Otherwise you can [use existing account IDs as explained here](https://learn.microsoft.com/en-us/advertising/guides/get-started?view=bingads-13#get-ids),
|
57
|
-
or use the `customer_management` endpoint as explained
|
73
|
+
or use the `customer_management` endpoint as explained above.
|
58
74
|
|
59
75
|
Once you have your MS Advertising customer and account ids:
|
60
76
|
```ruby
|
@@ -80,22 +96,76 @@ The methods implemented contain additional code to ease data manipulation but an
|
|
80
96
|
|
81
97
|
```
|
82
98
|
|
99
|
+
### Reporting
|
100
|
+
You can generate the report following the
|
101
|
+
[process recommended by Microsoft](https://learn.microsoft.com/en-us/advertising/guides/request-download-report?view=bingads-13):
|
102
|
+
|
103
|
+
That would mean coding something like this:
|
83
104
|
|
84
|
-
## Configure the gem
|
85
105
|
```ruby
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
106
|
+
submission_response = api.reporting
|
107
|
+
.call(:submit_generate_report,
|
108
|
+
account_performance_report_request: {
|
109
|
+
exclude_report_header: true,
|
110
|
+
exclude_report_footer: true,
|
111
|
+
exclude_column_headers: true,
|
112
|
+
format: "Csv",
|
113
|
+
aggregation: "Daily",
|
114
|
+
filter: nil,
|
115
|
+
columns: [
|
116
|
+
{
|
117
|
+
account_performance_report_column: "TimePeriod"
|
118
|
+
},
|
119
|
+
{
|
120
|
+
account_performance_report_column: "AccountId"
|
121
|
+
},
|
122
|
+
{
|
123
|
+
account_performance_report_column: "DeviceType"
|
124
|
+
},
|
125
|
+
{
|
126
|
+
account_performance_report_column: "Clicks"
|
127
|
+
}
|
128
|
+
],
|
129
|
+
scope: {
|
130
|
+
# Your account ID here
|
131
|
+
account_ids: [{long: 1000000}]
|
132
|
+
},
|
133
|
+
time: {
|
134
|
+
custom_date_range_start: {
|
135
|
+
day: 7,
|
136
|
+
month: 5,
|
137
|
+
year: 2023
|
138
|
+
},
|
139
|
+
custom_date_range_end: {
|
140
|
+
day: 8,
|
141
|
+
month: 5,
|
142
|
+
year: 2023
|
143
|
+
}
|
144
|
+
}
|
145
|
+
}
|
146
|
+
)
|
147
|
+
|
148
|
+
report_request_id = submission_response.fetch(:report_request_id)
|
149
|
+
|
150
|
+
# Then you can poll the API to check the status of the report generation
|
151
|
+
poll_response = api.reporting.call(:poll_generate_report, report_request_id: report_request_id)
|
152
|
+
|
153
|
+
# When it is ready you can download it
|
154
|
+
report_request_status = poll_response.fetch(:report_request_status)
|
155
|
+
|
156
|
+
report_generation_status = report_request_status[:status].downcase.to_sym
|
157
|
+
# => One of these: :pending, :error, :success
|
158
|
+
|
159
|
+
if report_generation_status == :success
|
160
|
+
url = report_request_status[:report_download_url]
|
161
|
+
# => The URL to download the report (with the library of your choice)
|
96
162
|
end
|
97
163
|
```
|
98
164
|
|
165
|
+
🛈 Report request example [here in the API docs](https://learn.microsoft.com/en-us/advertising/reporting-service/accountperformancereportrequest?view=bingads-13)
|
166
|
+
|
167
|
+
🛈 Hint: convert parameter names from PascalCase to snake_case when consulting the API docs
|
168
|
+
|
99
169
|
## Development
|
100
170
|
You can run `bin/console` for an interactive prompt that will allow you to experiment.
|
101
171
|
|
data/bing_ads_ruby_sdk.gemspec
CHANGED
@@ -4,7 +4,7 @@ require "bing_ads_ruby_sdk/version"
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "bing_ads_ruby_sdk"
|
7
|
-
spec.required_ruby_version = ">=
|
7
|
+
spec.required_ruby_version = ">= 3"
|
8
8
|
|
9
9
|
spec.version = BingAdsRubySdk::VERSION
|
10
10
|
spec.authors = %w[Effilab developers]
|
data/changelog.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
## V1.7 Release
|
2
|
+
- Fixed a bug preventing all but the first ad extension associations to be fetched
|
3
|
+
- All error messages are now returned instead of just the first one
|
4
|
+
- Updated dependencies
|
5
|
+
|
6
|
+
## V1.6 Release
|
7
|
+
- Updated documentation
|
8
|
+
- Fixed an envkey/dotenv related bug preventing the gem from starting
|
9
|
+
- Dropped support for Ruby 2
|
10
|
+
|
1
11
|
## V1.5.1 Release
|
2
12
|
- Bug fix: Rake task missing
|
3
13
|
|
@@ -29,7 +29,7 @@ module BingAdsRubySdk
|
|
29
29
|
|
30
30
|
class ServerError < GeneralError
|
31
31
|
def initialize(server_error)
|
32
|
-
super
|
32
|
+
super("Server raised error #{server_error}")
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -45,19 +45,14 @@ module BingAdsRubySdk
|
|
45
45
|
error_list = all_errors
|
46
46
|
return @message if error_list.empty?
|
47
47
|
|
48
|
-
|
49
|
-
if error_list.count > 1
|
50
|
-
"API raised #{error_list.count} errors, including: #{first_message}"
|
51
|
-
else
|
52
|
-
first_message
|
53
|
-
end
|
48
|
+
concatenated_error_messages(error_list)
|
54
49
|
end
|
55
50
|
|
56
51
|
private
|
57
52
|
|
58
53
|
def populate_error_lists
|
59
54
|
self.class.error_lists.each do |key|
|
60
|
-
instance_variable_set("@#{key}", array_wrap(fault_hash[key]))
|
55
|
+
instance_variable_set(:"@#{key}", array_wrap(fault_hash[key]))
|
61
56
|
end
|
62
57
|
end
|
63
58
|
|
@@ -85,9 +80,18 @@ module BingAdsRubySdk
|
|
85
80
|
BingAdsRubySdk::StringUtils.snakize(class_name).to_sym
|
86
81
|
end
|
87
82
|
|
88
|
-
def
|
89
|
-
|
90
|
-
|
83
|
+
def concatenated_error_messages(error_list)
|
84
|
+
errors = error_list.map do |error|
|
85
|
+
if error.is_a?(Hash) && error[:error_code]
|
86
|
+
error
|
87
|
+
else
|
88
|
+
error.values
|
89
|
+
end
|
90
|
+
end.flatten.compact
|
91
|
+
|
92
|
+
errors.map do |error|
|
93
|
+
format_message(error[:error_code], error[:message])
|
94
|
+
end.uniq.join(", ")
|
91
95
|
end
|
92
96
|
|
93
97
|
def array_wrap(value)
|
@@ -123,13 +127,13 @@ module BingAdsRubySdk
|
|
123
127
|
raw_response[fault_key] || {}
|
124
128
|
end
|
125
129
|
|
126
|
-
#
|
127
|
-
# overridden because partial errors are structured differently
|
130
|
+
# This is overridden because partial errors are structured differently
|
128
131
|
# to application faults
|
129
132
|
# @return [Hash] containing the details of the error
|
130
|
-
def
|
131
|
-
|
132
|
-
|
133
|
+
def concatenated_error_messages(error_list)
|
134
|
+
error_list.map do |error|
|
135
|
+
format_message(error[:error_code], error[:message])
|
136
|
+
end.uniq.join(", ")
|
133
137
|
end
|
134
138
|
end
|
135
139
|
|
@@ -37,9 +37,8 @@ module BingAdsRubySdk
|
|
37
37
|
wrap_array(
|
38
38
|
call(__method__, message)
|
39
39
|
.dig(:ad_extension_association_collection, :ad_extension_association_collection)
|
40
|
-
.
|
41
|
-
|
42
|
-
)
|
40
|
+
.map { |entity_group| entity_group.dig(:ad_extension_associations, :ad_extension_association) }
|
41
|
+
).flatten
|
43
42
|
rescue
|
44
43
|
[]
|
45
44
|
end
|
@@ -7,6 +7,8 @@ module BingAdsRubySdk
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def self.snakize(string)
|
10
|
+
raise "Unexpected string length : #{string.length} for string '#{string[0..200]}...'" if string.length > 1000
|
11
|
+
|
10
12
|
string.gsub(MULTIPLE_CAPSREGEX, MATCHING_PATTERN)
|
11
13
|
.gsub(SPLIT_REGEX, MATCHING_PATTERN)
|
12
14
|
.tr("-", "_")
|
data/lib/bing_ads_ruby_sdk.rb
CHANGED
@@ -10,6 +10,9 @@ require "bing_ads_ruby_sdk/string_utils"
|
|
10
10
|
require "bing_ads_ruby_sdk/railtie" if defined?(Rails)
|
11
11
|
|
12
12
|
module BingAdsRubySdk
|
13
|
+
TYPE_KEY = "@type"
|
14
|
+
ROOT_PATH = File.join(__dir__, "..")
|
15
|
+
|
13
16
|
def self.config
|
14
17
|
@configuration ||= BingAdsRubySdk::Configuration.new
|
15
18
|
end
|
@@ -18,9 +21,9 @@ module BingAdsRubySdk
|
|
18
21
|
yield(config)
|
19
22
|
end
|
20
23
|
|
21
|
-
def self.log(level,
|
24
|
+
def self.log(level, ...)
|
22
25
|
return unless config.log
|
23
|
-
config.logger.send(level,
|
26
|
+
config.logger.send(level, ...)
|
24
27
|
end
|
25
28
|
|
26
29
|
def self.root_path
|
@@ -30,7 +33,4 @@ module BingAdsRubySdk
|
|
30
33
|
def self.type_key
|
31
34
|
TYPE_KEY
|
32
35
|
end
|
33
|
-
|
34
|
-
TYPE_KEY = "@type"
|
35
|
-
ROOT_PATH = File.join(__dir__, "..")
|
36
36
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bing_ads_ruby_sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: '1.7'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Effilab
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2024-11-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: signet
|
@@ -256,14 +256,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
256
256
|
requirements:
|
257
257
|
- - ">="
|
258
258
|
- !ruby/object:Gem::Version
|
259
|
-
version: '
|
259
|
+
version: '3'
|
260
260
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
261
261
|
requirements:
|
262
262
|
- - ">="
|
263
263
|
- !ruby/object:Gem::Version
|
264
264
|
version: '0'
|
265
265
|
requirements: []
|
266
|
-
rubygems_version: 3.
|
266
|
+
rubygems_version: 3.5.22
|
267
267
|
signing_key:
|
268
268
|
specification_version: 4
|
269
269
|
summary: Bing Ads Ruby SDK
|