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

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

Constant Summary collapse

Service =
'campaign'
PlanType =
{
  id:                 :id,
  name:               :name,
  budget:             :budget,
  region:             :region,
  search_intention:   :searchIntention,
  schedule:           :schedule,
  start_date:         :startDate,
  end_date:           :endDate,
  status:             :sysStatus,
  pause:              :status,
  add_time:           :addTime,
  update_time:        :updateTime,
  price_ratio:        :mobilePriceRate,
  extend_adtype:      :extendAdType,
  "negative" =>       :negtiveWords,
  negative:           :negativeWords,
  "exact_negative" => :exactNegtiveWords,
  exact_negative:     :exactNegativeWords,
  device:             :device,
  is_precise:         :isPrecise,
}

Class Method Summary collapse

Methods inherited from PPC::API::Qihu

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

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



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

def self.add( auth, plan )
  plan[0][:negative] = {exact: plan[0].delete(:exact_negative), phrase: plan[0].delete(:negative)}.to_json if plan[0][:exact_negative] || plan[0][:negative]
  params = make_type(plan)[0]
  response = request( auth, Service, 'add', params )
  process( response, 'id' ){ |x| [ { id:x.to_i, name: plan[0][:name]} ] }
end

.all(auth) ⇒ Object

combine two original method to provice new method



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

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

.delete(auth, id) ⇒ Object



68
69
70
71
# File 'lib/ppc/api/qihu/plan.rb', line 68

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

.enable(auth, id) ⇒ Object



73
74
75
# File 'lib/ppc/api/qihu/plan.rb', line 73

def self.enable( auth, id )
  self.update(auth, [{id: id[0], pause: "enable"}])
end

.get(auth, ids) ⇒ Object



48
49
50
51
# File 'lib/ppc/api/qihu/plan.rb', line 48

def self.get(auth, ids)
  response = request( auth, Service, 'getInfoByIdList', {idList: ids} )
  process( response, 'campaignList' ){ |x| reverse_type(x) }
end

.ids(auth) ⇒ Object

move getCampaignId to plan module for operation call



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

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

.info(auth, ids) ⇒ Object



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

def self.info(auth, ids)
  response = request( auth, Service, 'getInfoByIdList', {idList: ids} )
  process( response, 'campaignList' ){ |x| reverse_type(x)[0] }
end

.pause(auth, id) ⇒ Object



77
78
79
# File 'lib/ppc/api/qihu/plan.rb', line 77

def self.pause( auth, id )
  self.update(auth, [{id: id[0], pause: "pause"}])
end

.update(auth, plan) ⇒ Object



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

def self.update( auth, plan )
  plan[0][:negative] = {exact: plan[0].delete(:exact_negative), phrase: plan[0].delete(:negative)}.to_json if plan[0][:exact_negative] || plan[0][:negative]
  params = make_type(plan)[0]
  response = request( auth, Service, 'update', params )
  process( response, 'id' ){ |x| [ { id:x.to_i } ] }
end