Skip to content

Commit 7c30877

Browse files
committed
Fixes require sentences for fault classes (issue #2). Support for OAuth
1 parent dab7e5a commit 7c30877

File tree

5 files changed

+92
-32
lines changed

5 files changed

+92
-32
lines changed

bing-ads-api-0.2.0.gem

0 Bytes
Binary file not shown.

lib/bing-ads-api.rb

+7-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@
1717
Dir[File.join(File.dirname(__FILE__), 'bing-ads-api', 'data', '*.rb')].each { |file| require file }
1818

1919
# Require Fault objects
20-
Dir[File.join(File.dirname(__FILE__), 'bing-ads-api', 'fault', '*.rb')].each { |file| require file }
20+
require 'bing-ads-api/fault/application_fault'
21+
require 'bing-ads-api/fault/ad_api_error'
22+
require 'bing-ads-api/fault/ad_api_fault_detail'
23+
require 'bing-ads-api/fault/api_fault_detail'
24+
require 'bing-ads-api/fault/batch_error'
25+
require 'bing-ads-api/fault/operation_error'
26+
require 'bing-ads-api/fault/partial_errors'
2127

2228
# Require Reporting helper objects
2329
Dir[File.join(File.dirname(__FILE__), 'bing-ads-api', 'data', 'reporting', 'helpers', '*.rb')].each { |file| require file }

lib/bing-ads-api.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ wsdl:
1212
reporting: "https://api.sandbox.bingads.microsoft.com/Api/Advertiser/Reporting/V9/ReportingService.svc?singleWsdl"
1313
production:
1414
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"
15+
customer_management: "https://clientcenter.api.bingads.microsoft.com/Api/CustomerManagement/v9/CustomerManagementService.svc?singleWsdl"
1616
reporting: "https://api.bingads.microsoft.com/Api/Advertiser/Reporting/V9/ReportingService.svc?singleWsdl"
1717

1818
# All major constants are here

lib/bing-ads-api/client_proxy.rb

+26-10
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class ClientProxy
3333

3434

3535
# Atributos del client proxy
36-
attr_accessor :username, :password, :developer_token, :wsdl_url, :account_id, :customer_id, :service, :namespace
36+
attr_accessor :username, :password, :developer_token, :authentication_token, :wsdl_url, :account_id, :customer_id, :service, :namespace
3737

3838
# Public : Constructor
3939
#
@@ -67,8 +67,12 @@ class ClientProxy
6767
# Returns:: ClientProxy instance
6868
def initialize(options=nil)
6969
if options
70-
@username ||= options[:username]
71-
@password ||= options[:password]
70+
if options[:authentication_token]
71+
@authentication_token ||= options[:authentication_token]
72+
else
73+
@username ||= options[:username]
74+
@password ||= options[:password]
75+
end
7276
@developer_token ||= options[:developer_token]
7377
@wsdl_url ||= options[:wsdl_url]
7478
@account_id ||= options[:account_id]
@@ -115,17 +119,29 @@ def get_proxy(client_settings)
115119
convert_request_keys_to: KEYS_CASE,
116120
wsdl: self.wsdl_url,
117121
namespace_identifier: NAMESPACE,
118-
soap_header: {
119-
"#{NAMESPACE.to_s}:CustomerAccountId" => self.account_id,
120-
"#{NAMESPACE.to_s}:CustomerId" => self.customer_id,
121-
"#{NAMESPACE.to_s}:DeveloperToken" => self.developer_token,
122-
"#{NAMESPACE.to_s}:UserName" => self.username,
123-
"#{NAMESPACE.to_s}:Password" => self.password
124-
}
122+
soap_header: build_headers
125123
}
126124
settings.merge(client_settings) if client_settings
125+
puts "settings"
126+
puts settings
127127
return Savon.client(settings)
128128
end
129+
130+
131+
def build_headers
132+
headers = {
133+
"#{NAMESPACE.to_s}:CustomerAccountId" => self.account_id,
134+
"#{NAMESPACE.to_s}:CustomerId" => self.customer_id,
135+
"#{NAMESPACE.to_s}:DeveloperToken" => self.developer_token,
136+
}
137+
if self.authentication_token
138+
headers["#{NAMESPACE.to_s}:AuthenticationToken"] = self.authentication_token
139+
else
140+
headers["#{NAMESPACE.to_s}:UserName"] = self.username
141+
headers["#{NAMESPACE.to_s}:Password"] = self.password
142+
end
143+
return headers
144+
end
129145
end
130146

131147
end

