Class: PPC::API::Qihu::Group
Constant Summary
collapse
- Service =
'group'
- GroupType =
{
id: :id,
plan_id: :campaignId,
pause: :status,
name: :name,
price: :price,
negative: :negativeWords,
exact_negative: :exactNegativeWords,
add_time: :addTime,
update_time: :updateTime,
from_time: :fromTime,
}
Class Method Summary
collapse
process, request_http_body, request_http_header, request_uri
Methods included from PPC::API
#make_type, #process, #request, #request_http_body, #request_http_header, #request_uri, #reverse_type
Class Method Details
.add(auth, groups) ⇒ Object
43
44
45
46
47
|
# File 'lib/ppc/api/qihu/group.rb', line 43
def self.add( auth, groups )
groups.each{ |group| group[:negative] = {exact: group.delete(:exact_negative), phrase: group.delete(:negative)} if group[:exact_negative] || group[:negative] }
response = request( auth, Service, 'batchAdd', {groups: make_type( groups )} )
process( response, 'groupIdList' ){ |x| x.map.with_index{|id, index| {id: id, name: groups[index][:name]}} }
end
|
.all(auth, plan_id) ⇒ Object
28
29
30
31
|
# File 'lib/ppc/api/qihu/group.rb', line 28
def self.all( auth, plan_id )
group_ids = self.ids( auth, plan_id )[:result][:group_ids]
self.get( auth, group_ids )
end
|
.delete(auth, id) ⇒ Object
57
58
59
60
|
# File 'lib/ppc/api/qihu/group.rb', line 57
def self.delete( auth, id )
response = request( auth, Service, 'deleteById', {id: id[0]} )
process( response, 'affectedRecords' ){ |x| x == '1' }
end
|
.enable(auth, id) ⇒ Object
62
63
64
|
# File 'lib/ppc/api/qihu/group.rb', line 62
def self.enable( auth, id )
self.update(auth, [{id: id[0], pause: "enable"}])
end
|
.get(auth, ids) ⇒ Object
38
39
40
41
|
# File 'lib/ppc/api/qihu/group.rb', line 38
def self.get( auth, ids )
response = request( auth, Service, 'getInfoByIdList', { idList: ids } )
process( response, 'groupList' ){ |x| reverse_type(x) }
end
|
.ids(auth, plan_id) ⇒ Object
33
34
35
36
|
# File 'lib/ppc/api/qihu/group.rb', line 33
def self.ids( auth, plan_id )
response = request( auth, Service, 'getIdListByCampaignId', { campaignId: plan_id[0] } )
process( response, 'groupIdList' ){ |x| { plan_id: plan_id[0], group_ids: x.map(&:to_i) } }
end
|
.info(auth, ids) ⇒ Object
23
24
25
26
|
# File 'lib/ppc/api/qihu/group.rb', line 23
def self.info( auth, ids )
response = request( auth, Service, 'getInfoByIdList', { idList: ids } )
process( response, 'groupList' ){ |x| reverse_type(x)[0] }
end
|
.pause(auth, id) ⇒ Object
66
67
68
|
# File 'lib/ppc/api/qihu/group.rb', line 66
def self.pause( auth, id )
self.update(auth, [{id: id[0], pause: "pause"}])
end
|
.update(auth, group) ⇒ Object
奇虎组服务不提供批量delete和update方法
50
51
52
53
54
55
|
# File 'lib/ppc/api/qihu/group.rb', line 50
def self.update( auth, group )
group[0][:negative] = {exact: group[0].delete(:exact_negative), phrase: group[0].delete(:negative)}.to_json if group[0][:exact_negative] || group[0][:negative]
params = make_type(group)[0]
response = request( auth, Service, 'update', params )
process( response, 'id' ){ |x| [{id: x, name: group[0][:name]}] }
end
|