Class: PPC::API::Sogou::Keyword

Inherits:
PPC::API::Sogou show all
Defined in:
lib/ppc/api/sogou/keyword.rb

Constant Summary collapse

Service =
'Cpc'
Match_type =
{ 'exact' => 0, 'phrase' => 2, 'wide' => 1,'0' => 'exact', '2' => 'phrase', '1' => 'wide' }
KeywordType =
{
  id:                 :cpcId,
  group_id:           :cpcGrpId,
  keyword:            :cpc,
  price:              :price,
  pc_destination:     :visitUrl,
  mobile_destination: :mobileVisitUrl,
  match_type:         :matchType,
  pause:              :pause,
  status:             :status,
  quality:            :cpcQuality,
  "group_id" =>       :cpc_grp_id,
  "keyword_ids" =>    :cpc_ids,
  "keywords" =>       :cpc_types,
  "id" =>             :cpc_id,
  "pc_destination" => :visit_url,
  "quality" =>        :cpc_quality,
  "mobile_destination" => :mobile_visit_url,
}

Class Method Summary collapse

Methods inherited from PPC::API::Sogou

debug_print, process, request

Methods included from PPC::API

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

Class Method Details

.add(auth, keywords) ⇒ Object



64
65
66
67
68
# File 'lib/ppc/api/sogou/keyword.rb', line 64

def self.add( auth, keywords )
  body = { cpcTypes: make_type( keywords )  }
  response = request( auth, Service, "addCpc", body )
  process(response, 'cpcTypes'){|x| reverse_type(x)  }
end

.all(auth, ids) ⇒ Object



49
50
51
52
# File 'lib/ppc/api/sogou/keyword.rb', line 49

def self.all( auth, ids )
  response = request( auth, Service, "getCpcByCpcGrpId", {cpcGrpIds: ids} )
  process(response, 'cpcGrpCpcs'){|x| ids.count == 1 ? reverse_type(x[:cpc_types]) : x.map{|y| reverse_type(y[:cpc_types])}.flatten }
end

.delete(auth, ids) ⇒ Object



76
77
78
79
# File 'lib/ppc/api/sogou/keyword.rb', line 76

def self.delete( auth, ids )
  response = request( auth, Service, 'deleteCpc', {cpcIds: ids} )
  process(response, ''){|x| x }
end

.enable(auth, ids) ⇒ Object



81
82
83
84
# File 'lib/ppc/api/sogou/keyword.rb', line 81

def self.enable( auth, ids )
  keywords = ids.map{|id| {id: id, pause: false} }
  self.update( auth, keywords )
end

.get(auth, ids) ⇒ Object



59
60
61
62
# File 'lib/ppc/api/sogou/keyword.rb', line 59

def self.get( auth, ids )
  response = request( auth, Service, 'getCpcByCpcId', {cpcIds: ids} )
  process(response, 'cpcTypes'){|x| reverse_type( x ) }
end

.ids(auth, ids) ⇒ Object



54
55
56
57
# File 'lib/ppc/api/sogou/keyword.rb', line 54

def self.ids( auth, ids )
  response = request( auth, Service, "getCpcIdByCpcGrpId", {cpcGrpIds: ids} )
  process(response, 'cpcGrpCpcIds'){|x| reverse_type( x ) }
end

.info(auth, ids) ⇒ Object



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

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

.pause(auth, ids) ⇒ Object



86
87
88
89
# File 'lib/ppc/api/sogou/keyword.rb', line 86

def self.pause( auth, ids )
  keywords = ids.map{|id| {id: id, pause: true} }
  self.update( auth, keywords )
end

.quality(auth, ids) ⇒ Object



97
98
99
100
# File 'lib/ppc/api/sogou/keyword.rb', line 97

def self.quality( auth ,ids )
  response = request( auth, Service, 'getCpcByCpcId', {cpcIds: ids} )
  process(response, 'cpcTypes'){|x| reverse_type(x, @quality_map) }
end

.status(auth, ids) ⇒ Object

sogou的keyword服务不提供质量度和状态,从getInfo方法中查询



92
93
94
95
# File 'lib/ppc/api/sogou/keyword.rb', line 92

def self.status( auth, ids )
  response = request( auth, Service, 'getCpcByCpcId', {cpcIds: ids} )
  process(response, 'cpcTypes'){|x|  reverse_type(x, @status_map) }
end

.update(auth, keywords) ⇒ Object



70
71
72
73
74
# File 'lib/ppc/api/sogou/keyword.rb', line 70

def self.update( auth, keywords )
  body = { cpcTypes: make_type( keywords )  }
  response = request( auth, Service, "updateCpc", body )
  process(response, 'cpcTypes'){|x| reverse_type(x)  }
end