bing-ads-api 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.rdoc +92 -0
  3. data/Rakefile +38 -0
  4. data/lib/bing-ads-api.rb +38 -0
  5. data/lib/bing-ads-api.yml +345 -0
  6. data/lib/bing-ads-api/api_exception.rb +42 -0
  7. data/lib/bing-ads-api/client_proxy.rb +131 -0
  8. data/lib/bing-ads-api/config.rb +75 -0
  9. data/lib/bing-ads-api/constants.rb +133 -0
  10. data/lib/bing-ads-api/data/ad.rb +119 -0
  11. data/lib/bing-ads-api/data/ad_group.rb +121 -0
  12. data/lib/bing-ads-api/data/campaign.rb +40 -0
  13. data/lib/bing-ads-api/data/report_request.rb +78 -0
  14. data/lib/bing-ads-api/data/report_request_status.rb +48 -0
  15. data/lib/bing-ads-api/data/reporting/account_performance_report_request.rb +176 -0
  16. data/lib/bing-ads-api/data/reporting/campaign_performance_report_request.rb +186 -0
  17. data/lib/bing-ads-api/data/reporting/helpers/column_helper.rb +65 -0
  18. data/lib/bing-ads-api/data/reporting/helpers/filter_helper.rb +124 -0
  19. data/lib/bing-ads-api/data/reporting/helpers/scope_helper.rb +51 -0
  20. data/lib/bing-ads-api/data/reporting/helpers/time_helper.rb +69 -0
  21. data/lib/bing-ads-api/data/reporting/performance_report_request.rb +78 -0
  22. data/lib/bing-ads-api/data_object.rb +35 -0
  23. data/lib/bing-ads-api/fault/ad_api_error.rb +15 -0
  24. data/lib/bing-ads-api/fault/ad_api_fault_detail.rb +67 -0
  25. data/lib/bing-ads-api/fault/api_fault_detail.rb +97 -0
  26. data/lib/bing-ads-api/fault/application_fault.rb +18 -0
  27. data/lib/bing-ads-api/fault/batch_error.rb +47 -0
  28. data/lib/bing-ads-api/fault/operation_error.rb +22 -0
  29. data/lib/bing-ads-api/fault/partial_errors.rb +75 -0
  30. data/lib/bing-ads-api/service.rb +174 -0
  31. data/lib/bing-ads-api/service/campaign_management.rb +483 -0
  32. data/lib/bing-ads-api/service/reporting.rb +101 -0
  33. data/lib/bing-ads-api/soap_hasheable.rb +143 -0
  34. data/lib/bing-ads-api/version.rb +6 -0
  35. data/lib/locales/es.yml +174 -0
  36. data/lib/tasks/bing-ads-api_tasks.rake +4 -0
  37. data/test/bing-ads-api_test.rb +134 -0
  38. data/test/campaign_management_test.rb +463 -0
  39. data/test/data_object_test.rb +46 -0
  40. data/test/dummy/README.rdoc +261 -0
  41. data/test/dummy/Rakefile +7 -0
  42. data/test/dummy/app/assets/javascripts/application.js +15 -0
  43. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  44. data/test/dummy/app/controllers/application_controller.rb +3 -0
  45. data/test/dummy/app/helpers/application_helper.rb +2 -0
  46. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  47. data/test/dummy/config.ru +4 -0
  48. data/test/dummy/config/application.rb +56 -0
  49. data/test/dummy/config/boot.rb +10 -0
  50. data/test/dummy/config/database.yml +25 -0
  51. data/test/dummy/config/environment.rb +5 -0
  52. data/test/dummy/config/environments/development.rb +37 -0
  53. data/test/dummy/config/environments/production.rb +67 -0
  54. data/test/dummy/config/environments/test.rb +37 -0
  55. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  56. data/test/dummy/config/initializers/inflections.rb +15 -0
  57. data/test/dummy/config/initializers/mime_types.rb +5 -0
  58. data/test/dummy/config/initializers/secret_token.rb +7 -0
  59. data/test/dummy/config/initializers/session_store.rb +8 -0
  60. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  61. data/test/dummy/config/locales/en.yml +5 -0
  62. data/test/dummy/config/routes.rb +58 -0
  63. data/test/dummy/db/development.sqlite3 +0 -0
  64. data/test/dummy/db/test.sqlite3 +0 -0
  65. data/test/dummy/log/development.log +29 -0
  66. data/test/dummy/log/test.log +3264 -0
  67. data/test/dummy/public/404.html +26 -0
  68. data/test/dummy/public/422.html +26 -0
  69. data/test/dummy/public/500.html +25 -0
  70. data/test/dummy/public/favicon.ico +0 -0
  71. data/test/dummy/script/rails +6 -0
  72. data/test/report_request_test.rb +312 -0
  73. data/test/reporting_test.rb +145 -0
  74. data/test/test_helper.rb +11 -0
  75. metadata +205 -0
