Class: PPC::API::Qihu::Group

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

Constant Summary collapse

Service =
'group'

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, group) ⇒ Object

奇虎组服务不提供批量add,delete和update方法



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

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

.all(auth) ⇒ Object



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

def self.all( auth )
  '''
  unimplemented due to ineffciency
  '''
  # unimplement
end

.delete(auth, id) ⇒ Object



69
70
71
72
# File 'lib/ppc/api/qihu/group.rb', line 69

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

.get(auth, ids) ⇒ Object



62
63
64
65
66
67
# File 'lib/ppc/api/qihu/group.rb', line 62

def self.get( auth, ids )
  ids = to_json_string( ids )
  body = { 'idList' => ids }
  response = request( auth, Service, 'getInfoByIdList', body  )
  process( response, 'groupList' ){ |x| reverse_type(x) }
end

.ids(auth) ⇒ Object

再次封装提供all和ids



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ppc/api/qihu/group.rb', line 20

def self.ids( auth )
  '''
  接口与其他的相同,但是无论如何:succ均为true,不返回任何错误信息
  因为是重复调用了search的接口,速度非常的慢,* 慎用 *
  '''
  plan_ids = ::PPC::API::Qihu::Plan::ids( auth )[:result]
  plan_group_ids = []

  plan_ids.each do |plan_id|
    plan_group_id = {}
    plan_group_id[:plan_id] = plan_id
    plan_group_id[:group_ids] = search_id_by_plan_id( auth, plan_id )[:result]
    plan_group_ids << plan_group_id
  end
  return { succ: true, failure:nil, result: plan_group_ids }
end

.search_by_plan_id(auth, id) ⇒ Object

combine searchIdbyId and get to provide another method



84
85
86
87
88
89
90
91
# File 'lib/ppc/api/qihu/group.rb', line 84

def self.search_by_plan_id( auth, id )
  group_ids = search_id_by_plan_id( auth, id )[:result][0][:group_ids]
  response = get( auth, group_ids )
  if response[:succ]
    response[:result] = [ { plan_id:id, groups:response[:result]}]
  end
  return response
end

.search_id_by_plan_id(auth, id) ⇒ Object



74
75
76
77
78
79
80
81
# File 'lib/ppc/api/qihu/group.rb', line 74

def self.search_id_by_plan_id( auth, id )
  response = request( auth, Service, 'getIdListByCampaignId', { 'campaignId' => id.to_s })
  #为了保持接口一致性,这里也是伪装成了百度的接口
  process( response, 'groupIdList' ){ 
    |x|
    [ { plan_id:id, group_ids: to_id_list(x) } ]
  }
end

.update(auth, group) ⇒ Object



51
52
53
54
55
56
57
58
59
60
# File 'lib/ppc/api/qihu/group.rb', line 51

def self.update( auth, group )
  if group[:negative] || group[:exact_negative]
    ng = {"exact" => group[:exact_negative], "phrase" => group[:negative]}.to_json
  end
  params = make_type(group)[0]
  params.merge!({:negativeWords => ng}) if ng
  response = request( auth, Service, 'update', params )
  # 保证接口一致性
  process( response, 'id' ){ |x|[ { id:x.to_i } ]  }
end