ppc 0.3.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.autotest +25 -0
- data/.gemtest +0 -0
- data/History.txt +6 -0
- data/Manifest.txt +8 -0
- data/README.txt +80 -0
- data/Rakefile +19 -0
- data/bin/ppc +3 -0
- data/lib/ppc.rb +6 -15
- data/test/test_ppc.rb +0 -0
- metadata +41 -130
- data/.gitignore +0 -37
- data/.rspec +0 -2
- data/LICENSE +0 -339
- data/README.md +0 -78
- data/lib/ppc/api.rb +0 -10
- data/lib/ppc/api/baidu.rb +0 -138
- data/lib/ppc/api/baidu/account.rb +0 -47
- data/lib/ppc/api/baidu/bulk.rb +0 -41
- data/lib/ppc/api/baidu/creative.rb +0 -125
- data/lib/ppc/api/baidu/group.rb +0 -111
- data/lib/ppc/api/baidu/keyword.rb +0 -204
- data/lib/ppc/api/baidu/plan.rb +0 -68
- data/lib/ppc/api/baidu/report.rb +0 -143
- data/lib/ppc/api/qihu.rb +0 -107
- data/lib/ppc/api/qihu/account.rb +0 -86
- data/lib/ppc/api/qihu/creative.rb +0 -106
- data/lib/ppc/api/qihu/group.rb +0 -113
- data/lib/ppc/api/qihu/keyword.rb +0 -111
- data/lib/ppc/api/qihu/plan.rb +0 -64
- data/lib/ppc/api/qihu/report.rb +0 -159
- data/lib/ppc/api/shenma.rb +0 -64
- data/lib/ppc/api/shenma/report.rb +0 -135
- data/lib/ppc/api/sogou.rb +0 -122
- data/lib/ppc/api/sogou/account.rb +0 -42
- data/lib/ppc/api/sogou/creative.rb +0 -117
- data/lib/ppc/api/sogou/group.rb +0 -116
- data/lib/ppc/api/sogou/keyword.rb +0 -182
- data/lib/ppc/api/sogou/plan.rb +0 -66
- data/lib/ppc/api/sogou/report.rb +0 -129
- data/lib/ppc/ext.rb +0 -9
- data/lib/ppc/operation.rb +0 -196
- data/lib/ppc/operation/account.rb +0 -53
- data/lib/ppc/operation/creative.rb +0 -28
- data/lib/ppc/operation/group.rb +0 -59
- data/lib/ppc/operation/keyword.rb +0 -32
- data/lib/ppc/operation/plan.rb +0 -47
- data/lib/ppc/operation/report.rb +0 -19
- data/ppc.gemspec +0 -26
- data/spec/baidu/api_baidu_account_spec.rb +0 -15
- data/spec/baidu/api_baidu_creative_spec.rb +0 -67
- data/spec/baidu/api_baidu_group_spec.rb +0 -45
- data/spec/baidu/api_baidu_keyword_spec.rb +0 -61
- data/spec/baidu/api_baidu_plan_spec.rb +0 -43
- data/spec/baidu/api_baidu_report_spec.rb +0 -44
- data/spec/baidu/api_baidu_spec.rb +0 -55
- data/spec/operation/operation_baidu_report_spec.rb +0 -17
- data/spec/operation/operation_baidu_spec.rb +0 -78
- data/spec/operation/operation_qihu_report_spec.rb +0 -18
- data/spec/operation/operation_qihu_spec.rb +0 -51
- data/spec/operation/operation_sogou_report_spec.rb +0 -17
- data/spec/operation/operation_sogou_spec.rb +0 -51
- data/spec/operation/operation_spec_helper.rb +0 -51
- data/spec/qihu/api_qihu_account_spec.rb +0 -25
- data/spec/qihu/api_qihu_creative_spec.rb +0 -48
- data/spec/qihu/api_qihu_group_spec.rb +0 -40
- data/spec/qihu/api_qihu_keyword_spec.rb +0 -50
- data/spec/qihu/api_qihu_plan_spec.rb +0 -39
- data/spec/qihu/api_qihu_report_spec.rb +0 -54
- data/spec/sogou/api_sogou_account_spec.rb +0 -15
- data/spec/sogou/api_sogou_creative_spec.rb +0 -48
- data/spec/sogou/api_sogou_group_spec.rb +0 -45
- data/spec/sogou/api_sogou_keyword_spec.rb +0 -50
- data/spec/sogou/api_sogou_plan_spec.rb +0 -39
- data/spec/sogou/api_sogou_report_spec.rb +0 -51
- data/spec/spec_helper.rb +0 -134
@@ -1,47 +0,0 @@
|
|
1
|
-
module PPC
|
2
|
-
module API
|
3
|
-
class Baidu
|
4
|
-
class Account< Baidu
|
5
|
-
Service = 'Account'
|
6
|
-
|
7
|
-
@map = [
|
8
|
-
[:id,:userid],
|
9
|
-
[:balance,:balance],
|
10
|
-
[:cost,:cost],
|
11
|
-
[:payment,:payment],
|
12
|
-
[:status,:userStat],
|
13
|
-
[:budget_type,:budgetType],
|
14
|
-
[:budget,:budget],
|
15
|
-
[:region,:regionTarget],
|
16
|
-
[:exclude_ip,:excludeIp],
|
17
|
-
[:isdynamic,:isDynamicCreative],
|
18
|
-
[:dynamic_param,:dynamicCreativeParam],
|
19
|
-
[:open_domains,:openDomains],
|
20
|
-
[:reg_domain,:regDomain],
|
21
|
-
[:offline_time,:budgetOfflineTime],
|
22
|
-
[:weekly_budget,:weeklyBudget],
|
23
|
-
[:opt,:opt]
|
24
|
-
]
|
25
|
-
|
26
|
-
def self.info( auth )
|
27
|
-
response = request(auth,Service,'getAccountInfo' )
|
28
|
-
return process( response, 'accountInfoType' ){ |x|reverse_type(x)[0] }
|
29
|
-
end
|
30
|
-
|
31
|
-
def self.update(auth, param = {} )
|
32
|
-
"""
|
33
|
-
update account info
|
34
|
-
@ params : account_info_type
|
35
|
-
@return : account info_type
|
36
|
-
"""
|
37
|
-
# for account service, there is not bulk operation
|
38
|
-
infoType = make_type( param )[0]
|
39
|
-
body = { accountInfoType: infoType }
|
40
|
-
response = request(auth,Service,'updateAccountInfo', body)
|
41
|
-
return process( response, 'accountInfoType' ){ |x|reverse_type(x)[0] }
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
data/lib/ppc/api/baidu/bulk.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
module PPC
|
2
|
-
module API
|
3
|
-
class Baidu
|
4
|
-
class Bulk < Baidu
|
5
|
-
Service = 'BulkJob'
|
6
|
-
|
7
|
-
def self.get_all_object( auth,params = {})
|
8
|
-
|
9
|
-
plan_ids = params[:plan_ids]
|
10
|
-
|
11
|
-
unless plan_ids.nil?
|
12
|
-
plan_ids = plan_ids.class == Array ? plan_ids : [plan_ids]
|
13
|
-
end
|
14
|
-
|
15
|
-
options = {
|
16
|
-
campaignIds: plan_ids || [] ,
|
17
|
-
includeQuality: params[:quality] || true ,
|
18
|
-
includeTemp: params[:temp] || false ,
|
19
|
-
format: params[:format] || 1 ,
|
20
|
-
newCreativeFiles: params[:adcopy] || 0 ,
|
21
|
-
includeTempNewCreatives: params[:temp_adcopy] || 0 ,
|
22
|
-
includePhraseType: params[:phrase] || 0 ,
|
23
|
-
extended: params[:extended] || 0
|
24
|
-
}
|
25
|
-
response = request( auth, Service, 'getAllObjects',options )
|
26
|
-
response[:get_all_objects_response][:file_id]
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.state( auth, id)
|
30
|
-
raise "empty id" if id.nil? or id.empty?
|
31
|
-
request(auth, Service, 'getFileState',{fileId:id})[:get_file_state_response][:is_generated]
|
32
|
-
end
|
33
|
-
|
34
|
-
def self.path( auth, id)
|
35
|
-
request( auth, Service, 'getFilePath',{fileId:id})[:get_file_path_response][:file_paths]
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,125 +0,0 @@
|
|
1
|
-
# -*- coding:utf-8 -*-
|
2
|
-
module PPC
|
3
|
-
module API
|
4
|
-
class Baidu
|
5
|
-
class Creative< Baidu
|
6
|
-
Service = 'Creative'
|
7
|
-
|
8
|
-
@map =[
|
9
|
-
[:id,:creativeId],
|
10
|
-
[:group_id,:adgroupId],
|
11
|
-
[:title,:title],
|
12
|
-
[:description1,:description1],
|
13
|
-
[:description2,:description2],
|
14
|
-
[:pc_destination,:pcDestinationUrl],
|
15
|
-
[:pc_display,:pcDisplayUrl],
|
16
|
-
[:moile_destination,:mobileDestinationUrl],
|
17
|
-
[:mobile_display,:mobileDisplayUrl],
|
18
|
-
[:pause,:pause],
|
19
|
-
[:preference,:devicePreference]
|
20
|
-
]
|
21
|
-
|
22
|
-
def self.add( auth, creatives )
|
23
|
-
body = { creativeTypes: make_type( creatives ) }
|
24
|
-
response = request( auth, Service, 'addCreative', body )
|
25
|
-
process( response, 'creativeTypes' ){ |x| reverse_type(x) }
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.get( auth, ids, getTemp = 0 )
|
29
|
-
'''
|
30
|
-
\'getCreativeByCreativeId\'
|
31
|
-
@ input : creative ids
|
32
|
-
@ output: creative informations
|
33
|
-
'''
|
34
|
-
ids = [ ids ] unless ids.is_a? Array
|
35
|
-
body = { creativeIds: ids, getTemp: getTemp }
|
36
|
-
response = request( auth, Service, 'getCreativeByCreativeId', body )
|
37
|
-
process( response, 'creativeTypes' ){ |x| reverse_type(x) }
|
38
|
-
end
|
39
|
-
|
40
|
-
def self.update( auth, creatives )
|
41
|
-
'''
|
42
|
-
根据实际使用情况,更新的时候creative title为必填选
|
43
|
-
'''
|
44
|
-
body = { creativeTypes: make_type( creatives ) }
|
45
|
-
response = request( auth, Service, 'updateCreative', body )
|
46
|
-
process( response, 'creativeTypes' ){ |x| reverse_type(x) }
|
47
|
-
end
|
48
|
-
|
49
|
-
def self.delete( auth, ids )
|
50
|
-
ids = [ ids ] unless ids.is_a? Array
|
51
|
-
body = { creativeIds: ids }
|
52
|
-
response = request( auth, Service, 'deleteCreative', body )
|
53
|
-
process( response, 'result' ){ |x| x }
|
54
|
-
end
|
55
|
-
|
56
|
-
def self.activate( auth, ids )
|
57
|
-
ids = [ ids ] unless ids.is_a? Array
|
58
|
-
body = { creativeIds: ids }
|
59
|
-
response = request( auth, Service, 'activateCreative', body )
|
60
|
-
process( response, 'creativeTypes' ){ |x| reverse_type(x) }
|
61
|
-
end
|
62
|
-
|
63
|
-
def self.status( auth, ids, type )
|
64
|
-
ids = [ ids ] unless ids.is_a? Array
|
65
|
-
|
66
|
-
type = case type
|
67
|
-
when 'plan' then 3
|
68
|
-
when 'group' then 5
|
69
|
-
when 'creative' then 7
|
70
|
-
else
|
71
|
-
Exception.new( 'type must among: \'plan\',\'group\' and \'key\' ')
|
72
|
-
end
|
73
|
-
|
74
|
-
body = { ids: ids, type: type }
|
75
|
-
response = request( auth, Service, 'getCreativeStatus', body )
|
76
|
-
process( response, 'CreativeStatus' ){ |x| x }
|
77
|
-
end
|
78
|
-
|
79
|
-
def self.search_id_by_group_id( auth, ids, getTemp = 0 )
|
80
|
-
'''
|
81
|
-
\'getCreativeIdByAdgroupId\'
|
82
|
-
@ input: group ids
|
83
|
-
@ output: groupCreativeIds
|
84
|
-
'''
|
85
|
-
ids = [ ids ] unless ids.is_a? Array
|
86
|
-
body = { adgroupIds: ids, getTemp: getTemp }
|
87
|
-
response = request( auth, Service, 'getCreativeIdByAdgroupId', body )
|
88
|
-
process( response, 'groupCreativeIds' ){ |x| make_groupCreativeIds( x ) }
|
89
|
-
end
|
90
|
-
|
91
|
-
def self.search_by_group_id( auth, ids, getTemp = 0 )
|
92
|
-
ids = [ ids ] unless ids.is_a? Array
|
93
|
-
body = { adgroupIds: ids, getTemp: getTemp }
|
94
|
-
response = request( auth, Service, 'getCreativeByAdgroupId', body )
|
95
|
-
process( response, 'groupCreatives' ){ |x| make_groupCreatives( x ) }
|
96
|
-
end
|
97
|
-
|
98
|
-
private
|
99
|
-
def self.make_groupCreativeIds( groupCreativeIds )
|
100
|
-
group_creative_ids = []
|
101
|
-
groupCreativeIds.each do |groupCreativeId|
|
102
|
-
group_creative_id = { }
|
103
|
-
group_creative_id[:group_id] = groupCreativeId['adgroupIds']
|
104
|
-
group_creative_id[:creative_ids] = groupCreativeId['creativeIds']
|
105
|
-
group_creative_ids << group_creative_id
|
106
|
-
end
|
107
|
-
return group_creative_ids
|
108
|
-
end
|
109
|
-
|
110
|
-
private
|
111
|
-
def self.make_groupCreatives( groupCreatives )
|
112
|
-
group_creatives = []
|
113
|
-
groupCreatives.each do |groupCreative |
|
114
|
-
group_creative = {}
|
115
|
-
group_creative[:group_id] = groupCreative['adgroupId']
|
116
|
-
group_creative[:creatives] = reverse_type( groupCreative['creativeTypes'] )
|
117
|
-
group_creatives << group_creative
|
118
|
-
end
|
119
|
-
return group_creatives
|
120
|
-
end
|
121
|
-
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
data/lib/ppc/api/baidu/group.rb
DELETED
@@ -1,111 +0,0 @@
|
|
1
|
-
# -*- coding:utf-8 -*-
|
2
|
-
module PPC
|
3
|
-
module API
|
4
|
-
class Baidu
|
5
|
-
class Group< Baidu
|
6
|
-
Service = 'Adgroup'
|
7
|
-
|
8
|
-
@map =[
|
9
|
-
[:plan_id, :campaignId],
|
10
|
-
[:id, :adgroupId],
|
11
|
-
[:name, :adgroupName],
|
12
|
-
[:price, :maxPrice],
|
13
|
-
[:negative, :negativeWords],
|
14
|
-
[:exact_negative, :exactNegativeWords],
|
15
|
-
[:pause, :pause],
|
16
|
-
[:status, :status],
|
17
|
-
[:reserved, :reserved]
|
18
|
-
]
|
19
|
-
|
20
|
-
def self.ids(auth )
|
21
|
-
"""
|
22
|
-
@return : Array of campaignAdgroupIds
|
23
|
-
"""
|
24
|
-
response = request( auth, Service , "getAllAdgroupId" )
|
25
|
-
process( response, 'campaignAdgroupIds' ){ |x| make_planGroupIds( x ) }
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.get( auth, ids )
|
29
|
-
ids = [ ids ] unless ids.is_a? Array
|
30
|
-
body = { adgroupIds: ids }
|
31
|
-
response = request(auth, Service, "getAdgroupByAdgroupId",body )
|
32
|
-
process( response, 'adgroupTypes' ){ |x| reverse_type(x) }
|
33
|
-
end
|
34
|
-
|
35
|
-
def self.add( auth, groups )
|
36
|
-
"""
|
37
|
-
@ input : one or list of AdgroupType
|
38
|
-
@ output : list of AdgroupType
|
39
|
-
"""
|
40
|
-
adgrouptypes = make_type( groups )
|
41
|
-
|
42
|
-
body = {adgroupTypes: adgrouptypes }
|
43
|
-
|
44
|
-
response = request( auth, Service, "addAdgroup", body )
|
45
|
-
process( response, 'adgroupTypes' ){ |x| reverse_type(x) }
|
46
|
-
end
|
47
|
-
|
48
|
-
def self.update( auth, groups )
|
49
|
-
"""
|
50
|
-
@ input : one or list of AdgroupType
|
51
|
-
@ output : list of AdgroupType
|
52
|
-
"""
|
53
|
-
adgrouptypes = make_type( groups )
|
54
|
-
body = {adgroupTypes: adgrouptypes}
|
55
|
-
|
56
|
-
response = request( auth, Service, "updateAdgroup",body )
|
57
|
-
process( response, 'adgroupTypes' ){ |x| reverse_type(x) }
|
58
|
-
end
|
59
|
-
|
60
|
-
def self.delete( auth, ids )
|
61
|
-
"""
|
62
|
-
delete group body has no message
|
63
|
-
"""
|
64
|
-
ids = [ ids ] unless ids.is_a? Array
|
65
|
-
body = { adgroupIds: ids }
|
66
|
-
response = request( auth, Service,"deleteAdgroup", body )
|
67
|
-
process( response, 'nil' ){ |x| x }
|
68
|
-
end
|
69
|
-
|
70
|
-
def self.search_by_plan_id( auth, ids )
|
71
|
-
ids = [ ids ] unless ids.class == Array
|
72
|
-
body = { campaignIds: ids }
|
73
|
-
response = request( auth, Service ,"getAdgroupByCampaignId", body )
|
74
|
-
process( response, 'campaignAdgroups' ){ |x| make_planGroups( x ) }
|
75
|
-
end
|
76
|
-
|
77
|
-
def self.search_id_by_plan_id( auth, ids )
|
78
|
-
ids = [ ids ] unless ids.class == Array
|
79
|
-
body = { campaignIds: ids }
|
80
|
-
response = request( auth, Service ,"getAdgroupIdByCampaignId", body )
|
81
|
-
process( response, 'campaignAdgroupIds' ){ |x| make_planGroupIds( x ) }
|
82
|
-
end
|
83
|
-
|
84
|
-
private
|
85
|
-
def self.make_planGroupIds( campaignAdgroupIds )
|
86
|
-
planGroupIds = []
|
87
|
-
campaignAdgroupIds.each do |campaignAdgroupId|
|
88
|
-
planGroupId = { }
|
89
|
-
planGroupId[:plan_id] = campaignAdgroupId['campaignId']
|
90
|
-
planGroupId[:group_ids] = campaignAdgroupId['adgroupIds']
|
91
|
-
planGroupIds << planGroupId
|
92
|
-
end
|
93
|
-
return planGroupIds
|
94
|
-
end
|
95
|
-
|
96
|
-
private
|
97
|
-
def self.make_planGroups( campaignAdgroups )
|
98
|
-
planGroups = []
|
99
|
-
campaignAdgroups.each do |campaignAdgroup|
|
100
|
-
planGroup = {}
|
101
|
-
planGroup[:plan_id] = campaignAdgroup['campaignId']
|
102
|
-
planGroup[:groups] = reverse_type( campaignAdgroup['adgroupTypes'] )
|
103
|
-
planGroups << planGroup
|
104
|
-
end
|
105
|
-
return planGroups
|
106
|
-
end
|
107
|
-
|
108
|
-
end # class group
|
109
|
-
end # class baidu
|
110
|
-
end # API
|
111
|
-
end # module
|
@@ -1,204 +0,0 @@
|
|
1
|
-
# -*- coding:utf-8 -*-
|
2
|
-
module PPC
|
3
|
-
module API
|
4
|
-
class Baidu
|
5
|
-
class Keyword< Baidu
|
6
|
-
Service = 'Keyword'
|
7
|
-
|
8
|
-
Match_type = { 'exact' => 1, 'pharse' => 2, 'wide' => 3,1 => 'exact', 2=> 'pharse' , 3 => 'wide' }
|
9
|
-
Device = { 'pc' => 0, 'mobile' => 1, 'all' => 2 }
|
10
|
-
Type = { 'plan' => 3, 'group' => 5, 'keyword' => 11 }
|
11
|
-
|
12
|
-
@map = [
|
13
|
-
[:id,:keywordId],
|
14
|
-
[:group_id,:adgroupId],
|
15
|
-
[:keyword,:keyword],
|
16
|
-
[:price,:price],
|
17
|
-
[:pc_destination,:pcDestinationUrl],
|
18
|
-
[:mobile_destination,:mobileDestinationUrl],
|
19
|
-
[:match_type,:matchType],
|
20
|
-
[:phrase_type,:phraseType],
|
21
|
-
[:status,:status],
|
22
|
-
[:pause,:pause]
|
23
|
-
]
|
24
|
-
|
25
|
-
@quality10_map = [
|
26
|
-
[ :id, :id ],
|
27
|
-
[ :group_id, :adgroupId ],
|
28
|
-
[ :plan_id, :Campaigned ],
|
29
|
-
[ :pc_quality, :pcQuality ],
|
30
|
-
[ :pc_reliable, :pcReliable ],
|
31
|
-
[ :pc_reason, :pcReason ],
|
32
|
-
[ :pc_scale, :pcScale ],
|
33
|
-
[ :mobile_quality, :mobileQuality ],
|
34
|
-
[ :mobile_reliable, :mobileReliable ],
|
35
|
-
[ :mobile_reason, :mobileReason ],
|
36
|
-
[ :mobile_scale, :mobileScale ]
|
37
|
-
]
|
38
|
-
|
39
|
-
# 后面改成info方法
|
40
|
-
def self.get( auth, ids )
|
41
|
-
'''
|
42
|
-
getKeywordByKeywordId
|
43
|
-
'''
|
44
|
-
ids = [ ids ] unless ids.is_a? Array
|
45
|
-
body = { keywordIds: ids}
|
46
|
-
response = request( auth, Service, 'getKeywordByKeywordId', body )
|
47
|
-
return process(response, 'keywordTypes' ){|x| reverse_type( x ) }
|
48
|
-
end
|
49
|
-
|
50
|
-
def self.add( auth, keywords )
|
51
|
-
'''
|
52
|
-
'''
|
53
|
-
keywordtypes = make_type( keywords )
|
54
|
-
body = { keywordTypes: keywordtypes }
|
55
|
-
response = request( auth, Service, "addKeyword", body )
|
56
|
-
return process(response, 'keywordTypes' ){|x| reverse_type(x) }
|
57
|
-
end
|
58
|
-
|
59
|
-
def self.update( auth, keywords )
|
60
|
-
'''
|
61
|
-
'''
|
62
|
-
keywordtypes = make_type( keywords )
|
63
|
-
body = { keywordTypes: keywordtypes }
|
64
|
-
response = request( auth, Service, "updateKeyword", body )
|
65
|
-
return process(response, 'keywordTypes' ){|x| reverse_type(x) }
|
66
|
-
end
|
67
|
-
|
68
|
-
def self.delete( auth, ids )
|
69
|
-
"""
|
70
|
-
"""
|
71
|
-
ids = [ ids ] unless ids.is_a? Array
|
72
|
-
body = { keywordIds: ids}
|
73
|
-
response = request( auth, Service, 'deleteKeyword', body )
|
74
|
-
return process(response, 'result' ){|x| x }
|
75
|
-
end
|
76
|
-
|
77
|
-
def self.activate( auth, ids )
|
78
|
-
"""
|
79
|
-
"""
|
80
|
-
ids = [ ids ] unless ids.is_a? Array
|
81
|
-
body = { keywordIds: ids }
|
82
|
-
response = request( auth, Service, 'activateKeyword', body)
|
83
|
-
return process(response, 'keywordTypes' ){|x| reverse_type(x) }
|
84
|
-
end
|
85
|
-
|
86
|
-
def self.search_by_group_id( auth, group_ids )
|
87
|
-
"""
|
88
|
-
getKeywordByGroupIds
|
89
|
-
@input: list of group id
|
90
|
-
@output: list of groupKeyword
|
91
|
-
"""
|
92
|
-
group_ids = [ group_ids ] unless group_ids.is_a? Array
|
93
|
-
body = { adgroupIds: group_ids }
|
94
|
-
response = request( auth, Service, "getKeywordByAdgroupId", body )
|
95
|
-
return process(response, 'groupKeywords' ){|x| make_groupKeywords( x ) }
|
96
|
-
end
|
97
|
-
|
98
|
-
def self.search_id_by_group_id( auth, group_ids )
|
99
|
-
group_ids = [ group_ids ] unless group_ids.is_a? Array
|
100
|
-
body = { adgroupIds: group_ids }
|
101
|
-
response = request( auth, Service, "getKeywordIdByAdgroupId", body )
|
102
|
-
return process(response, 'groupKeywordIds' ){|x| make_groupKeywordIds( x ) }
|
103
|
-
end
|
104
|
-
|
105
|
-
# 下面三个操作操作对象包括计划,组和关键字
|
106
|
-
# 不知道放在这里合不合适
|
107
|
-
def self.status( auth, ids, type )
|
108
|
-
'''
|
109
|
-
Return [{ id: id, status: status } ... ]
|
110
|
-
'''
|
111
|
-
ids = [ ids ] unless ids.is_a? Array
|
112
|
-
body = { ids: ids, type: Type[type]}
|
113
|
-
response = request( auth, Service, 'getKeywordStatus', body )
|
114
|
-
return process(response, 'keywordStatus' ){ |statusTypes|
|
115
|
-
statusTypes = [statusTypes] unless statusTypes.is_a? Array
|
116
|
-
status =[]
|
117
|
-
|
118
|
-
statusTypes.each do |statusType|
|
119
|
-
status << { id: statusType['id'], status: statusType['status'] }
|
120
|
-
end
|
121
|
-
return status
|
122
|
-
}
|
123
|
-
end
|
124
|
-
|
125
|
-
def self.quality( auth ,ids, type, device )
|
126
|
-
'''
|
127
|
-
Return 10Quanlity *Not the old Quality* of given ketword id
|
128
|
-
'''
|
129
|
-
ids = [ ids ] unless ids.is_a? Array
|
130
|
-
body = { ids: ids, type: Type[type], device:Device[device] }
|
131
|
-
response = request( auth, Service, 'getKeyword10Quality', body )
|
132
|
-
return process(response, 'keyword10Quality' ){|x| reverse_type( x, @quality10_map ) }
|
133
|
-
end
|
134
|
-
|
135
|
-
private
|
136
|
-
def self.make_groupKeywordIds( groupKeywordIds )
|
137
|
-
group_keyword_ids = []
|
138
|
-
groupKeywordIds.each do |groupKeywordId|
|
139
|
-
group_keyword_id = { }
|
140
|
-
group_keyword_id[:group_id] = groupKeywordId['adgroupIds']
|
141
|
-
group_keyword_id[:keyword_ids] = groupKeywordId['keywordIds']
|
142
|
-
group_keyword_ids << group_keyword_id
|
143
|
-
end
|
144
|
-
return group_keyword_ids
|
145
|
-
end
|
146
|
-
|
147
|
-
private
|
148
|
-
def self.make_groupKeywords( groupKeywords )
|
149
|
-
group_keywords = []
|
150
|
-
groupKeywords.each do |groupKeyword|
|
151
|
-
group_keyword = {}
|
152
|
-
group_keyword[:group_id] = groupKeyword['adgroupId']
|
153
|
-
group_keyword[:keywords] = reverse_type( groupKeyword['keywordTypes'] )
|
154
|
-
group_keywords << group_keyword
|
155
|
-
end
|
156
|
-
return group_keywords
|
157
|
-
end
|
158
|
-
|
159
|
-
# Override
|
160
|
-
def self.make_type( params, map = @map)
|
161
|
-
params = [ params ] unless params.is_a? Array
|
162
|
-
types = []
|
163
|
-
params.each do |param|
|
164
|
-
type = {}
|
165
|
-
map.each do |key|
|
166
|
-
# 增加对matchtype的自动转换
|
167
|
-
if key[0] == :match_type
|
168
|
-
value = param[ key[0] ]
|
169
|
-
type[ key[1] ] = Match_type[ value ] if value
|
170
|
-
else
|
171
|
-
value = param[ key[0] ]
|
172
|
-
type[ key[1] ] = value if value
|
173
|
-
end
|
174
|
-
end
|
175
|
-
types << type
|
176
|
-
end
|
177
|
-
return types
|
178
|
-
end
|
179
|
-
|
180
|
-
# Overwrite
|
181
|
-
def self.reverse_type( types, map = @map )
|
182
|
-
types = [ types ] unless types.is_a? Array
|
183
|
-
params = []
|
184
|
-
types.each do |type|
|
185
|
-
param = {}
|
186
|
-
# 增加对matchtype的自动转换
|
187
|
-
map.each do |key|
|
188
|
-
if key[0] == :match_type
|
189
|
-
value = type[ key[1].to_s ]
|
190
|
-
param[ key[0] ] = Match_type[ value ] if value
|
191
|
-
else
|
192
|
-
value = type[ key[1].to_s ]
|
193
|
-
param[ key[0] ] = value if value
|
194
|
-
end
|
195
|
-
end # map.each
|
196
|
-
params << param
|
197
|
-
end # types.each
|
198
|
-
return params
|
199
|
-
end
|
200
|
-
|
201
|
-
end # keyword
|
202
|
-
end # Baidu
|
203
|
-
end # API
|
204
|
-
end # PPC
|