@@ -0,0 +1,42 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ module BingAdsApi
4
+
5
+ # Public : Generic exception thrown by service classes in BingAdsApi.
6
+ # Exception of this kind wrap an AdApiFaultDetail or ApiFaultDetail instance
7
+ # to look over the specific details of the SOAP request fault.
8
+ #
9
+ # Author:: jlopezn@neonline.cl
10
+ #
11
+ # Example
12
+ #
13
+ #
14
+ #
15
+ #
16
+ class ApiException < Exception
17
+
18
+ attr_accessor :fault_object
19
+
20
+ # Public : Constructor. Based on the default Exception constructor,
21
+ # adds the fault_object instance, that can be an ApiFaultDetail or
22
+ # AdApiFaultDetail instance
23
+ #
24
+ # === Parameters
25
+ # * fault_object - AdApiFaultDetail or ApiFaultDetail instance
26
+ # * msg - optional message
27
+ #
28
+ # Author:: jlopezn@neonline.cl
29
+ def initialize(fault_object, msg=nil)
30
+ super(msg)
31
+ self.fault_object = fault_object
32
+ end
33
+
34
+
35
+ # Public : Specified to string method
36
+ #
37
+ # Author:: jlopezn@neonline.cl
38
+ def to_s
39
+ super.to_s + " - " + fault_object.to_s
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,131 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ module BingAdsApi
4
+
5
+ # Public : ClientProxy es un objeto para encapsular la conexión y request
6
+ # de servicios a la API de Bing. En su inicialización requiere los datos
7
+ # de autenticación y el WSDL al servicio que se requiere.
8
+ #
9
+ # Author:: jlopezn@neonline.cl
10
+ #
11
+ # Examples
12
+ # # => hash con datos autenticación y WSDL
13
+ # options = {
14
+ # :username => "username",
15
+ # :password => "password",
16
+ # :developer_token => "THE_TOKEN",
17
+ # :customer_id => "123456",
18
+ # :account_id => "123456",
19
+ # :wsdl_url => "https://api.sandbox.bingads.microsoft.com/Api/Advertiser/CampaignManagement/v9/CampaignManagementService.svc?singleWsdl"
20
+ # }
21
+ # # => Instancia de ClientProxy
22
+ # client = BingAdsApi::ClientProxy.new(options)
23
+ # # => Llamada a servicio 'GetCampaignsByAccountId'
24
+ # response = client.service.call(:get_campaigns_by_account_id,
25
+ # message: { Account_id: client.account_id})
26
+ class ClientProxy
27
+
28
+ # Public : Namespace para atributos bing. Hace referencia a la versión de API usada
29
+ NAMESPACE = :v9
30
+
31
+ # Public : Case empleado los nombres de atributos en los XML
32
+ KEYS_CASE = :camelcase
33
+
34
+
35
+ # Atributos del client proxy
36
+ attr_accessor :username, :password, :developer_token, :wsdl_url, :account_id, :customer_id, :service, :namespace
37
+
38
+ # Public : Constructor
39
+ #
40
+ # Author:: jlopezn@neonline.cl
41
+ #
42
+ # === Parameters
43
+ # options - Hash con valores de autenticación y WSDL
44
+ #
45
+ #
46
+ # === Options
47
+ # * username - Bing Ads username
48
+ # * passwrod - Bing Ads user's sign-in password
49
+ # * developer_token - client application's developer access token
50
+ # * customer_id - identifier for the customer that owns the account
51
+ # * account_id - identifier of the account that own the entities in the request
52
+ # * wsdl_url - URL for the WSDL to be called
53
+ # * proxy - Hash with any Savon Client additional options (such as header, logger or enconding)
54
+ #
55
+ # === Examples
56
+ # options = {
57
+ # :username => "username",
58
+ # :password => "password",
59
+ # :developer_token => "THE_TOKEN",
60
+ # :customer_id => "123456",
61
+ # :account_id => "123456",
62
+ # :wsdl_url => "https://api.sandbox.bingads.microsoft.com/Api/Advertiser/CampaignManagement/v9/CampaignManagementService.svc?singleWsdl"
63
+ # }
64
+ # # => Instancia de ClientProxy
65
+ # client = BingAdsApi::ClientProxy.new(options)
66
+ #
67
+ # Returns:: ClientProxy instance
68
+ def initialize(options=nil)
69
+ if options
70
+ @username ||= options[:username]
71
+ @password ||= options[:password]
72
+ @developer_token ||= options[:developer_token]
73
+ @wsdl_url ||= options[:wsdl_url]
74
+ @account_id ||= options[:account_id]
75
+ @customer_id ||= options[:customer_id]
76
+ @namespace ||= options[:namespace]
77
+ end
78
+ self.service = get_proxy(options[:proxy])
79
+ end
80
+
81
+
82
+ # Public : Delegate for Savon::Client.call method
83
+ #
84
+ # Author:: jlopezn@neonline.cl
85
+ #
86
+ # === Parameters
87
+ # service_name - Service to be called
88
+ # message - Message for the service
89
+ # options - Additional options for the service
90
+ #
91
+ # === Examples
92
+ # client.call_service(:some_service_name, {key: value})
93
+ # # => <Response>
94
+ #
95
+ # Returns:: Response from the Savon::Client
96
+ # Raises:: Savon::SOAPFault Savon::HTTPError Savon::InvalidResponseError
97
+ def call(service_name, message, options={})
98
+ self.service.call(service_name, message)
99
+ end
100
+
101
+
102
+ private
103
+ # Internal : Wrapper for Savon client instances
104
+ #
105
+ # Author:: jlopezn@neonline.cl
106
+ #
107
+ # Examples
108
+ # get_proxy
109
+ # # => <Savon::Client>
110
+ #
111
+ # Returns:: Savon client instance
112
+ def get_proxy(client_settings)
113
+
114
+ settings = {
115
+ convert_request_keys_to: KEYS_CASE,
116
+ wsdl: self.wsdl_url,
117
+ 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
+ }
125
+ }
126
+ settings.merge(client_settings) if client_settings
127
+ return Savon.client(settings)
128
+ end
129
+ end
130
+
131
+ end
@@ -0,0 +1,75 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'singleton'
3
+
4
+ module BingAdsApi
5
+
6
+ # Public : Helper class for configuration issues like WSDL URLs and constants
7
+ #
8
+ # Author:: author@neonline.cl
9
+ #
10
+ # Examples
11
+ # class_usage
12
+ # # => class_usage_return
13
+ class Config
14
+ include Singleton
15
+
16
+ # Array with Bing Ads API environments: +sandbox+ and +production+
17
+ ENVIRONMENTS = ['sandbox', 'production']
18
+
19
+ attr_accessor :config
20
+ @config = YAML.load_file(File.join(File.dirname(__FILE__),"../bing-ads-api.yml"))
21
+
22
+ # Public : Constructor
23
+ #
24
+ # Author:: jlopezn@neonline.cl
25
+ def initialize
26
+ @config = YAML.load_file(File.join(File.dirname(__FILE__),"../bing-ads-api.yml"))
27
+ end
28
+
29
+ # Public : Returns the config file as an Hash instance
30
+ #
31
+ # Author:: jlopezn@neonline.cl
32
+ #
33
+ # Returns:: Hash
34
+ def self.hash_instance
35
+ instance.config
36
+ end
37
+
38
+ ## Constants
39
+ @config['constants'].each do |key, value|
40
+
41
+ define_method("#{key.to_s}_constants") do |constant=nil|
42
+ value[constant.to_s] if constant
43
+ value
44
+ end
45
+
46
+ end
47
+
48
+
49
+ # Public : Returns a String with WSDL url for the service indicated
50
+ #
51
+ # Author:: jlopezn@neonline.cl
52
+ #
53
+ # === Parameters
54
+ # environment - Bing Environment: 'sandbox' or 'production'
55
+ # service - service name
56
+ #
57
+ # === Examples
58
+ # config.service_wsdl(:sandbox, :campaign_management)
59
+ # # => "https://api.sandbox.bingads.microsoft.com/Api/Advertiser/CampaignManagement/v9/CampaignManagementService.svc?singleWsdl"
60
+ #
61
+ # Returns:: returns
62
+ # Raises:: exception
63
+ def service_wsdl(environment, service)
64
+ if (ENVIRONMENTS.include?(environment.to_s))
65
+ if @config['wsdl'][environment.to_s].include?(service.to_s)
66
+ return @config['wsdl'][environment.to_s][service.to_s]
67
+ end
68
+ raise "Unknown service '#{service.to_s}'. Available services: #{@config['wsdl'][environment.to_s].keys.join(", ")}"
69
+ end
70
+ raise "Invalid environment: #{environment}. Value should be 'sandbox' or 'production'"
71
+ end
72
+
73
+ end
74
+
75
+ end
@@ -0,0 +1,133 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ module BingAdsApi
4
+
5
+ # Public : Utility class for TimeZones values
6
+ #
7
+ # Example
8
+ # BingAdsApi::TimeZone.SANTIAGO
9
+ # # => 'Santiago'
10
+ #
11
+ # Author:: jlopezn@neonline.cl
12
+ module TimeZone
13
+
14
+
15
+ BingAdsApi::Config.instance.common_constants['time_zones'].each do |key, value|
16
+ TimeZone.const_set(key.upcase, value)
17
+ end
18
+
19
+ end
20
+
21
+ # Public : Utility class for AdLanguages values
22
+ #
23
+ # Example
24
+ # BingAdsApi::AdLanguages.SPANISH
25
+ # # => 'Spanish'
26
+ # BingAdsApi::AdLanguages.SPANISH_CODE
27
+ # # => 'ES'
28
+ #
29
+ # Author:: jlopezn@neonline.cl
30
+ module AdLanguage
31
+
32
+ BingAdsApi::Config.instance.common_constants['ad_languages'].each do |key, value|
33
+ if key == 'codes'
34
+ value.each do |code_key, code_value|
35
+ AdLanguage.const_set("#{code_key.upcase}_CODE", code_value)
36
+ end
37
+ else
38
+ AdLanguage.const_set(key.upcase, value)
39
+ end
40
+ end
41
+
42
+ end
43
+
44
+
45
+ ## Dynamic classes for campaign management constants
46
+ BingAdsApi::Config.instance.campaign_management_constants.each do |const_key, const_value|
47
+
48
+ const_module = Module.new do
49
+ # Dynamically create Constants classes for each value found
50
+ const_value.each do |key, value|
51
+ self.const_set(key.upcase, value)
52
+ end
53
+
54
+ end
55
+ BingAdsApi.const_set(const_key.camelize, const_module)
56
+
57
+ end
58
+
59
+ # Public : Module for Reporting formats
60
+ #
61
+ # Example
62
+ # BingAdsApi::ReportFormat.CSV
63
+ # # => 'Csv'
64
+ #
65
+ # Author:: jlopezn@neonline.cl
66
+ module ReportFormat
67
+ BingAdsApi::Config.instance.reporting_constants['format'].each do |key, value|
68
+ ReportFormat.const_set(key.upcase, value)
69
+ end
70
+ end
71
+
72
+
73
+ # Public : Module for Reporting languages
74
+ #
75
+ # Example
76
+ # BingAdsApi::ReportLanguage.ENGLISH
77
+ # # => 'English'
78
+ #
79
+ # Author:: jlopezn@neonline.cl
80
+ module ReportLanguage
81
+ BingAdsApi::Config.instance.reporting_constants['language'].each do |key, value|
82
+ ReportLanguage.const_set(key.upcase, value)
83
+ end
84
+ end
85
+
86
+
87
+ # Public : Module for Reporting languages
88
+ #
89
+ # Example
90
+ # BingAdsApi::ReportAggregation.SUMMARY
91
+ # # => 'Summary'
92
+ # BingAdsApi::ReportAggregation.HOURLY
93
+ # # => 'Hourly'
94
+ #
95
+ # Author:: jlopezn@neonline.cl
96
+ module ReportAggregation
97
+ BingAdsApi::Config.instance.reporting_constants['aggregation'].each do |key, value|
98
+ ReportAggregation.const_set(key.upcase, value)
99
+ end
100
+ end
101
+
102
+
103
+ # Public : Module for Reporting languages
104
+ #
105
+ # Example
106
+ # BingAdsApi::ReportTimePeriods.TODAY
107
+ # # => 'Today'
108
+ # BingAdsApi::ReportTimePeriods.LAST_WEEK
109
+ # # => 'LastWeek'
110
+ #
111
+ # Author:: jlopezn@neonline.cl
112
+ module ReportTimePeriods
113
+ BingAdsApi::Config.instance.reporting_constants['time_periods'].each do |key, value|
114
+ ReportTimePeriods.const_set(key.upcase, value)
115
+ end
116
+ end
117
+
118
+
119
+ ## Dynamic classes for reporting constants
120
+ # BingAdsApi::Config.instance.reporting_constants.each do |const_key, const_value|
121
+ #
122
+ # const_module = Module.new do
123
+ # # Dynamically create Constants classes for each value found
124
+ # const_value.each do |key, value|
125
+ # self.const_set(key.upcase, value)
126
+ # end
127
+ #
128
+ # end
129
+ # BingAdsApi.const_set(const_key.camelize, const_module)
130
+ #
131
+ # end
132
+
133
+ end
@@ -0,0 +1,119 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ module BingAdsApi
4
+
5
+ ##
6
+ # Public : Defines the base object of an ad.
7
+ # Do not instantiate this object. Instead you can instantiate the
8
+ # BingAdsApi::TextAd, BingAdsApi::MobileAd, or BingAdsApi::ProductAd
9
+ # object that derives from this object.
10
+ #
11
+ # Reference: http://msdn.microsoft.com/en-US/library/bing-ads-campaign-management-ad.aspx
12
+ #
13
+ # Author:: jlopezn@neonline.cl
14
+ #
15
+ class Ad < BingAdsApi::DataObject
16
+ include BingAdsApi::AdEditorialStatus
17
+ include BingAdsApi::AdStatus
18
+ include BingAdsApi::AdType
19
+
20
+
21
+ attr_accessor :id,
22
+
23
+ :device_preference,
24
+ :editorial_status,
25
+
26
+ :status,
27
+ :type
28
+
29
+ end
30
+
31
+ ##
32
+ # Public : Defines a text ad.
33
+ #
34
+ # Reference: http://msdn.microsoft.com/en-US/library/bing-ads-campaign-management-textad.aspx
35
+ #
36
+ # Author:: jlopezn@neonline.cl
37
+ #
38
+ class TextAd < BingAdsApi::Ad
39
+
40
+ attr_accessor :destination_url,
41
+ :display_url,
42
+ :text,
43
+ :title
44
+
45
+ # Public : Specification of DataObject#to_hash method that ads the type attribute based on this specific class
46
+ #
47
+ # Author:: jlopezn@neonline.cl
48
+ #
49
+ # keys - specifies the keys case
50
+ #
51
+ # Returns:: Hash
52
+ def to_hash(keys = :underscore)
53
+ hash = super(keys)
54
+ hash[get_attribute_key("type", keys)] = "Text"
55
+ return hash
56
+ end
57
+ end
58
+
59
+
60
+ ##
61
+ # Public : Defines a mobile ad. A mobile ad is displayed to a user
62
+ # when the ad is viewed on a low-fi mobile device.
63
+ #
64
+ # Reference: http://msdn.microsoft.com/en-US/library/bing-ads-campaign-management-mobilead.aspx
65
+ #
66
+ # Author:: jlopezn@neonline.cl
67
+ #
68
+ class MobileAd < BingAdsApi::Ad
69
+
70
+ attr_accessor :business_name,
71
+ :destination_url,
72
+ :display_url,
73
+ :phone_number,
74
+ :text,
75
+ :title
76
+
77
+ # Public : Specification of DataObject#to_hash method that ads the type attribute based on this specific class
78
+ #
79
+ # Author:: jlopezn@neonline.cl
80
+ #
81
+ # keys - specifies the keys case
82
+ #
83
+ # Returns:: Hash
84
+ def to_hash(keys = :underscore)
85
+ hash = super(keys)
86
+ hash[get_attribute_key("type", keys)] = "Mobile"
87
+ return hash
88
+ end
89
+
90
+ end
91
+
92
+
93
+ ##
94
+ # Public : Defines a product ad.
95
+ #
96
+ # Reference: http://msdn.microsoft.com/en-US/library/bing-ads-productad-campaign-management.aspx
97
+ #
98
+ # Author:: jlopezn@neonline.cl
99
+ #
100
+ class ProductAd < BingAdsApi::Ad
101
+
102
+ attr_accessor :promotional_text
103
+
104
+ # Public : Specification of DataObject#to_hash method that ads the type attribute based on this specific class
105
+ #
106
+ # Author:: jlopezn@neonline.cl
107
+ #
108
+ # keys - specifies the keys case
109
+ #
110
+ # Returns:: Hash
111
+ def to_hash(keys = :underscore)
112
+ hash = super(keys)
113
+ hash[get_attribute_key("type", keys)] = "Product"
114
+ return hash
115
+ end
116
+
117
+ end
118
+
119
+ end