bing-ads-reporting 1.1.2 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bing-ads-reporting/service.rb +42 -20
- data/lib/bing-ads-reporting/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc0057cb44b94bed322895917c644f381754a07c
|
4
|
+
data.tar.gz: 16e037d6ff98041c96dc50b260a2cb36aa598a44
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12fa989c13af0dd517d4eb7ab81582b3abf6ec0f2d43cfefe3f672c45157407a73681828ae24ca03118b49d212820ed407f6e1dc4bd9f7dc00a299060bdd86da
|
7
|
+
data.tar.gz: 93d79fd944913be27f9e9f5c089cb62af994cbbaacf6bfde041d8c14e31276782a48c87f45d13703d3ccb7064c4c19ecfc6d310097dcbf6d0dad52e9b665099e
|
@@ -2,6 +2,7 @@ module BingAdsReporting
|
|
2
2
|
class AuthenticationTokenExpired < Exception; end
|
3
3
|
|
4
4
|
class Service
|
5
|
+
SUCCESS = 'Success'
|
5
6
|
|
6
7
|
def initialize(settings, logger = nil)
|
7
8
|
@settings = settings
|
@@ -19,7 +20,8 @@ module BingAdsReporting
|
|
19
20
|
ns("Format") => options[:format],
|
20
21
|
ns("Language") => "English",
|
21
22
|
ns("ReportName") => options[:report_name],
|
22
|
-
ns("ReturnOnlyCompleteData") => false,
|
23
|
+
ns("ReturnOnlyCompleteData") => 'false',
|
24
|
+
|
23
25
|
ns("Aggregation") => options[:aggregation],
|
24
26
|
ns("Columns") => {
|
25
27
|
ns("#{report_type}ReportColumn") => options[:columns]
|
@@ -44,8 +46,10 @@ module BingAdsReporting
|
|
44
46
|
# ns("PredefinedTime") => options[:time]
|
45
47
|
}
|
46
48
|
},
|
47
|
-
:attributes! => {ns("ReportRequest") => {
|
48
|
-
"i:type" => ns("#{report_type}ReportRequest")
|
49
|
+
:attributes! => {ns("ReportRequest") => {
|
50
|
+
"i:type" => ns("#{report_type}ReportRequest"),
|
51
|
+
"i:nil" => 'false'
|
52
|
+
}
|
49
53
|
}
|
50
54
|
})
|
51
55
|
|
@@ -73,18 +77,24 @@ module BingAdsReporting
|
|
73
77
|
polled = poll_report(id)
|
74
78
|
status = polled.body[:poll_generate_report_response][:report_request_status][:status] rescue nil
|
75
79
|
raise "Report status: Error for ID: #{id}. TrackingId: #{polled.header[:tracking_id]}" if status == "Error"
|
76
|
-
status ==
|
77
|
-
end
|
78
|
-
|
79
|
-
def report_url(id)
|
80
|
-
download_url = poll_report(id).body[:poll_generate_report_response][:report_request_status][:report_download_url] rescue nil
|
80
|
+
status == SUCCESS
|
81
81
|
end
|
82
82
|
|
83
|
+
# returns nil if there is no data
|
83
84
|
def report_body(id)
|
84
85
|
download(report_url(id))
|
85
86
|
end
|
86
87
|
|
87
88
|
private
|
89
|
+
|
90
|
+
def report_url(id)
|
91
|
+
polled = poll_report(id)
|
92
|
+
status = polled.body[:poll_generate_report_response][:report_request_status][:status] rescue nil
|
93
|
+
download_url = polled.body[:poll_generate_report_response][:report_request_status][:report_download_url] rescue nil
|
94
|
+
return nil if download_url.nil? && status == SUCCESS
|
95
|
+
raise "Report URL is not available for report id #{id}" unless download_url
|
96
|
+
download_url
|
97
|
+
end
|
88
98
|
|
89
99
|
def default_options(report_settings)
|
90
100
|
{ format: report_settings[:report_format],
|
@@ -95,18 +105,28 @@ module BingAdsReporting
|
|
95
105
|
end
|
96
106
|
|
97
107
|
def poll_report(id)
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
108
|
+
begin
|
109
|
+
client.call(:poll_generate_report, message: {
|
110
|
+
ns("ReportRequestId") => id,
|
111
|
+
})
|
112
|
+
rescue Savon::SOAPFault => e
|
113
|
+
err = e.to_hash[:fault][:detail][:ad_api_fault_detail][:errors][:ad_api_error][:error_code] rescue nil
|
114
|
+
msg = e.to_hash[:fault][:detail][:ad_api_fault_detail][:errors][:ad_api_error][:message] if err
|
115
|
+
if err.nil?
|
116
|
+
err = e.to_hash[:fault][:detail][:api_fault_detail][:operation_errors][:operation_error][:error_code] rescue nil
|
117
|
+
msg = e.to_hash[:fault][:detail][:api_fault_detail][:operation_errors][:operation_error][:message] if err
|
118
|
+
end
|
119
|
+
if err == 'AuthenticationTokenExpired'
|
120
|
+
@logger.error err
|
121
|
+
raise AuthenticationTokenExpired.new(msg)
|
122
|
+
end
|
123
|
+
end
|
102
124
|
end
|
103
125
|
|
104
126
|
def download(url)
|
127
|
+
return unless url
|
105
128
|
@logger.debug "Downloading Bing report from: #{url}"
|
106
|
-
curl = Curl::Easy.new(url)
|
107
|
-
c.use_ssl = 3
|
108
|
-
c.ssl_version = 3
|
109
|
-
end
|
129
|
+
curl = Curl::Easy.new(url)
|
110
130
|
curl.perform
|
111
131
|
curl.body_str
|
112
132
|
end
|
@@ -126,17 +146,19 @@ module BingAdsReporting
|
|
126
146
|
ns('DeveloperToken') => @settings[:developerToken],
|
127
147
|
ns('AuthenticationToken') => @settings[:authenticationToken] }
|
128
148
|
end
|
129
|
-
Savon.client({
|
149
|
+
Savon.client({
|
150
|
+
wsdl: "https://reporting.api.bingads.microsoft.com/Api/Advertiser/Reporting/V11/ReportingService.svc?singleWsdl",
|
130
151
|
log_level: :info,
|
131
|
-
namespaces: {"xmlns:arr" => 'http://schemas.microsoft.com/2003/10/Serialization/Arrays'
|
152
|
+
namespaces: { "xmlns:arr" => 'http://schemas.microsoft.com/2003/10/Serialization/Arrays',
|
153
|
+
"xmlns:i" => "http://www.w3.org/2001/XMLSchema-instance" },
|
132
154
|
soap_header: header
|
133
155
|
})
|
134
|
-
# .merge({pretty_print_xml: true, log_level: :debug})) # for more logging
|
156
|
+
# .merge({pretty_print_xml: true, log_level: :debug, log: true, logger: @logger})) # for more logging
|
135
157
|
end
|
136
158
|
|
137
159
|
def ns(str)
|
138
160
|
"tns:#{str}"
|
139
161
|
end
|
140
|
-
|
162
|
+
|
141
163
|
end
|
142
164
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bing-ads-reporting
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Borkowski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: datebox
|
@@ -82,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
82
|
version: '0'
|
83
83
|
requirements: []
|
84
84
|
rubyforge_project:
|
85
|
-
rubygems_version: 2.
|
85
|
+
rubygems_version: 2.6.12
|
86
86
|
signing_key:
|
87
87
|
specification_version: 4
|
88
88
|
summary: Allows easily pull reports from Bing Ads
|