bing-ads-reporting 0.1.1 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e5ea9a2f68ab024058db195ff33acb2e3c8eaa0e
4
- data.tar.gz: 6ea308cc9e3c116bec9454035e78859dd6ae42bc
3
+ metadata.gz: 76f0917662f7d55f85fc067d94744e7f33891d71
4
+ data.tar.gz: a5583a6ec263e9adf5a4c8b0179b8787dcf3645e
5
5
  SHA512:
6
- metadata.gz: 4a6c30cb0d9568d4790a695060267f140c8c558f69fc207e854aa6db141e88e4f5356a8bd943efc86165e3b4ea968843152fd3eb0e0500433a864419f690b6ec
7
- data.tar.gz: e5597a7043e225f0c420fa5e3e2f14f0eae0b8f66b8149584b36769959504b7031017ddab9115b6316d7567a62d430d6c4b09849b4136286550b76880af0b6b5
6
+ metadata.gz: 609e71a291f1e6018cbfdcf0937a27cb96e538e790384583d85e03162ccb216aba450544b87256cdd2a8fa0c0ed95b0451507f2096d043de345a8ff920956c5c
7
+ data.tar.gz: 4a52d0d72a46af3fbecba1e0be47f0028c137034f1ef6f0dd38c6295de2e25eb5c0cb8ad78988c2999412c391e5b95ae99f81d20955a8b360ac6fc6eba4e2229
@@ -1,5 +1,6 @@
1
1
  require_relative 'bing-ads-reporting/service'
2
2
  require_relative 'bing-ads-reporting/version'
3
+ require 'logger'
3
4
 
4
5
  module BingAdsReporting
5
6
  end
@@ -1,8 +1,11 @@
1
1
  module BingAdsReporting
2
+ class AuthenticationTokenExpired < Exception; end
3
+
2
4
  class Service
3
5
 
4
- def initialize(settings)
6
+ def initialize(settings, logger = nil)
5
7
  @settings = settings
8
+ @logger = logger || Logger.new($stdout)
6
9
  end
7
10
 
8
11
  def generate_report(report_settings, report_params)
@@ -10,40 +13,52 @@ module BingAdsReporting
10
13
  period = options[:period]
11
14
  report_type = options[:report_type]
12
15
 
