bing-ads-api 0.2.1 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,7 +17,13 @@ Dir[File.join(File.dirname(__FILE__), 'bing-ads-api', 'service', '*.rb')].each {
17
17
  Dir[File.join(File.dirname(__FILE__), 'bing-ads-api', 'data', '*.rb')].each { |file| require file }
18
18
 
19
19
  # 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'
21
27
 
22
28
  # Require Reporting helper objects
23
29
  Dir[File.join(File.dirname(__FILE__), 'bing-ads-api', 'data', 'reporting', 'helpers', '*.rb')].each { |file| require file }
@@ -12,7 +12,7 @@ wsdl:
12
12
  reporting: "https://api.sandbox.bingads.microsoft.com/Api/Advertiser/Reporting/V9/ReportingService.svc?singleWsdl"
13
13
  production:
14
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"
15
+ customer_management: "https://clientcenter.api.bingads.microsoft.com/Api/CustomerManagement/v9/CustomerManagementService.svc?singleWsdl"
16
16
  reporting: "https://api.bingads.microsoft.com/Api/Advertiser/Reporting/V9/ReportingService.svc?singleWsdl"
17
17
 
18
18
  # All major constants are here
@@ -33,7 +33,7 @@ module BingAdsApi
33
33
 
34
34
 
35
35
  # 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
37
37
 
38
38
  # Public : Constructor
39
39
  #
@@ -67,8 +67,12 @@ module BingAdsApi
67
67
  # Returns:: ClientProxy instance
68
68
  def initialize(options=nil)
69
69
  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
72
76
  @developer_token ||= options[:developer_token]
73
77
  @wsdl_url ||= options[:wsdl_url]
74
78
  @account_id ||= options[:account_id]
@@ -115,17 +119,29 @@ module BingAdsApi
115
119
  convert_request_keys_to: KEYS_CASE,
116
120
  wsdl: self.wsdl_url,
117
121
  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
125
123
  }
126
124
  settings.merge(client_settings) if client_settings
125
+ puts "settings"
126
+ puts settings
127
127
  return Savon.client(settings)
128
128
  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
129
145
  end
130
146
 
131
147
  end
@@ -2,5 +2,5 @@
2
2
  module BingAdsApi
3
3
 
4
4
  # Gem Version
5
- VERSION = "0.2.1"
5
+ VERSION = "0.3"
6
6
  end
@@ -6,6 +6,15 @@ require 'test_helper'
6
6
  # Author:: jlopezn@neonline.cl
7
7
  class BingAdsApiTest < ActiveSupport::TestCase
8
8
 
9
+ def setup
10
+ @username = ""
11
+ @password = ""
12
+ @developer_token = ""
13
+ @customer_id = ""
14
+ @account_id = ""
15
+ @auth_token = ""
16
+ end
17
+
9
18
  test "truth" do
10
19
  assert_kind_of Module, BingAdsApi
11
20
  end
@@ -53,11 +62,11 @@ class BingAdsApiTest < ActiveSupport::TestCase
53
62
 
54
63
  test "create client proxy" do
55
64
  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,
61
70
  :wsdl_url => "https://api.sandbox.bingads.microsoft.com/Api/Advertiser/CampaignManagement/v9/CampaignManagementService.svc?singleWsdl"
62
71
  }
63
72
  client = BingAdsApi::ClientProxy.new(options)
@@ -71,11 +80,11 @@ class BingAdsApiTest < ActiveSupport::TestCase
71
80
 
72
81
  test "create client proxy with additional settings" do
73
82
  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,
79
88
  :wsdl_url => "https://api.sandbox.bingads.microsoft.com/Api/Advertiser/CampaignManagement/v9/CampaignManagementService.svc?singleWsdl",
80
89
  :proxy => {
81
90
  :logger => Rails.logger,
@@ -91,13 +100,42 @@ class BingAdsApiTest < ActiveSupport::TestCase
91
100
  end
92
101
 
93
102
 
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
+
94
132
  test "call service" do
95
133
  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,
101
139
  :wsdl_url => "https://api.sandbox.bingads.microsoft.com/Api/Advertiser/CampaignManagement/v9/CampaignManagementService.svc?singleWsdl"
102
140
  }
103
141
 
@@ -113,11 +151,11 @@ class BingAdsApiTest < ActiveSupport::TestCase
113
151
  test "create and call from config" do
114
152
  config = BingAdsApi::Config.instance
115
153
  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,
121
159
  :wsdl_url => config.service_wsdl(:sandbox, :campaign_management)
122
160
  }
123
161
 
@@ -29,3 +29,7 @@ Connecting to database specified by database.yml
29
29
  Connecting to database specified by database.yml
30
30
  Connecting to database specified by database.yml
31
31
  Connecting to database specified by database.yml
32
+ Connecting to database specified by database.yml
33
+ Connecting to database specified by database.yml
34
+ Connecting to database specified by database.yml
35
+ Connecting to database specified by database.yml
@@ -3290,3 +3290,33 @@ Connecting to database specified by database.yml
3290
3290
   (0.1ms) rollback transaction
3291
3291
   (0.1ms) begin transaction
3292
3292
   (0.1ms) rollback transaction
3293
+ Connecting to database specified by database.yml
3294
+  (0.4ms) begin transaction
3295
+  (0.1ms) rollback transaction
3296
+ Connecting to database specified by database.yml
3297
+  (0.3ms) begin transaction
3298
+  (0.1ms) rollback transaction
3299
+ Connecting to database specified by database.yml
3300
+  (0.3ms) begin transaction
3301
+  (0.1ms) rollback transaction
3302
+ Connecting to database specified by database.yml
3303
+  (0.4ms) begin transaction
3304
+  (0.1ms) rollback transaction
3305
+ Connecting to database specified by database.yml
3306
+  (0.3ms) begin transaction
3307
+  (0.1ms) rollback transaction
3308
+ Connecting to database specified by database.yml
3309
+  (0.3ms) begin transaction
3310
+  (0.1ms) rollback transaction
3311
+ Connecting to database specified by database.yml
3312
+  (0.3ms) begin transaction
3313
+  (0.1ms) rollback transaction
3314
+ Connecting to database specified by database.yml
3315
+  (0.3ms) begin transaction
3316
+  (0.1ms) rollback transaction
3317
+ Connecting to database specified by database.yml
3318
+  (0.6ms) begin transaction
3319
+  (0.1ms) rollback transaction
3320
+ Connecting to database specified by database.yml
3321
+  (1.0ms) begin transaction
3322
+  (0.1ms) 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.2.1
4
+ version: '0.3'
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-27 00:00:00.000000000 Z
12
+ date: 2014-03-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails