adcenter_api 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/adcenter_api.rb CHANGED
@@ -40,23 +40,19 @@ module AdcenterApi
40
40
  # - auth_handler: instance of an AdsCommon::Auth::BaseHandler subclass to
41
41
  # handle authentication
42
42
  # - version: intended API version
43
- # - namespace: namespace to use as default for body
43
+ # - header_ns: header namespace
44
+ # - default_ns: default namespace
44
45
  #
45
46
  # Returns:
46
- # - a list of SOAP header handlers; one per provided header
47
+ # - SOAP header handler
47
48
  #
48
- def soap_header_handler(auth_handler, version, namespace)
49
+ def soap_header_handler(auth_handler, version, header_ns, default_ns)
49
50
  auth_method = @config.read('authentication.method', :CLIENTLOGIN)
50
- handler =
51
- case auth_method
52
- when :CLIENTLOGIN
53
- #auth_ns = api_config.client_login_config(:AUTH_NAMESPACE_PREAMBLE) + version.to_s
54
- #AdcenterApi::ClientLoginHeaderHandler.new(@credential_handler, auth_handler, namespace, auth_ns, version)
55
- AdcenterApi::ClientLoginHeaderHandler.new(@credential_handler, auth_handler, namespace, version)
56
- when :OAUTH, :OAUTH2
57
- AdsCommon::SavonHeaders::OAuthHeaderHandler.new(@credential_handler, auth_handler, namespace, version)
58
- end
59
- return handler
51
+ handler_class = case auth_method
52
+ when :CLIENTLOGIN then AdcenterApi::ClientLoginHeaderHandler
53
+ when :OAUTH, :OAUTH2 then AdsCommon::SavonHeaders::OAuthHeaderHandler
54
+ end
55
+ return handler_class.new(@credential_handler, auth_handler, header_ns, default_ns, version)
60
56
  end
61
57
 
62
58
  # Helper method to provide a simple way of doing an MCC-level operation
@@ -51,11 +51,13 @@ module AdcenterApi
51
51
  @@environment_config = {
52
52
  :PRODUCTION => {
53
53
  :oauth_scope => '',
54
+ :header_ns => 'https://adcenter.microsoft.com/api/adcenter/',
54
55
  :v7 => '',
55
56
  :v8 => ''
56
57
  },
57
58
  :SANDBOX => {
58
59
  :oauth_scope => '',
60
+ :header_ns => 'https://adcenter.microsoft.com/api/adcenter/',
59
61
  :v7 => '',
60
62
  :v8 => ''
61
63
  }
@@ -91,7 +93,6 @@ module AdcenterApi
91
93
  #TODO: remove client_login_config
92
94
  @@client_login_config = {
93
95
  :AUTH_SERVER => 'https://www.microsoft.com',
94
- :AUTH_NAMESPACE_PREAMBLE => 'https://adcenter.microsoft.com/api/adcenter/',
95
96
  :LOGIN_SERVICE_NAME => 'adcenter'
96
97
  }
97
98
 
@@ -3,56 +3,8 @@ require 'ads_common/savon_headers/base_header_handler'
3
3
 
4
4
  module AdcenterApi
5
5
  class ClientLoginHeaderHandler < AdsCommon::SavonHeaders::BaseHeaderHandler
6
- # Initializes a header handler.
7
- #
8
- # Args:
9
- # - credential_handler: a header with credential data
10
- # - auth_handler: a header with auth data
11
- # - element_name: an API-specific name of header element
12
- # - namespace: default namespace to use
13
- # - auth_namespace: namespace to use for auth headers
14
- # - version: services version
15
- #
16
- #def initialize(credential_handler, auth_handler, namespace, auth_namespace, version)
17
- def initialize(credential_handler, auth_handler, namespace, version)
18
- super(credential_handler, auth_handler, namespace, version)
19
- #@auth_namespace = auth_namespace
20
- end
21
-
22
- # Enriches soap object with API-specific headers like namespaces, login
23
- # credentials etc. Sets the default namespace for the body to the one
24
- # specified in initializer.
25
- #
26
- # Args:
27
- # - request: a HTTPI Request for extra configuration (unused)
28
- # - soap: a Savon soap object to fill fields in
29
- #
30
- # Returns:
31
- # - modified soap structure
32
- #
33
- def prepare_request(request, soap)
34
- super(request, soap)
35
- soap.header[:attributes!] ||= {}
36
- header_name = prepend_namespace(get_header_element_name())
37
- soap.header[:attributes!][header_name] ||= {}
38
- #soap.header[:attributes!][header_name]['xmlns'] = @auth_namespace
39
- return soap
40
- end
41
6
 
42
7
  private
43
- # Skips namespace prefixes for all elements except top level. Use default
44
- # (inherited) prefixing for the top level key.
45
- #
46
- # Args:
47
- # - str: String to prepend with a namespace
48
- #
49
- # Returns:
50
- # - String with a namespace
51
- #
52
- def prepend_namespace(str)
53
- #return get_header_element_name().eql?(str) ? super(str) : str
54
- super(str)
55
- end
56
8
 
57
9
  # Generates Adcenter API specific request header with ClientLogin data.
58
10
  def generate_request_header()
@@ -25,7 +25,7 @@ module AdcenterApi
25
25
  validate_headers_for_server(result)
26
26
 
27
27
  extra_headers = {
28
- 'userAgent' => generate_soap_user_agent(),
28
+ 'userAgent' => generate_user_agent(),
29
29
  'developerToken' => result[:developer_token]
30
30
  }
31
31
  if !@use_mcc and result[:client_customer_id]
@@ -38,26 +38,14 @@ module AdcenterApi
38
38
  return result
39
39
  end
40
40
 
41
- # Generates string to user as user agent in HTTP headers.
42
- def generate_http_user_agent(extra_ids = [])
43
- extra_ids, agent_app = get_user_agent_data(extra_ids)
44
- super(extra_ids, agent_app)
45
- end
46
-
47
- # Generates string to user as user agent in SOAP headers.
48
- def generate_soap_user_agent(extra_ids = [])
49
- extra_ids, agent_app = get_user_agent_data(extra_ids)
50
- super(extra_ids, agent_app)
51
- end
52
-
53
- private
54
-
55
- # Returns agent name and data for user-agent string generation.
56
- def get_user_agent_data(extra_ids)
41
+ # Generates string to use as user agent in headers.
42
+ def generate_user_agent(extra_ids = [])
57
43
  agent_app = @config.read('authentication.user_agent')
58
44
  extra_ids << ['AwApi-Ruby/%s' % AdcenterApi::ApiConfig::CLIENT_LIB_VERSION]
59
- return [extra_ids, agent_app]
60
- end
45
+ super(extra_ids, agent_app)
46
+ end
47
+
48
+ private
61
49
 
62
50
  # Validates that the right credentials are being used for the chosen
63
51
  # environment.
@@ -32,7 +32,7 @@ module AdcenterApi
32
32
  'Content-Type' => 'application/x-www-form-urlencoded',
33
33
  'Authorization' =>
34
34
  @auth_handler.auth_string(credentials, HTTPI::Request.new(url)),
35
- 'User-Agent' => @credential_handler.generate_http_user_agent(),
35
+ 'User-Agent' => @credential_handler.generate_user_agent(),
36
36
  'clientCustomerId' => credentials[:client_customer_id].to_s,
37
37
  'developerToken' => credentials[:developer_token]
38
38
  }
