bing-ads-api 0.1.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.
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,121 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ module BingAdsApi
4
+
5
+ # Public : Defines an ad group.
6
+ #
7
+ # Author:: jlopezn@neonline.cl
8
+ #
9
+ # Examples
10
+ # ad_group = BingAdsApi::AdGroup.new(
11
+ # :ad_distribution => BingAdsApi::AdGroup::SEARCH,
12
+ # :language => BingAdsApi::AdGroup::SPANISH,
13
+ # :name => "Ad Group name",
14
+ # :pricing_model => BingAdsApi::AdGroup::CPC,
15
+ # :bidding_model => BingAdsApi::AdGroup::KEYWORD)
16
+ # # => <BingAdsApi::AdGroup>
17
+ class AdGroup < BingAdsApi::DataObject
18
+ include BingAdsApi::AdDistribution
19
+ include BingAdsApi::AdRotationType
20
+ include BingAdsApi::PricingModel
21
+ include BingAdsApi::BiddingModel
22
+ include BingAdsApi::AdLanguage
23
+ include BingAdsApi::AdGroupStatus
24
+
25
+
26
+ attr_accessor :id,
27
+ :ad_distribution,
28
+ :ad_rotation,
29
+
30
+ :broad_match_bid,
31
+ :content_match_bid,
32
+ :exact_match_bid,
33
+ :phrase_match_bid,
34
+
35
+ :bidding_model,
36
+ :pricing_model,
37
+
38
+ :language,
39
+ :name,
40
+ :status,
41
+
42
+ :start_date,
43
+ :end_date
44
+
45
+
46
+
47
+ # Public : Constructor in a ActiveRecord style, with a hash of attributes as input
48
+ #
49
+ # Author:: jlopezn@neonline.cl
50
+ #
51
+ # attributes - Hash with the objects attributes
52
+ def initialize(attributes={})
53
+ super(attributes)
54
+ set_custom_attributes(attributes)
55
+ end
56
+
57
+
58
+ # Public : Returns this object as a hash to SOAP requests
59
+ # This methods is a specialization for the +DataObject#to_hash+ method
60
+ # that ads specific hash keys for the AdGroup object
61
+ #
62
+ # Author:: jlopezn@neonline.cl
63
+ #
64
+ # keys - specifies the keys case: CamelCase or underscore_case
65
+ #
66
+ # Returns:: Hash
67
+ def to_hash(keys = :underscore)
68
+ hash = super(keys)
69
+
70
+ amount_key = get_attribute_key("amount", keys)
71
+ if self.content_match_bid
72
+ #hash.delete(:content_match_bid)
73
+ hash[get_attribute_key("content_match_bid", keys)] = {amount_key => self.content_match_bid}
74
+ end
75
+
76
+ if self.exact_match_bid
77
+ hash[get_attribute_key("exact_match_bid", keys)] = {amount_key => self.exact_match_bid}
78
+ end
79
+
80
+ if self.phrase_match_bid
81
+ hash[get_attribute_key("phrase_match_bid", keys)] = {amount_key => self.phrase_match_bid}
82
+ end
83
+
84
+ if self.broad_match_bid
85
+ hash[get_attribute_key("broad_match_bid", keys)] = {amount_key => self.broad_match_bid}
86
+ end
87
+
88
+ if self.start_date
89
+ hash[get_attribute_key("start_date", keys)] = date_to_hash(self.start_date, keys)
90
+ end
91
+
92
+ if self.end_date
93
+ hash[get_attribute_key("end_date", keys)] = date_to_hash(self.end_date, keys)
94
+ end
95
+
96
+ return hash
97
+ end
98
+
99
+
100
+ private
101
+ def set_custom_attributes(attributes)
102
+ self.content_match_bid = attributes[:content_match_bid][:amount] if attributes.key?(:content_match_bid)
103
+ self.exact_match_bid = attributes[:exact_match_bid][:amount] if attributes.key?(:exact_match_bid)
104
+ self.phrase_match_bid = attributes[:phrase_match_bid][:amount] if attributes.key?(:phrase_match_bid)
105
+ self.broad_match_bid = attributes[:broad_match_bid][:amount] if attributes.key?(:broad_match_bid)
106
+
107
+ if attributes.key?(:start_date) && !attributes[:start_date].nil?
108
+ self.start_date = DateTime.strptime(
109
+ "#{attributes[:start_date][:year]}-#{attributes[:start_date][:month]}-#{attributes[:start_date][:day]}",
110
+ "%Y-%m-%d")
111
+ end
112
+
113
+ if attributes.key?(:end_date) && !attributes[:end_date].nil?
114
+ self.end_date = DateTime.strptime(
115
+ "#{attributes[:end_date][:year]}-#{attributes[:end_date][:month]}-#{attributes[:end_date][:day]}",
116
+ "%Y-%m-%d")
117
+ end
118
+
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,40 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ module BingAdsApi
4
+
5
+ # Public : Define a campaign
6
+ #
7
+ # Author:: jlopezn@neonline.cl
8
+ #
9
+ # Examples
10
+ # campaign = BingAdsApi::Campaign.new(
11
+ # :budget_type => BingAdsApi::Campaign::DAILY_BUDGET_STANDARD,
12
+ # :conversion_tracking_enabled => "false",
13
+ # :daily_budget => 2000,
14
+ # :daylight_saving => "false",
15
+ # :description => name + " first description",
16
+ # :monthly_budget => 5400,
17
+ # :name => name + " first name",
18
+ # :status => BingAdsApi::Campaign::PAUSED,
19
+ # :time_zone => BingAdsApi::Campaign::SANTIAGO)
20
+ # # => <BingAdsApi::Campaign>
21
+ class Campaign < BingAdsApi::DataObject
22
+ include BingAdsApi::TimeZone
23
+ include BingAdsApi::BudgetLimitType
24
+ include BingAdsApi::CampaignStatus
25
+ include BingAdsApi::PricingModel
26
+
27
+
28
+ attr_accessor :id,
29
+ :budget_type,
30
+ :conversion_tracking_enabled,
31
+ :daily_budget,
32
+ :daylight_saving,
33
+ :description,
34
+ :monthly_budget,
35
+ :name,
36
+ :status,
37
+ :time_zone
38
+
39
+ end
40
+ end
@@ -0,0 +1,78 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ module BingAdsApi
4
+
5
+ ##
6
+ # Public : Defines the base object for all report requests.
7
+ # Do not instantiate this object. Instead, you may instantiate one
8
+ # of the following report request objects which derives from this object to request a report.
9
+ #
10
+ # Reference: http://msdn.microsoft.com/en-us/library/bing-ads-reporting-bing-ads-reportrequest.aspx
11
+ #
12
+ # Author:: jlopezn@neonline.cl
13
+ class ReportRequest < BingAdsApi::DataObject
14
+
15
+ # Valid Formats for reports
16
+ FORMATS = BingAdsApi::Config.instance.
17
+ reporting_constants['format']
18
+
19
+ # Valid languages for reports
20
+ LANGUAGES = BingAdsApi::Config.instance.
21
+ reporting_constants['language']
22
+
23
+ # Valid report request status for reports
24
+ REQUEST_STATUS = BingAdsApi::Config.instance.
25
+ reporting_constants['request_status_type']
26
+
27
+ attr_accessor :format, :language, :report_name, :return_only_complete_data
28
+
29
+ # Public : Constructor. Adds validations to format and language attributes
30
+ #
31
+ # Author:: jlopezn@neonline.cl
32
+ #
33
+ # === Parameters
34
+ # attributes - Hash with Report request parameters
35
+ def initialize(attributes={})
36
+ raise Exception.new("Invalid format '#{attributes[:format]}'") if !valid_format(attributes[:format])
37
+ raise Exception.new("Invalid language '#{attributes[:language]}'") if !valid_language(attributes[:language])
38
+ super(attributes)
39
+ self.return_only_complete_data = attributes[:return_only_complete_data] || false
40
+ end
41
+
42
+
43
+ # Public:: Returns this object as a Hash for SOAP Requests
44
+ #
45
+ # Author:: jlopezn@neonline.cl
46
+ #
47
+ # === Parameters
48
+ # * +keys_case+ - specifies the case for the hash keys
49
+ # ==== keys_case
50
+ # * :camelcase - CamelCase
51
+ # * :underscore - underscore_case
52
+ #
53
+ # === Examples
54
+ # report_request.to_hash(:camelcase)
55
+ # # => {"Format"=>"Xml", "Language"=>"English", "ReportName"=>"My Report", "ReturnOnlyCompleteData"=>true}
56
+ #
57
+ # Returns:: Hash
58
+ def to_hash(keys_case = :underscore)
59
+ hash = super(keys_case)
60
+ hash[get_attribute_key('format', keys_case)] = FORMATS[self.format.to_s]
61
+ hash[get_attribute_key('language', keys_case)] = LANGUAGES[self.language.to_s]
62
+ return hash
63
+ end
64
+
65
+ private
66
+
67
+ def valid_format(format)
68
+ return FORMATS.key?(format.to_s)
69
+ end
70
+
71
+
72
+ def valid_language(language)
73
+ return LANGUAGES.key?(language.to_s)
74
+ end
75
+
76
+ end
77
+
78
+ end
@@ -0,0 +1,48 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ module BingAdsApi
4
+
5
+ ##
6
+ # Public : Defines the status of a report request.
7
+ #
8
+ # Reference: http://msdn.microsoft.com/en-US/library/bing-ads-reporting-bing-ads-reportrequeststatus.aspx
9
+ #
10
+ # Author:: jlopezn@neonline.cl
11
+ class ReportRequestStatus < BingAdsApi::DataObject
12
+
13
+ # Valid report request status for reports
14
+ REQUEST_STATUS = BingAdsApi::Config.instance.
15
+ reporting_constants['request_status_type']
16
+
17
+ attr_accessor :report_download_url, :status
18
+
19
+ # Public:: Returns true if the status is success
20
+ #
21
+ # Author:: jlopezn@neonline.cl
22
+ #
23
+ # Returns:: boolean
24
+ def success?
25
+ return status == REQUEST_STATUS['success']
26
+ end
27
+
28
+ # Public:: Returns true if the status is pending
29
+ #
30
+ # Author:: jlopezn@neonline.cl
31
+ #
32
+ # Returns:: boolean
33
+ def pending?
34
+ return status == REQUEST_STATUS['pending']
35
+ end
36
+
37
+ # Public:: Returns true if the status is error
38
+ #
39
+ # Author:: jlopezn@neonline.cl
40
+ #
41
+ # Returns:: boolean
42
+ def error?
43
+ return status == REQUEST_STATUS['error']
44
+ end
45
+
46
+ end
47
+
48
+ end
@@ -0,0 +1,176 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ module BingAdsApi
4
+
5
+ ##
6
+ # Public : Defines the base object for all report requests.
7
+ # Do not instantiate this object. Instead, you may instantiate one
8
+ # of the following report request objects which derives from this object to request a report.
9
+ #
10
+ # Reference: http://msdn.microsoft.com/en-us/library/bing-ads-reporting-bing-ads-reportrequest.aspx
11
+ #
12
+ # Author:: jlopezn@neonline.cl
13
+ #
14
+ # === Usage
15
+ #
16
+ # request = BingAdsApi::AccountPerformanceReportRequest.new(
17
+ # :format => :xml,
18
+ # :language => :english,
19
+ # :report_name => "Me report",
20
+ # :aggregation => :hourly,
21
+ # :columns => [:account_name, :account_number, :time_period],
22
+ # # The filter is specified as a hash
23
+ # :filter => {
24
+ # :ad_distribution => :search,
25
+ # :device_os => :android,
26
+ # :device_type => :tablet,
27
+ # :status => :submited },
28
+ # :scope => {
29
+ # :account_ids => [123456, 234567],
30
+ # :campaigns => [<BingAdsApi::CampaignReportScope>] },
31
+ # # predefined date
32
+ # :time => :this_week)
33
+ #
34
+ # request2 = BingAdsApi::AccountPerformanceReportRequest.new(
35
+ # :format => :csv,
36
+ # :language => :french,
37
+ # :report_name => "Me report",
38
+ # :aggregation => :daily,
39
+ # :columns => [:account_name, :account_number, :time_period],
40
+ # # no filter is specified
41
+ # :scope => {
42
+ # :account_ids => [123456, 234567],
43
+ # :campaigns => [<BingAdsApi::CampaignReportScope>] },
44
+ # # Custom date range
45
+ # :time => {
46
+ # :custom_date_range_start => {:day => 1, :month => 12, :year => 2013},
47
+ # :custom_date_range_end => {:day => 12, :month => 12, :year => 2013} }
48
+ # )
49
+ class AccountPerformanceReportRequest < BingAdsApi::PerformanceReportRequest
50
+
51
+ # Valid Columns for this report request
52
+ COLUMNS = BingAdsApi::Config.instance.
53
+ reporting_constants['account_performance_report']['columns']
54
+
55
+ # Valid Filters for this report request
56
+ FILTERS = BingAdsApi::Config.instance.
57
+ reporting_constants['account_performance_report']['filter']
58
+
59
+
60
+ # Public : Constructor. Adds a validations for the columns, filter
61
+ # and scope attributes
62
+ #
63
+ # Author:: jlopezn@neonline.cl
64
+ #
65
+ # === Parameters
66
+ # attributes - Hash with the report request attributes
67
+ #
68
+ # === Example
69
+ #
70
+ # request = BingAdsApi::AccountPerformanceReportRequest.new(
71
+ # :format => :xml,
72
+ # :language => :english,
73
+ # :report_name => "Me report",
74
+ # :aggregation => :hourly,
75
+ # :columns => [:account_name, :account_number, :time_period],
76
+ # # The filter is specified as a hash
77
+ # :filter => {
78
+ # :ad_distribution => :search,
79
+ # :device_os => :android,
80
+ # :device_type => :tablet,
81
+ # :status => :submited },
82
+ # :scope => {
83
+ # :account_ids => [123456, 234567],
84
+ # :campaigns => [<BingAdsApi::CampaignReportScope>] },
85
+ # # predefined date
86
+ # :time => :this_week)
87
+ #
88
+ # request2 = BingAdsApi::AccountPerformanceReportRequest.new(
89
+ # :format => :csv,
90
+ # :language => :french,
91
+ # :report_name => "Me report",
92
+ # :aggregation => :daily,
93
+ # :columns => [:account_name, :account_number, :time_period],
94
+ # # no filter is specified
95
+ # :scope => {
96
+ # :account_ids => [123456, 234567],
97
+ # :campaigns => [<BingAdsApi::CampaignReportScope>] },
98
+ # # Custom date range
99
+ # :time => {
100
+ # :custom_date_range_start => {:day => 1, :month => 12, :year => 2013},
101
+ # :custom_date_range_end => {:day => 12, :month => 12, :year => 2013} }
102
+ # )
103
+ def initialize(attributes={})
104
+ raise "Invalid columns" if !valid_columns(COLUMNS, attributes[:columns])
105
+ raise "Invalid filters" if !valid_filter(FILTERS, attributes[:filter])
106
+ raise "Invalid scope" if !valid_scope(attributes[:scope])
107
+ super(attributes)
108
+ end
109
+
110
+ # Public:: Returns the object as a Hash valid for SOAP requests
111
+ #
112
+ # Author:: jlopezn@neonline.cl
113
+ #
114
+ # === Parameters
115
+ # * +keys_case+ - case for the hashes keys: underscore or camelcase
116
+ #
117
+ # Returns:: Hash
118
+ def to_hash(keys = :underscore)
119
+ hash = super(keys)
120
+ hash[get_attribute_key('columns', keys)] =
121
+ columns_to_hash(COLUMNS, columns, keys)
122
+ hash[get_attribute_key('filter', keys)] =
123
+ filter_to_hash(FILTERS, keys)
124
+ hash[get_attribute_key('scope', keys)] = scope_to_hash(keys)
125
+ hash["@xsi:type"] = type_attribute_for_soap
126
+ return hash
127
+ end
128
+
129
+ private
130
+
131
+
132
+
133
+ # Internal:: Validates the scope attribute given in the constructor
134
+ #
135
+ # Author:: jlopezn@neonline.cl
136
+ #
137
+ # === Parameters
138
+ # * +scope+ - value for the 'scope' key in the has initializer
139
+ #
140
+ # Returns:: true if the scope specification is valid. Raises Exception otherwise
141
+ #
142
+ # Raises:: Exception if the scope is not valid
143
+ def valid_scope(scope)
144
+ raise Exception.new("Invalid scope: no account_ids key") if !scope.key?(:account_ids)
145
+ return true
146
+ end
147
+
148
+
149
+ # Internal:: Returns the scope attribute as a hash for the SOAP request
150
+ #
151
+ # Author:: jlopezn@neonline.cl
152
+ #
153
+ # === Parameters
154
+ # * +keys_case+ - case for the hash: underscore or camelcase
155
+ #
156
+ # Returns:: Hash
157
+ def scope_to_hash(keys_case=:underscore)
158
+ return { get_attribute_key('account_ids', keys_case) =>
159
+ {"ins0:long" => object_to_hash(scope[:account_ids], keys_case)} }
160
+ end
161
+
162
+
163
+ # Internal:: Returns a string with type attribute for the ReportRequest SOAP tag
164
+ #
165
+ # Author:: jlopezn@neonline.cl
166
+ #
167
+ # Returns:: "v9:AccountPerformanceReportRequest"
168
+ def type_attribute_for_soap
169
+ return BingAdsApi::ClientProxy::NAMESPACE.to_s + ":" +
170
+ BingAdsApi::Config.instance.
171
+ reporting_constants['account_performance_report']['type']
172
+ end
173
+
174
+ end
175
+
176
+ end