13
- response = client.call(:submit_generate_report, message: {
14
- ns('ReportRequest') => {
15
- ns("Format") => options[:format],
16
- ns("Language") => "English",
17
- ns("ReportName") => options[:report_name],
18
- ns("ReturnOnlyCompleteData") => false,
19
- ns("Aggregation") => options[:aggregation],
20
- ns("Columns") => {
21
- ns("#{report_type}ReportColumn") => options[:columns]
22
- },
23
- ns("Scope") => {
24
- ns("AccountIds") => {
25
- 'arr:long' => @settings[:accountId]
26
- }
27
- },
28
- ns("Time") => {
29
- # apparently order is important, and end date has to be before start date, wtf
30
- ns("CustomDateRangeEnd") => {
31
- ns("Day") => period.to.day,
32
- ns("Month") => period.to.month,
33
- ns("Year") => period.to.year
16
+ begin
17
+ response = client.call(:submit_generate_report, message: {
18
+ ns('ReportRequest') => {
19
+ ns("Format") => options[:format],
20
+ ns("Language") => "English",
21
+ ns("ReportName") => options[:report_name],
22
+ ns("ReturnOnlyCompleteData") => false,
23
+ ns("Aggregation") => options[:aggregation],
24
+ ns("Columns") => {
25
+ ns("#{report_type}ReportColumn") => options[:columns]
26
+ },
27
+ ns("Scope") => {
28
+ ns("AccountIds") => {
29
+ 'arr:long' => @settings[:accountId]
30
+ }
34
31
  },
35
- ns("CustomDateRangeStart") => {
36
- ns("Day") => period.from.day,
37
- ns("Month") => period.from.month,
38
- ns("Year") => period.from.year
32
+ ns("Time") => {
33
+ # apparently order is important, and end date has to be before start date, wtf
34
+ ns("CustomDateRangeEnd") => {
35
+ ns("Day") => period.to.day,
36
+ ns("Month") => period.to.month,
37
+ ns("Year") => period.to.year
38
+ },
39
+ ns("CustomDateRangeStart") => {
40
+ ns("Day") => period.from.day,
41
+ ns("Month") => period.from.month,
42
+ ns("Year") => period.from.year
43
+ }
44
+ # ns("PredefinedTime") => options[:time]
39
45
  }
40
- # ns("PredefinedTime") => options[:time]
46
+ },
47
+ :attributes! => {ns("ReportRequest") => {"xmlns:i" => "http://www.w3.org/2001/XMLSchema-instance",
48
+ "i:type" => ns("#{report_type}ReportRequest")}
41
49
  }
42
- },
43
- :attributes! => {ns("ReportRequest") => {"xmlns:i" => "http://www.w3.org/2001/XMLSchema-instance",
44
- "i:type" => ns("#{report_type}ReportRequest")}
45
- }
46
- })
50
+ })
51
+ rescue Savon::SOAPFault => e
52
+ err = e.to_hash[:fault][:detail][:ad_api_fault_detail][:errors][:ad_api_error][:error_code] rescue nil
53
+ msg = e.to_hash[:fault][:detail][:ad_api_fault_detail][:errors][:ad_api_error][:message] rescue ''
54
+ if err == 'AuthenticationTokenExpired'
55
+ @logger.error err
56
+ raise AuthenticationTokenExpired.new(msg)
57
+ end
58
+ @logger.error e.message
59
+ @logger.error msg
60
+ raise e
61
+ end
47
62
 
48
63
  response.body[:submit_generate_report_response][:report_request_id]
49
64
  end
@@ -81,7 +96,7 @@ module BingAdsReporting
81
96
  end
82
97
 
83
98
  def download(url)
84
- puts %Q{Downloading Bing report from: #{url}}
99
+ @logger.debug "Downloading Bing report from: #{url}"
85
100
  curl = Curl::Easy.new(url) do |c|
86
101
  c.use_ssl = 3
87
102
  c.ssl_version = 3
@@ -91,15 +106,24 @@ module BingAdsReporting
91
106
  end
92
107
 
93
108
  def client
109
+ if @settings[:username] && @settings[:password]
110
+ header = {ns('ApplicationToken') => @settings[:applicationToken],
111
+ ns('CustomerAccountId') => @settings[:accountId],
112
+ ns('CustomerId') => @settings[:customerId],
113
+ ns('DeveloperToken') => @settings[:developerToken],
114
+ ns('UserName') => @settings[:username],
115
+ ns('Password') => @settings[:password] }
116
+ else
117
+ header = {ns('ApplicationToken') => @settings[:applicationToken],
118
+ ns('CustomerAccountId') => @settings[:accountId],
119
+ ns('CustomerId') => @settings[:customerId],
120
+ ns('DeveloperToken') => @settings[:developerToken],
121
+ ns('AuthenticationToken') => @settings[:authenticationToken] }
122
+ end
94
123
  Savon.client({wsdl: "https://api.bingads.microsoft.com/Api/Advertiser/Reporting/V9/ReportingService.svc?wsdl",
95
124
  log_level: :info,
96
125
  namespaces: {"xmlns:arr" => 'http://schemas.microsoft.com/2003/10/Serialization/Arrays'},
97
- soap_header: {ns('ApplicationToken') => @settings[:applicationToken],
98
- ns('CustomerAccountId') => @settings[:accountId],
99
- ns('CustomerId') => @settings[:customerId],
100
- ns('DeveloperToken') => @settings[:developerToken],
101
- ns('UserName') => @settings[:username],
102
- ns('Password') => @settings[:password] }
126
+ soap_header: header
103
127
  })
104
128
  # .merge({pretty_print_xml: true, log_level: :debug})) # for more logging
105
129
  end
@@ -1,3 +1,3 @@
1
1
  module BingAdsReporting
2
- VERSION = "0.1.1"
2
+ VERSION = "1.1.1"
3
3
  end
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bing-ads-reporting
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Borkowski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-13 00:00:00.000000000 Z
11
+ date: 2015-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: datebox
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: savon
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: curb
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  description: Bing Ads Reports
@@ -72,17 +72,17 @@ require_paths:
72
72
  - lib
73
73
  required_ruby_version: !ruby/object:Gem::Requirement
74
74
  requirements:
75
- - - '>='
75
+ - - ">="
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
78
  required_rubygems_version: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  requirements: []
84
84
  rubyforge_project:
85
- rubygems_version: 2.2.2
85
+ rubygems_version: 2.4.5
86
86
  signing_key:
87
87
  specification_version: 4
88
88
  summary: Allows easily pull reports from Bing Ads