bing-ads-api 0.1.0 → 0.2.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.
- data/README.rdoc +30 -1
- data/lib/bing-ads-api.yml +10 -0
- data/lib/bing-ads-api/constants.rb +17 -0
- data/lib/bing-ads-api/data/accounts_info.rb +72 -0
- data/lib/bing-ads-api/service.rb +3 -1
- data/lib/bing-ads-api/service/customer_management.rb +83 -0
- data/lib/bing-ads-api/soap_hasheable.rb +17 -0
- data/lib/bing-ads-api/version.rb +1 -1
- data/test/customer_management_test.rb +44 -0
- data/test/dummy/log/development.log +2 -0
- data/test/dummy/log/test.log +28 -0
- metadata +6 -2
data/README.rdoc
CHANGED
@@ -13,7 +13,7 @@ Add to your Gemfile
|
|
13
13
|
gem 'bing-ads-api'
|
14
14
|
|
15
15
|
== Examples
|
16
|
-
So far, I've just integrated some methods from +CampaignManagement+ and +Reporting+ services
|
16
|
+
So far, I've just integrated some methods from +CampaignManagement+, +CustomerManagement+ and +Reporting+ services
|
17
17
|
|
18
18
|
|
19
19
|
=== Authentication
|
@@ -87,6 +87,35 @@ a object representation of the hash
|
|
87
87
|
# => campaigns is an array of BingAdsApi::Campaign
|
88
88
|
|
89
89
|
|
90
|
+
=== Customer Management
|
91
|
+
|
92
|
+
Example of service object initialization:
|
93
|
+
options = {
|
94
|
+
:environment => :sandbox,
|
95
|
+
:username => "desarrollo_neonline",
|
96
|
+
:password => "neonline2013",
|
97
|
+
:developer_token => "BBD37VB98",
|
98
|
+
:customer_id => "21021746",
|
99
|
+
:account_id => "5978083"
|
100
|
+
}
|
101
|
+
service = BingAdsApi::CustomerManagement.new(options)
|
102
|
+
|
103
|
+
==== Get accounts info
|
104
|
+
accounts = service.get_accounts_info
|
105
|
+
# => accounts is an array of BingAdsApi::AccountsInfo
|
106
|
+
|
107
|
+
For this method you can also specify a diferent customer id
|
108
|
+
accounts = service.get_accounts_info(12345)
|
109
|
+
# => accounts is an array of BingAdsApi::AccountsInfo
|
110
|
+
That would give you the customer's 12345 accounts
|
111
|
+
|
112
|
+
|
90
113
|
|
91
114
|
=== Reporting
|
92
115
|
|
116
|
+
==== Submit generate report
|
117
|
+
|
118
|
+
|
119
|
+
==== Poll generate report
|
120
|
+
|
121
|
+
|
data/lib/bing-ads-api.yml
CHANGED
@@ -8,9 +8,11 @@
|
|
8
8
|
wsdl:
|
9
9
|
sandbox:
|
10
10
|
campaign_management: "https://api.sandbox.bingads.microsoft.com/Api/Advertiser/CampaignManagement/v9/CampaignManagementService.svc?singleWsdl"
|
11
|
+
customer_management: "https://clientcenter.api.sandbox.bingads.microsoft.com/Api/CustomerManagement/v9/CustomerManagementService.svc?singleWsdl"
|
11
12
|
reporting: "https://api.sandbox.bingads.microsoft.com/Api/Advertiser/Reporting/V9/ReportingService.svc?singleWsdl"
|
12
13
|
production:
|
13
14
|
campaign_management: "https://api.bingads.microsoft.com/Api/Advertiser/CampaignManagement/v9/CampaignManagementService.svc?singleWsdl"
|
15
|
+
customer_management: "i.bingads.microsoft.com/Api/CustomerManagement/v9/CustomerManagementService.svc?singleWsdl"
|
14
16
|
reporting: "https://api.bingads.microsoft.com/Api/Advertiser/Reporting/V9/ReportingService.svc?singleWsdl"
|
15
17
|
|
16
18
|
# All major constants are here
|
@@ -177,6 +179,14 @@ constants:
|
|
177
179
|
paused: 'Paused'
|
178
180
|
deleted: 'Deleted'
|
179
181
|
inactive: 'Inactive'
|
182
|
+
# Constants specific for customer management
|
183
|
+
customer_management:
|
184
|
+
account_life_cycle_statuses:
|
185
|
+
draft: "Draft"
|
186
|
+
active: "Active"
|
187
|
+
inactive: "Inactive"
|
188
|
+
pause: "Pause"
|
189
|
+
pending: "Pending"
|
180
190
|
# Constants specific for reporting services
|
181
191
|
reporting:
|
182
192
|
format:
|
@@ -56,6 +56,23 @@ module BingAdsApi
|
|
56
56
|
|
57
57
|
end
|
58
58
|
|
59
|
+
|
60
|
+
## Dynamic classes for customer management constants
|
61
|
+
BingAdsApi::Config.instance.customer_management_constants.each do |const_key, const_value|
|
62
|
+
|
63
|
+
const_module = Module.new do
|
64
|
+
# Dynamically create Constants classes for each value found
|
65
|
+
const_value.each do |key, value|
|
66
|
+
self.const_set(key.upcase, value)
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
BingAdsApi.const_set(const_key.camelize, const_module)
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
|
59
76
|
# Public : Module for Reporting formats
|
60
77
|
#
|
61
78
|
# Example
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
|
3
|
+
module BingAdsApi
|
4
|
+
|
5
|
+
# Public : Define an account info
|
6
|
+
#
|
7
|
+
# Author:: jlopezn@neonline.cl
|
8
|
+
#
|
9
|
+
# Examples
|
10
|
+
# campaign = BingAdsApi::AccountInfo.new(
|
11
|
+
# :account_life_cycle_status => BingAdsApi::AccountsInfo::DRAFT
|
12
|
+
# :name => "Account Name",
|
13
|
+
# :number => 1234567,
|
14
|
+
# :pause_reason => "1")
|
15
|
+
# # => <BingAdsApi::AccountInfo>
|
16
|
+
class AccountInfo < BingAdsApi::DataObject
|
17
|
+
include BingAdsApi::AccountLifeCycleStatuses
|
18
|
+
|
19
|
+
attr_accessor :id, :account_life_cycle_status, :name, :number, :pause_reason
|
20
|
+
|
21
|
+
# Public:: Returns true if the account is in status active
|
22
|
+
#
|
23
|
+
# Author:: jlopezn@neonline.cl
|
24
|
+
#
|
25
|
+
# Returns:: boolean
|
26
|
+
def active?
|
27
|
+
return account_life_cycle_status == ACTIVE
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
# Public:: Returns true if the account is in status draft
|
32
|
+
#
|
33
|
+
# Author:: jlopezn@neonline.cl
|
34
|
+
#
|
35
|
+
# Returns:: boolean
|
36
|
+
def draft?
|
37
|
+
return account_life_cycle_status == DRAFT
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
# Public:: Returns true if the account is in status inactive
|
42
|
+
#
|
43
|
+
# Author:: jlopezn@neonline.cl
|
44
|
+
#
|
45
|
+
# Returns:: boolean
|
46
|
+
def inactive?
|
47
|
+
return account_life_cycle_status == INACTIVE
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
# Public:: Returns true if the account is in status pause
|
52
|
+
#
|
53
|
+
# Author:: jlopezn@neonline.cl
|
54
|
+
#
|
55
|
+
# Returns:: boolean
|
56
|
+
def pause?
|
57
|
+
return account_life_cycle_status == PAUSE
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
# Public:: Returns true if the account is in status pending
|
62
|
+
#
|
63
|
+
# Author:: jlopezn@neonline.cl
|
64
|
+
#
|
65
|
+
# Returns:: boolean
|
66
|
+
def pending?
|
67
|
+
return account_life_cycle_status == PENDING
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
data/lib/bing-ads-api/service.rb
CHANGED
@@ -13,6 +13,7 @@ module BingAdsApi
|
|
13
13
|
# Default logger for services
|
14
14
|
LOGGER = Logger.new(STDOUT)
|
15
15
|
|
16
|
+
|
16
17
|
# Public : Constructor
|
17
18
|
#
|
18
19
|
# Author:: jlopezn@neonline.cl
|
@@ -62,7 +63,8 @@ module BingAdsApi
|
|
62
63
|
self.client_proxy = BingAdsApi::ClientProxy.new(clientProxySettings)
|
63
64
|
|
64
65
|
end
|
65
|
-
|
66
|
+
|
67
|
+
|
66
68
|
# Public : This is a utility wrapper for calling services into the
|
67
69
|
# +ClientProxy+. This methods handle all the +Savon::Client+ Exceptions
|
68
70
|
# and returns a Hash with the call response
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module BingAdsApi
|
3
|
+
|
4
|
+
|
5
|
+
# Public : This class represents the Customer Management Services
|
6
|
+
# defined in the Bing Ads API, to manage customer accounts
|
7
|
+
#
|
8
|
+
# Author:: jlopezn@neonline.cl
|
9
|
+
#
|
10
|
+
# Examples
|
11
|
+
# options = {
|
12
|
+
# :environment => :sandbox,
|
13
|
+
# :username => "username",
|
14
|
+
# :password => "pass",
|
15
|
+
# :developer_token => "SOME_TOKEN",
|
16
|
+
# :customer_id => "1234567",
|
17
|
+
# :account_id => "9876543" }
|
18
|
+
# service = BingAdsApi::CustomerManagement.new(options)
|
19
|
+
class CustomerManagement < BingAdsApi::Service
|
20
|
+
|
21
|
+
|
22
|
+
# Public : Constructor
|
23
|
+
#
|
24
|
+
# Author:: jlopezn@neonline.cl
|
25
|
+
#
|
26
|
+
# options - Hash with the parameters for the client proxy and the environment
|
27
|
+
#
|
28
|
+
# Examples
|
29
|
+
# options = {
|
30
|
+
# :environment => :sandbox,
|
31
|
+
# :username => "username",
|
32
|
+
# :password => "password",
|
33
|
+
# :developer_token => "DEV_TOKEN",
|
34
|
+
# :customer_id => "123456",
|
35
|
+
# :account_id => "654321"
|
36
|
+
# }
|
37
|
+
# service = BingAdsApi::CustomerManagement.new(options)
|
38
|
+
def initialize(options={})
|
39
|
+
super(options)
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
#########################
|
44
|
+
## Operations Wrappers ##
|
45
|
+
#########################
|
46
|
+
|
47
|
+
# Public : Gets a list of objects that contains account identification information,
|
48
|
+
# for example the name and identifier of the account, for the specified customer.
|
49
|
+
#
|
50
|
+
# Author:: jlopezn@neonline.cl
|
51
|
+
#
|
52
|
+
# === Parameters
|
53
|
+
# +customer_id+ - identifier for the customer who owns the accounts. If nil, then the authentication customer id is used
|
54
|
+
# +only_parent_accounts+ - boolean to determine whether to return only the accounts that belong to the customer or to also
|
55
|
+
# return the accounts that the customer manages for other customers. Default false
|
56
|
+
#
|
57
|
+
# === Examples
|
58
|
+
# customer_management_service.get_accounts_info
|
59
|
+
# # => Array[BingAdsApi::AccountsInfo]
|
60
|
+
#
|
61
|
+
# Returns:: Array of BingAdsApi::AccountsInfo
|
62
|
+
#
|
63
|
+
# Raises:: exception
|
64
|
+
def get_accounts_info(customer_id=nil, only_parent_accounts=false)
|
65
|
+
response = call(:get_accounts_info,
|
66
|
+
{customer_id: customer_id || self.client_proxy.customer_id,
|
67
|
+
only_parent_accounts: only_parent_accounts.to_s})
|
68
|
+
response_hash = get_response_hash(response, __method__)
|
69
|
+
accounts = response_hash[:accounts_info][:account_info].map do |account_hash|
|
70
|
+
BingAdsApi::AccountInfo.new(account_hash)
|
71
|
+
end
|
72
|
+
return accounts
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
private
|
77
|
+
def get_service_name
|
78
|
+
"customer_management"
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
@@ -86,10 +86,27 @@ module BingAdsApi
|
|
86
86
|
end
|
87
87
|
|
88
88
|
|
89
|
+
# Public:: Normalize the keys of a hash with the case specified
|
90
|
+
#
|
91
|
+
# Author:: jlopexn@neonline.cl
|
92
|
+
#
|
93
|
+
# === Parameters
|
94
|
+
# * +hash+ - Hash to be normalized
|
95
|
+
# * +keys_case+ - :underscore or :camelcase
|
96
|
+
#
|
97
|
+
# === Examples
|
98
|
+
# normalize_hash_keys({:some_key => value1}, :camelcase)
|
99
|
+
# # => {"SomeKey" => value1}
|
100
|
+
#
|
101
|
+
# normalize_hash_keys({:some_key => value1}, :underscore)
|
102
|
+
# # => {"some_key" => value1}
|
103
|
+
#
|
104
|
+
# Returns:: Hash
|
89
105
|
def normalize_hash_keys(hash, keys_case)
|
90
106
|
return hash.inject({}) { |h, (k, v)| h[get_attribute_key(k, keys_case)] = object_to_hash(v, keys_case); h }
|
91
107
|
end
|
92
108
|
|
109
|
+
|
93
110
|
# Internal : Helper method to determinate the key name in the hash for the SOAP request
|
94
111
|
#
|
95
112
|
# Author:: jlopezn@neonline.cl
|
data/lib/bing-ads-api/version.rb
CHANGED
@@ -0,0 +1,44 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
# Public : Test case for Customer Management services
|
5
|
+
#
|
6
|
+
# Author:: jlopezn@neonline.cl
|
7
|
+
class CustomerManagementTest < ActiveSupport::TestCase
|
8
|
+
|
9
|
+
def setup
|
10
|
+
|
11
|
+
@config = BingAdsApi::Config.instance
|
12
|
+
@options = {
|
13
|
+
:environment => :sandbox,
|
14
|
+
:username => "desarrollo_neonline",
|
15
|
+
:password => "neonline2013",
|
16
|
+
:developer_token => "BBD37VB98",
|
17
|
+
:customer_id => "21021746",
|
18
|
+
:account_id => "5978083"
|
19
|
+
}
|
20
|
+
@service = BingAdsApi::CustomerManagement.new(@options)
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
test "truth" do
|
26
|
+
assert_kind_of Module, BingAdsApi
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
test "initialize" do
|
31
|
+
@service = BingAdsApi::CustomerManagement.new(@options)
|
32
|
+
assert !@service.nil?, "CustomerManagement service not instantiated"
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
test "get accounts info" do
|
37
|
+
response = @service.get_accounts_info
|
38
|
+
puts response
|
39
|
+
assert !response.nil?, "No response received"
|
40
|
+
assert response.is_a?(Array), "No Array as response received"
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -27,3 +27,5 @@ Connecting to database specified by database.yml
|
|
27
27
|
Connecting to database specified by database.yml
|
28
28
|
Connecting to database specified by database.yml
|
29
29
|
Connecting to database specified by database.yml
|
30
|
+
Connecting to database specified by database.yml
|
31
|
+
Connecting to database specified by database.yml
|
data/test/dummy/log/test.log
CHANGED
@@ -3262,3 +3262,31 @@ Connecting to database specified by database.yml
|
|
3262
3262
|
Connecting to database specified by database.yml
|
3263
3263
|
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
|
3264
3264
|
[1m[35m (0.1ms)[0m rollback transaction
|
3265
|
+
Connecting to database specified by database.yml
|
3266
|
+
[1m[36m (13.2ms)[0m [1mbegin transaction[0m
|
3267
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
3268
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
3269
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
3270
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
3271
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
3272
|
+
Connecting to database specified by database.yml
|
3273
|
+
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
|
3274
|
+
[1m[35m (0.2ms)[0m rollback transaction
|
3275
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
3276
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
3277
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
3278
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
3279
|
+
Connecting to database specified by database.yml
|
3280
|
+
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
|
3281
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
3282
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
3283
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
3284
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
3285
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
3286
|
+
Connecting to database specified by database.yml
|
3287
|
+
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
|
3288
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
3289
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
3290
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
3291
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
3292
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bing-ads-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-02-
|
12
|
+
date: 2014-02-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -78,11 +78,13 @@ files:
|
|
78
78
|
- lib/bing-ads-api/data/reporting/account_performance_report_request.rb
|
79
79
|
- lib/bing-ads-api/data/reporting/campaign_performance_report_request.rb
|
80
80
|
- lib/bing-ads-api/data/reporting/performance_report_request.rb
|
81
|
+
- lib/bing-ads-api/data/accounts_info.rb
|
81
82
|
- lib/bing-ads-api/data/ad.rb
|
82
83
|
- lib/bing-ads-api/data/ad_group.rb
|
83
84
|
- lib/bing-ads-api/config.rb
|
84
85
|
- lib/bing-ads-api/service/campaign_management.rb
|
85
86
|
- lib/bing-ads-api/service/reporting.rb
|
87
|
+
- lib/bing-ads-api/service/customer_management.rb
|
86
88
|
- lib/bing-ads-api/version.rb
|
87
89
|
- lib/bing-ads-api/client_proxy.rb
|
88
90
|
- lib/bing-ads-api/service.rb
|
@@ -138,6 +140,7 @@ files:
|
|
138
140
|
- test/test_helper.rb
|
139
141
|
- test/report_request_test.rb
|
140
142
|
- test/reporting_test.rb
|
143
|
+
- test/customer_management_test.rb
|
141
144
|
- test/bing-ads-api_test.rb
|
142
145
|
- test/data_object_test.rb
|
143
146
|
homepage: http://www.github.com/jplopez/bing-ads-api
|
@@ -201,5 +204,6 @@ test_files:
|
|
201
204
|
- test/test_helper.rb
|
202
205
|
- test/report_request_test.rb
|
203
206
|
- test/reporting_test.rb
|
207
|
+
- test/customer_management_test.rb
|
204
208
|
- test/bing-ads-api_test.rb
|
205
209
|
- test/data_object_test.rb
|