@@ -1,5 +1,5 @@
1
1
  module AdcenterApi
2
2
  module ApiConfig
3
- CLIENT_LIB_VERSION = "0.0.2"
3
+ CLIENT_LIB_VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -27,6 +27,7 @@ AdsCommon::SavonService.class_eval do
27
27
  additional_headers = args.delete(:headers) unless args.nil?
28
28
  prepend_namespace_to_hash(args, ns)
29
29
  prepend_namespace_to_hash(additional_headers, ns)
30
+ puts "**************************************args = #{args}"
30
31
  response = @client.request(ns, original_input_name) do |soap|
31
32
  @client.http.headers["SOAPAction"] = original_action_name
32
33
  soap.body = args
@@ -39,7 +40,11 @@ AdsCommon::SavonService.class_eval do
39
40
  if h.is_a?(Hash)
40
41
  h.dup.each do |k,v|
41
42
  h.delete(k)
42
- h[k.to_s=~ /^#{namespace}:/ ? k : prepend_namespace(k.to_s.camelize, namespace)] = prepend_namespace_to_hash(v, namespace)
43
+ if k.to_s=~/!$/ || k.to_s=~/:/ #on ne transforme pas les noms finissant par ! ou contenant : (exemple: attributes! ou xsi:type)
44
+ h[k] = prepend_namespace_to_hash(v, namespace)
45
+ else
46
+ h[k.to_s=~ /^#{namespace}:/ ? k : prepend_namespace(k.to_s.camelize, namespace)] = prepend_namespace_to_hash(v, namespace)
47
+ end
43
48
  end
44
49
  elsif h.is_a?(Array) # e.g: h = {:campaigns => {:campaign => [{:name => 'foo'}, {:name => 'foofoo'}]}}
45
50
  h.map!{|e| prepend_namespace_to_hash(e, namespace)}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adcenter_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-06 00:00:00.000000000 Z
12
+ date: 2012-08-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &2165880020 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,21 +21,31 @@ dependencies:
21
21
  version: 3.1.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2165880020
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 3.1.0
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: google-ads-common
27
- requirement: &2165879580 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
- - - ! '>='
35
+ - - ~>
31
36
  - !ruby/object:Gem::Version
32
- version: '0'
37
+ version: 0.8.0
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *2165879580
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.8.0
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: rake
38
- requirement: &2165879100 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: '0'
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *2165879100
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: rspec
49
- requirement: &2165878560 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ~>
@@ -54,7 +69,12 @@ dependencies:
54
69
  version: '2.8'
55
70
  type: :development
56
71
  prerelease: false
57
- version_requirements: *2165878560
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '2.8'
58
78
  description: Ruby wrapper for Microsoft Adcenter API
59
79
  email:
60
80
  - arambert@optimeez.com
@@ -128,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
148
  version: '0'
129
149
  requirements: []
130
150
  rubyforge_project:
131
- rubygems_version: 1.8.15
151
+ rubygems_version: 1.8.24
132
152
  signing_key:
133
153
  specification_version: 3
134
154
  summary: Ruby wrapper for Microsoft Adcenter API