Skip to content

Commit

Permalink
Customer Management service: get accounts info
Browse files Browse the repository at this point in the history
  • Loading branch information
jplopez committed Feb 26, 2014
1 parent 1337688 commit 85af080
Show file tree
Hide file tree
Showing 57 changed files with 1,463 additions and 49 deletions.
19 changes: 11 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
bing-ads-api (0.0.1)
bing-ads-api (0.1.0)
rails
savon (~> 2.3.0)

Expand Down Expand Up @@ -41,7 +41,7 @@ GEM
arel (3.0.3)
builder (3.0.4)
erubis (2.7.0)
gyoku (1.1.0)
gyoku (1.1.1)
builder (>= 2.1.2)
hike (1.2.3)
httpi (2.1.0)
Expand All @@ -57,8 +57,10 @@ GEM
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.25.1)
mini_portile (0.5.2)
multi_json (1.8.2)
nokogiri (1.5.10)
nokogiri (1.6.1)
mini_portile (~> 0.5.0)
nori (2.3.0)
polyglot (0.3.3)
rack (1.4.5)
Expand Down Expand Up @@ -87,14 +89,14 @@ GEM
rdoc (3.12.2)
json (~> 1.4)
rubyntlm (0.3.4)
savon (2.3.0)
savon (2.3.3)
akami (~> 1.2.0)
builder (>= 2.1.2)
gyoku (~> 1.1.0)
httpi (~> 2.1.0)
nokogiri (>= 1.4.0, < 1.6)
nokogiri (>= 1.4.0)
nori (~> 2.3.0)
wasabi (~> 3.2.0)
wasabi (~> 3.2.2)
sprockets (2.2.2)
hike (~> 1.2)
multi_json (~> 1.0)
Expand All @@ -107,9 +109,10 @@ GEM
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.38)
wasabi (3.2.0)
wasabi (3.2.3)
httpi (~> 2.0)
nokogiri (>= 1.4.0, < 1.6)
mime-types (< 2.0.0)
nokogiri (>= 1.4.0)

PLATFORMS
ruby
Expand Down
31 changes: 30 additions & 1 deletion README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Add to your Gemfile
gem 'bing-ads-api'

== Examples
So far, I've just integrated some methods from +CampaignManagement+ and +Reporting+ services
So far, I've just integrated some methods from +CampaignManagement+, +CustomerManagement+ and +Reporting+ services


=== Authentication
Expand Down Expand Up @@ -87,6 +87,35 @@ a object representation of the hash
# => campaigns is an array of BingAdsApi::Campaign


=== Customer Management

Example of service object initialization:
options = {
:environment => :sandbox,
:username => "desarrollo_neonline",
:password => "neonline2013",
:developer_token => "BBD37VB98",
:customer_id => "21021746",
:account_id => "5978083"
}
service = BingAdsApi::CustomerManagement.new(options)

==== Get accounts info
accounts = service.get_accounts_info
# => accounts is an array of BingAdsApi::AccountsInfo

For this method you can also specify a diferent customer id
accounts = service.get_accounts_info(12345)
# => accounts is an array of BingAdsApi::AccountsInfo
That would give you the customer's 12345 accounts



=== Reporting

==== Submit generate report


==== Poll generate report


Binary file added bing-ads-api-0.1.0.gem
Binary file not shown.
10 changes: 10 additions & 0 deletions lib/bing-ads-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
wsdl:
sandbox:
campaign_management: "https://api.sandbox.bingads.microsoft.com/Api/Advertiser/CampaignManagement/v9/CampaignManagementService.svc?singleWsdl"
customer_management: "https://clientcenter.api.sandbox.bingads.microsoft.com/Api/CustomerManagement/v9/CustomerManagementService.svc?singleWsdl"
reporting: "https://api.sandbox.bingads.microsoft.com/Api/Advertiser/Reporting/V9/ReportingService.svc?singleWsdl"
production:
campaign_management: "https://api.bingads.microsoft.com/Api/Advertiser/CampaignManagement/v9/CampaignManagementService.svc?singleWsdl"
customer_management: "i.bingads.microsoft.com/Api/CustomerManagement/v9/CustomerManagementService.svc?singleWsdl"
reporting: "https://api.bingads.microsoft.com/Api/Advertiser/Reporting/V9/ReportingService.svc?singleWsdl"

# All major constants are here
Expand Down Expand Up @@ -177,6 +179,14 @@ constants:
paused: 'Paused'
deleted: 'Deleted'
inactive: 'Inactive'
# Constants specific for customer management
customer_management:
account_life_cycle_statuses:
draft: "Draft"
active: "Active"
inactive: "Inactive"
pause: "Pause"
pending: "Pending"
# Constants specific for reporting services
reporting:
format:
Expand Down
17 changes: 17 additions & 0 deletions lib/bing-ads-api/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,23 @@ module AdLanguage

end


## Dynamic classes for customer management constants
BingAdsApi::Config.instance.customer_management_constants.each do |const_key, const_value|

const_module = Module.new do
# Dynamically create Constants classes for each value found
const_value.each do |key, value|
self.const_set(key.upcase, value)
end

end
BingAdsApi.const_set(const_key.camelize, const_module)

end