test/bing-ads-api_test.rb

+58-20
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@
66
# Author:: jlopezn@neonline.cl
77
class BingAdsApiTest < ActiveSupport::TestCase
88

9+
def setup
10+
@username = ""
11+
@password = ""
12+
@developer_token = ""
13+
@customer_id = ""
14+
@account_id = ""
15+
@auth_token = ""
16+
end
17+
918
test "truth" do
1019
assert_kind_of Module, BingAdsApi
1120
end
@@ -53,11 +62,11 @@ class BingAdsApiTest < ActiveSupport::TestCase
5362

5463
test "create client proxy" do
5564
options = {
56-
:username => "desarrollo_neonline",
57-
:password => "neonline2013",
58-
:developer_token => "BBD37VB98",
59-
:customer_id => "21021746",
60-
:account_id => "5978083",
65+
:username => @username,
66+
:password => @password,
67+
:developer_token => @developer_token,
68+
:customer_id => @customer_id,
69+
:account_id => @account_id,
6170
:wsdl_url => "https://api.sandbox.bingads.microsoft.com/Api/Advertiser/CampaignManagement/v9/CampaignManagementService.svc?singleWsdl"
6271
}
6372
client = BingAdsApi::ClientProxy.new(options)
@@ -71,11 +80,11 @@ class BingAdsApiTest < ActiveSupport::TestCase
7180

7281
test "create client proxy with additional settings" do
7382
options = {
74-
:username => "desarrollo_neonline",
75-
:password => "neonline2013",
76-
:developer_token => "BBD37VB98",
77-
:customer_id => "21021746",
78-
:account_id => "5978083",
83+
:username => @username,
84+
:password => @password,
85+
:developer_token => @developer_token,
86+
:customer_id => @customer_id,
87+
:account_id => @account_id,
7988
:wsdl_url => "https://api.sandbox.bingads.microsoft.com/Api/Advertiser/CampaignManagement/v9/CampaignManagementService.svc?singleWsdl",
8089
:proxy => {
8190
:logger => Rails.logger,
@@ -91,13 +100,42 @@ class BingAdsApiTest < ActiveSupport::TestCase
91100
end
92101

93102

103+
test "create oauth client proxy" do
104+
105+
options = {
106+
:authentication_token => @auth_token,
107+
:developer_token => @developer_token,
108+
:customer_id => @customer_id,
109+
:account_id => @account_id,
110+
:wsdl_url => "https://api.bingads.microsoft.com/Api/Advertiser/CampaignManagement/v9/CampaignManagementService.svc?singleWsdl",
111+
:proxy => {
112+
:logger => Rails.logger,
113+
:encoding => "UTF-8"
114+
}
115+
}
116+
client = BingAdsApi::ClientProxy.new(options)
117+
#puts client.inspect
118+
assert !client.nil?, "Client proxy not created"
119+
120+
#puts client.service
121+
assert !client.service.nil?, "Service client not created"
122+
123+
#call service method
124+
assert_nothing_raised(Exception, "Service call raised exception") {
125+
response = client.call(:get_campaigns_by_account_id,
126+
message: {Account_id: "2642632"})
127+
puts response
128+
}
129+
end
130+
131+
94132
test "call service" do
95133
options = {
96-
:username => "desarrollo_neonline",
97-
:password => "neonline2013",
98-
:developer_token => "BBD37VB98",
99-
:customer_id => "21021746",
100-
:account_id => "5978083",
134+
:username => @username,
135+
:password => @password,
136+
:developer_token => @developer_token,
137+
:customer_id => @customer_id,
138+
:account_id => @account_id,
101139
:wsdl_url => "https://api.sandbox.bingads.microsoft.com/Api/Advertiser/CampaignManagement/v9/CampaignManagementService.svc?singleWsdl"
102140
}
103141

@@ -113,11 +151,11 @@ class BingAdsApiTest < ActiveSupport::TestCase
113151
test "create and call from config" do
114152
config = BingAdsApi::Config.instance
115153
options = {
116-
:username => "desarrollo_neonline",
117-
:password => "neonline2013",
118-
:developer_token => "BBD37VB98",
119-
:customer_id => "21021746",
120-
:account_id => "5978083",
154+
:username => @username,
155+
:password => @password,
156+
:developer_token => @developer_token,
157+
:customer_id => @customer_id,
158+
:account_id => @account_id,
121159
:wsdl_url => config.service_wsdl(:sandbox, :campaign_management)
122160
}
123161

0 commit comments

Comments
 (0)