diff --git a/bing-ads-api.gemspec b/bing-ads-api.gemspec index 02e4cee..4864529 100644 --- a/bing-ads-api.gemspec +++ b/bing-ads-api.gemspec @@ -7,7 +7,7 @@ require "bing-ads-api/version" Gem::Specification.new do |s| s.name = "bing-ads-api" s.version = BingAdsApi::VERSION - s.authors = ["Juan Pablo Lopez N", "Alex Cavalli", "Colin Knox"] + s.authors = ["Juan Pablo Lopez N", "Alex Cavalli", "Colin Knox", "Arnold Roa"] s.email = ["alex.cavalli@offers.com"] s.homepage = "https://github.com/alexcavalli/bing-ads-api" s.summary = "Bing Ads API for Ruby" diff --git a/lib/bing-ads-api.rb b/lib/bing-ads-api.rb index 05f00cf..c749cd6 100644 --- a/lib/bing-ads-api.rb +++ b/lib/bing-ads-api.rb @@ -9,6 +9,8 @@ require 'bing-ads-api/soap_hasheable' require 'bing-ads-api/data_object' +# Require Reporting helper objects +Dir[File.join(File.dirname(__FILE__), 'bing-ads-api', 'data', 'reporting', 'helpers', '*.rb')].each { |file| require file } # Require services Dir[File.join(File.dirname(__FILE__), 'bing-ads-api', 'service', '*.rb')].each { |file| require file } @@ -19,6 +21,8 @@ # Require bulk data objects Dir[File.join(File.dirname(__FILE__), 'bing-ads-api', 'data', 'bulk', '*.rb')].each { |file| require file } +Dir[File.join(File.dirname(__FILE__), 'bing-ads-api', 'data', 'campaign_management', '*.rb')].each { |file| require file } + # Require Fault objects require 'bing-ads-api/fault/application_fault' @@ -29,9 +33,6 @@ require 'bing-ads-api/fault/operation_error' require 'bing-ads-api/fault/partial_errors' -# Require Reporting helper objects -Dir[File.join(File.dirname(__FILE__), 'bing-ads-api', 'data', 'reporting', 'helpers', '*.rb')].each { |file| require file } - # Require report request data objects require 'bing-ads-api/data/reporting/performance_report_request' require 'bing-ads-api/data/reporting/account_performance_report_request' diff --git a/lib/bing-ads-api.yml b/lib/bing-ads-api.yml index 3558a8c..ff676e0 100644 --- a/lib/bing-ads-api.yml +++ b/lib/bing-ads-api.yml @@ -15,7 +15,7 @@ wsdl: production: campaign_management: "https://campaign.api.bingads.microsoft.com/Api/Advertiser/CampaignManagement/V11/CampaignManagementService.svc?singleWsdl" customer_management: "https://clientcenter.api.bingads.microsoft.com/Api/CustomerManagement/v11/CustomerManagementService.svc?singleWsdl" - customer_billing: "https://clientcenter.api.bingads.microsoft.com/Api/Billing/v11/CustomerBillingService.svc?singleWsdl" + customer_billing: "https://clientcenter.api.bingads.microsoft.com/Api/Billing/v11/CustomerBillingService.svc?singleWsdl" reporting: "https://api.bingads.microsoft.com/Api/Advertiser/Reporting/v11/ReportingService.svc?singleWsdl" bulk: "https://bulk.api.bingads.microsoft.com/Api/Advertiser/CampaignManagement/V10/BulkService.svc?singleWsdl" diff --git a/lib/bing-ads-api/data/campaign_management/offline_conversion.rb b/lib/bing-ads-api/data/campaign_management/offline_conversion.rb new file mode 100644 index 0000000..bd7659b --- /dev/null +++ b/lib/bing-ads-api/data/campaign_management/offline_conversion.rb @@ -0,0 +1,28 @@ +# -*- encoding : utf-8 -*- + +module BingAdsApi + + class OfflineConversion < BingAdsApi::DataObject + include BingAdsApi::Helpers::TimeHelper + + attr_accessor :conversion_currency_code, + :conversion_name, + :conversion_time, + :conversion_value, + :microsoft_click_id + + def initialize(attributes={}) + attributes[:conversion_time] = to_ms_time(attributes[:conversion_time]) + super(attributes) + end + + def to_hash(keys = :underscore) + hash = super(keys) + hash[:'@xsi:type'] = "#{ClientProxy::NAMESPACE}:OfflineConversion" + return hash + end + + + end + +end diff --git a/lib/bing-ads-api/data/reporting/helpers/time_helper.rb b/lib/bing-ads-api/data/reporting/helpers/time_helper.rb index 4642ab8..9c2a6af 100644 --- a/lib/bing-ads-api/data/reporting/helpers/time_helper.rb +++ b/lib/bing-ads-api/data/reporting/helpers/time_helper.rb @@ -65,5 +65,11 @@ def time_to_hash(keys_case) end end + + def to_ms_time(time) + return nil if time.nil? + time.utc.strftime '%Y-%m-%dT%H:%M:%S.%7NZ' + end + end end diff --git a/lib/bing-ads-api/service/campaign_management.rb b/lib/bing-ads-api/service/campaign_management.rb index 3edea2b..28a4df7 100644 --- a/lib/bing-ads-api/service/campaign_management.rb +++ b/lib/bing-ads-api/service/campaign_management.rb @@ -44,6 +44,47 @@ def initialize(options={}) ## Operations Wrappers ## ######################### + def get_account_properties(account_property_name) + response = call(:get_account_properties, + { account_property_names: { account_property_name: account_property_name }}) + response_hash = get_response_hash(response, __method__) + + end + + # offline_conversion = BingAdsApi::OfflineConversion.new( + # conversion_currency_code: currency_code, + # conversion_name: conversion_name, + # conversion_time: conversion_time, + # conversion_value: conversion_value, + # microsoft_click_id: msclkid) + # service.apply_offline_conversion offline_conversion + def apply_offline_conversion(offline_conversion) + response = call(:apply_offline_conversions, + { offline_conversions: { offline_conversion: offline_conversion.to_hash(:camelcase) }}) + response_hash = get_response_hash(response, :apply_offline_conversions) + + # Checks if there are partial errors in the request + if response_hash[:partial_errors].key?(:batch_error) + partial_errors = BingAdsApi::PartialErrors.new( + response_hash[:partial_errors]) + response_hash[:partial_errors] = partial_errors + else + response_hash.delete(:partial_errors) + end + + response_hash + end + + # ToDo not yet working, the idea is be able to send an array of conversion, + # this is how the api is really designed to work + def apply_offline_conversions(offline_conversions) + raise 'parameter must be an array' unless offline_conversions.is? Array + + response = call(:apply_offline_conversions, + { offline_conversions: { offline_conversion: offline_conversion }}) + response_hash = get_response_hash(response, __method__) + end + # Public : Returns all the budgets found in the specified account # # Author:: dmitrii@webstreak.com diff --git a/lib/bing-ads-api/service/customer_management.rb b/lib/bing-ads-api/service/customer_management.rb index d43eef9..de6b960 100644 --- a/lib/bing-ads-api/service/customer_management.rb +++ b/lib/bing-ads-api/service/customer_management.rb @@ -66,12 +66,31 @@ def get_accounts_info(customer_id=nil, only_parent_accounts=false) {customer_id: customer_id || self.client_proxy.customer_id, only_parent_accounts: only_parent_accounts.to_s}) response_hash = get_response_hash(response, __method__) - accounts = response_hash[:accounts_info][:account_info].map do |account_hash| + + # if is a single item it returns a hash instead of array. + account_info = response_hash[:accounts_info][:account_info] + account_info = [account_info] if account_info.is_a? Hash + + accounts = account_info.map do |account_hash| BingAdsApi::AccountInfo.new(account_hash) end return accounts end + def get_customers_info(max_rows: 1) + response = call(:get_customers_info, + {customer_name_filter: '', top_n: max_rows}) + response_hash = get_response_hash(response, __method__) + + response_hash[:customers_info][:customer_info] + end + + def get_account(account_id) + response = call(:get_account, account_id: account_id) + response_hash = get_response_hash(response, __method__) + response_hash[:account] + end + private def get_service_name diff --git a/lib/bing-ads-api/version.rb b/lib/bing-ads-api/version.rb index 92b8b0c..5155090 100644 --- a/lib/bing-ads-api/version.rb +++ b/lib/bing-ads-api/version.rb @@ -2,5 +2,5 @@ module BingAdsApi # Gem Version - VERSION = "0.7.1" + VERSION = "0.7.2" end diff --git a/spec/customer_management_spec.rb b/spec/customer_management_spec.rb index 8c69226..3cf86c9 100644 --- a/spec/customer_management_spec.rb +++ b/spec/customer_management_spec.rb @@ -27,4 +27,11 @@ expect(response).to be_kind_of(Array) end + + it "should get customers info" do + response = service.get_customers_info + expect(response).not_to be_nil + expect(response).to be_kind_of(Array) + end + end