Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Offline Conversion implementation #1

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bing-ads-api.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ["[email protected]"]
s.homepage = "https://github.com/alexcavalli/bing-ads-api"
s.summary = "Bing Ads API for Ruby"
Expand Down
7 changes: 4 additions & 3 deletions lib/bing-ads-api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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'
Expand All @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion lib/bing-ads-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
28 changes: 28 additions & 0 deletions lib/bing-ads-api/data/campaign_management/offline_conversion.rb
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions lib/bing-ads-api/data/reporting/helpers/time_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
41 changes: 41 additions & 0 deletions lib/bing-ads-api/service/campaign_management.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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:: [email protected]
Expand Down
21 changes: 20 additions & 1 deletion lib/bing-ads-api/service/customer_management.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/bing-ads-api/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
module BingAdsApi

# Gem Version
VERSION = "0.7.1"
VERSION = "0.7.2"
end
7 changes: 7 additions & 0 deletions spec/customer_management_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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