Class: PPC::API::Sogou

Inherits:
Object
  • Object
show all
Extended by:
PPC::API
Defined in:
lib/ppc/api/sogou.rb,
lib/ppc/api/sogou/bulk.rb,
lib/ppc/api/sogou/plan.rb,
lib/ppc/api/sogou/group.rb,
lib/ppc/api/sogou/report.rb,
lib/ppc/api/sogou/account.rb,
lib/ppc/api/sogou/keyword.rb,
lib/ppc/api/sogou/creative.rb

Direct Known Subclasses

Account, Bulk, Creative, Group, Keyword, Plan, Report

Defined Under Namespace

Classes: Account, Bulk, Creative, Group, Keyword, Plan, Report

Class Method Summary collapse

Methods included from PPC::API

make_type, process, request, request_http_body, request_http_header, request_uri, reverse_type

Class Method Details

.debug_print(operation) ⇒ Object



45
46
47
# File 'lib/ppc/api/sogou.rb', line 45

def self.debug_print( operation )
  puts '{:header=>' + operation.header.to_s + ',  :body=>' + operation.body.to_s + '}'
end

.process(response, key, &func) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/ppc/api/sogou.rb', line 49

def self.process( response, key, &func )
  '''
  @input
  : type key : string
  : param key : type name, we will transfer camel string 
                         into snake_case symbol inside the method
  '''
  result = {}
  result[:succ]   = response[:header][:desc] == 'success'
  result[:failure] = response[:header][:failures]
  result[:no_quota] = (response[:header][:failures][:code] == '18') rescue false
  result[:result] = func[ response[:body][ key.snake_case.to_sym ] ] rescue nil
  result[:rquota] = response[:header][:rquota] if response[:header][:rquota]
  result
end

.request(auth, service, method, params = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/ppc/api/sogou.rb', line 15

def self.request( auth, service, method, params = {})
  '''
  ps. in savon3, .hash method will turn CamelXML to snake hash
  preprocess response, extract 
  '''

  service = service + "Service"
  client = Savon.new( "http://api.agent.sogou.com:8080/sem/sms/v1/#{service}?wsdl" )
  operation = client.operation( service, service, method )

  operation.header = { 
    AuthHeader:{
    username:   auth[:username],
    password:   auth[:password],
    token:      auth[:token]
  }
  }
  operation.body = {  (method+'Request').to_sym => params }
  # debug print
  debug_print( operation ) if ENV["DEBUG"]
  result = operation.call.hash[:envelope]
  #extract header and body
  response = { }
  response[:header] = result[:header][:res_header]
  response[:body] = result[:body][ (method + "Response").snake_case.to_sym ]
  # debug print
  puts response if ENV["DEBUG"]
  return response
end