# Public : Module for Reporting formats
#
# Example
Expand Down
72 changes: 72 additions & 0 deletions lib/bing-ads-api/data/accounts_info.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# -*- encoding : utf-8 -*-

module BingAdsApi

# Public : Define an account info
#
# Author:: [email protected]
#
# Examples
# campaign = BingAdsApi::AccountInfo.new(
# :account_life_cycle_status => BingAdsApi::AccountsInfo::DRAFT
# :name => "Account Name",
# :number => 1234567,
# :pause_reason => "1")
# # => <BingAdsApi::AccountInfo>
class AccountInfo < BingAdsApi::DataObject
include BingAdsApi::AccountLifeCycleStatuses

attr_accessor :id, :account_life_cycle_status, :name, :number, :pause_reason

# Public:: Returns true if the account is in status active
#
# Author:: [email protected]
#
# Returns:: boolean
def active?
return account_life_cycle_status == ACTIVE
end


# Public:: Returns true if the account is in status draft
#
# Author:: [email protected]
#
# Returns:: boolean
def draft?
return account_life_cycle_status == DRAFT
end


# Public:: Returns true if the account is in status inactive
#
# Author:: [email protected]
#
# Returns:: boolean
def inactive?
return account_life_cycle_status == INACTIVE
end


# Public:: Returns true if the account is in status pause
#
# Author:: [email protected]
#
# Returns:: boolean
def pause?
return account_life_cycle_status == PAUSE
end


# Public:: Returns true if the account is in status pending
#
# Author:: [email protected]
#
# Returns:: boolean
def pending?
return account_life_cycle_status == PENDING
end

end

end
4 changes: 3 additions & 1 deletion lib/bing-ads-api/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Service
# Default logger for services
LOGGER = Logger.new(STDOUT)


# Public : Constructor
#
# Author:: [email protected]
Expand Down Expand Up @@ -62,7 +63,8 @@ def initialize(options={})
self.client_proxy = BingAdsApi::ClientProxy.new(clientProxySettings)

end



# Public : This is a utility wrapper for calling services into the
# +ClientProxy+. This methods handle all the +Savon::Client+ Exceptions
# and returns a Hash with the call response
Expand Down
83 changes: 83 additions & 0 deletions lib/bing-ads-api/service/customer_management.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# -*- encoding : utf-8 -*-
module BingAdsApi


# Public : This class represents the Customer Management Services
# defined in the Bing Ads API, to manage customer accounts
#
# Author:: [email protected]
#
# Examples
# options = {
# :environment => :sandbox,
# :username => "username",
# :password => "pass",
# :developer_token => "SOME_TOKEN",
# :customer_id => "1234567",
# :account_id => "9876543" }
# service = BingAdsApi::CustomerManagement.new(options)
class CustomerManagement < BingAdsApi::Service


# Public : Constructor
#
# Author:: [email protected]
#
# options - Hash with the parameters for the client proxy and the environment
#
# Examples
# options = {
# :environment => :sandbox,
# :username => "username",
# :password => "password",
# :developer_token => "DEV_TOKEN",
# :customer_id => "123456",
# :account_id => "654321"
# }
# service = BingAdsApi::CustomerManagement.new(options)
def initialize(options={})
super(options)
end


#########################
## Operations Wrappers ##
#########################

# Public : Gets a list of objects that contains account identification information,
# for example the name and identifier of the account, for the specified customer.
#
# Author:: [email protected]
#
# === Parameters
# +customer_id+ - identifier for the customer who owns the accounts. If nil, then the authentication customer id is used
# +only_parent_accounts+ - boolean to determine whether to return only the accounts that belong to the customer or to also
# return the accounts that the customer manages for other customers. Default false
#
# === Examples
# customer_management_service.get_accounts_info
# # => Array[BingAdsApi::AccountsInfo]
#
# Returns:: Array of BingAdsApi::AccountsInfo
#
# Raises:: exception
def get_accounts_info(customer_id=nil, only_parent_accounts=false)
response = call(:get_accounts_info,
{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|
BingAdsApi::AccountInfo.new(account_hash)
end
return accounts
end


private
def get_service_name
"customer_management"
end

end

end
17 changes: 17 additions & 0 deletions lib/bing-ads-api/soap_hasheable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,27 @@ def object_to_hash(object, keys_case=:underscore)
end


# Public:: Normalize the keys of a hash with the case specified
#
# Author:: [email protected]
#
# === Parameters
# * +hash+ - Hash to be normalized
# * +keys_case+ - :underscore or :camelcase
#
# === Examples
# normalize_hash_keys({:some_key => value1}, :camelcase)
# # => {"SomeKey" => value1}
#
# normalize_hash_keys({:some_key => value1}, :underscore)
# # => {"some_key" => value1}
#
# Returns:: Hash
def normalize_hash_keys(hash, keys_case)
return hash.inject({}) { |h, (k, v)| h[get_attribute_key(k, keys_case)] = object_to_hash(v, keys_case); h }
end


# Internal : Helper method to determinate the key name in the hash for the SOAP request
#
# Author:: [email protected]
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.1.0"
VERSION = "0.2.0"
end
Loading

0 comments on commit 85af080

Please sign in to comment.