Class: PPC::API::Qihu::Plan

Inherits:
PPC::API::Qihu show all
Defined in:
lib/ppc/api/qihu/plan.rb

Constant Summary collapse

Service =
'campaign'

Class Method Summary collapse

Methods inherited from PPC::API::Qihu

make_type, process, request_http_body, request_http_header, request_uri, reverse_type, to_id_list, to_json_string

Methods included from PPC::API

#debug_off, #debug_on, #is_no_quota, #make_type, #process, #request, #request_http_body, #request_http_header, #request_uri, #reverse_type

Class Method Details

.add(auth, plan) ⇒ Object

奇虎计划API不提供批量服务



44
45
46
47
48
# File 'lib/ppc/api/qihu/plan.rb', line 44

def self.add( auth, plan )
  response = request( auth, Service, 'add', make_type( plan )[0])
  # 这里将返回的简单int做一个array和hash的封装一保证接口和百度,搜狗的一致性
  process( response, 'id' ){ |x| [ { id:x.to_i } ] }
end

.all(auth) ⇒ Object

combine two original method to provice new method



38
39
40
41
# File 'lib/ppc/api/qihu/plan.rb', line 38

def self.all( auth )
  plan_ids = ids( auth )[:result]
  get( auth, plan_ids )
end

.delete(auth, id) ⇒ Object



56
57
58
59
# File 'lib/ppc/api/qihu/plan.rb', line 56

def self.delete( auth, id )
  response = request( auth, Service, 'deleteById', { id: id } )
  process( response, 'affectedRecords' ){ |x|  x == '1'? 'success' : 'fail' }
end

.get(auth, ids) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/ppc/api/qihu/plan.rb', line 21

def self.get(auth, ids)
  '''
  :Type ids: ( Array of ) String or integer
  '''
  ids = to_json_string( ids )    
  body = {'idList' => ids}
  response = request( auth, Service, 'getInfoByIdList', body )
  process( response, 'campaignList' ){ |x| reverse_type(x) }
end

.ids(auth) ⇒ Object

move getCampaignId to plan module for operation call



32
33
34
35
# File 'lib/ppc/api/qihu/plan.rb', line 32

def self.ids( auth )
  response = request( auth, 'account', 'getCampaignIdList' )
  process( response, 'campaignIdList' ){ |x| to_id_list(x)}
end

.update(auth, plan) ⇒ Object



50
51
52
53
54
# File 'lib/ppc/api/qihu/plan.rb', line 50

def self.update( auth, plan ) 
  response = request( auth, Service, 'update', make_type( plan )[0])
  #同上,保证接口一致性
  process( response, 'id' ){ |x| [ { id:x.to_i } ] }
end