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
data/lib/ppc/api/sogou/group.rb
DELETED
@@ -1,116 +0,0 @@
|
|
1
|
-
# -*- coding:utf-8 -*-
|
2
|
-
module PPC
|
3
|
-
module API
|
4
|
-
class Sogou
|
5
|
-
class Group< Sogou
|
6
|
-
Service = 'CpcGrp'
|
7
|
-
|
8
|
-
@map =[
|
9
|
-
[:plan_id, :cpcPlanId],
|
10
|
-
[:id, :cpcGrpId],
|
11
|
-
[:name, :cpcGrpName],
|
12
|
-
[:price, :maxPrice],
|
13
|
-
[:negative, :negativeWords],
|
14
|
-
[:exact_negative, :exactNegativeWords],
|
15
|
-
[:pause, :pause],
|
16
|
-
[:status, :status],
|
17
|
-
[:opt, :opt]
|
18
|
-
]
|
19
|
-
|
20
|
-
def self.ids(auth, debug = false )
|
21
|
-
"""
|
22
|
-
@return : Array of cpcPlanGrpIdTypes
|
23
|
-
"""
|
24
|
-
response = request( auth, Service , "getAllCpcGrpId" )
|
25
|
-
#此处返回值与key与开发文档不同
|
26
|
-
process( response, 'cpcPlanGrpIds', debug ){ |x| make_planGroupIds( x ) }
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.get( auth, ids, debug = false )
|
30
|
-
ids = [ ids ] unless ids.is_a? Array
|
31
|
-
body = { cpcGrpIds: ids }
|
32
|
-
response = request(auth, Service, "getCpcGrpByCpcGrpId",body )
|
33
|
-
process( response, 'cpcGrpTypes', debug ){ |x| reverse_type(x) }
|
34
|
-
end
|
35
|
-
|
36
|
-
def self.add( auth, groups, debug = false )
|
37
|
-
"""
|
38
|
-
@ input : one or list of AdgroupType
|
39
|
-
@ output : list of AdgroupType
|
40
|
-
"""
|
41
|
-
cpcGrpTypes = make_type( groups )
|
42
|
-
|
43
|
-
body = {cpcGrpTypes: cpcGrpTypes }
|
44
|
-
|
45
|
-
response = request( auth, Service, "addCpcGrp", body )
|
46
|
-
process( response, 'cpcGrpTypes', debug ){ |x| reverse_type(x) }
|
47
|
-
end
|
48
|
-
|
49
|
-
def self.update( auth, groups, debug = false )
|
50
|
-
"""
|
51
|
-
@ input : one or list of AdgroupType
|
52
|
-
@ output : list of AdgroupType
|
53
|
-
"""
|
54
|
-
cpcGrpTypes = make_type( groups )
|
55
|
-
body = {cpcGrpTypes: cpcGrpTypes}
|
56
|
-
|
57
|
-
response = request( auth, Service, "updateCpcGrp",body )
|
58
|
-
process( response, 'cpcGrpTypes', debug ){ |x| reverse_type(x) }
|
59
|
-
end
|
60
|
-
|
61
|
-
def self.delete( auth, ids, debug = false )
|
62
|
-
"""
|
63
|
-
delete group body has no message
|
64
|
-
"""
|
65
|
-
ids = [ ids ] unless ids.is_a? Array
|
66
|
-
body = { cpcGrpIds: ids }
|
67
|
-
response = request( auth, Service,"deleteCpcGrp", body )
|
68
|
-
process( response, 'nil', debug ){ |x| x }
|
69
|
-
end
|
70
|
-
|
71
|
-
def self.search_by_plan_id( auth, ids, debug = false )
|
72
|
-
ids = [ ids ] unless ids.is_a? Array
|
73
|
-
body = { cpcPlanIds: ids }
|
74
|
-
response = request( auth, Service ,"getCpcGrpByCpcPlanId", body )
|
75
|
-
# 此处key与开发文档不同
|
76
|
-
process( response, 'cpcPlanGrps', debug ){ |x| make_planGroups( x ) }
|
77
|
-
end
|
78
|
-
|
79
|
-
def self.search_id_by_plan_id( auth, ids, debug = false )
|
80
|
-
ids = [ ids ] unless ids.is_a? Array
|
81
|
-
body = { cpcPlanIds: ids }
|
82
|
-
response = request( auth, Service ,"getCpcGrpIdByCpcPlanId", body )
|
83
|
-
process( response, 'cpcPlanGrpIds', debug ){ |x| make_planGroupIds( x ) }
|
84
|
-
end
|
85
|
-
|
86
|
-
private
|
87
|
-
def self.make_planGroupIds( cpcPlanGrpIdTypes )
|
88
|
-
cpcPlanGrpIdTypes = [cpcPlanGrpIdTypes] unless cpcPlanGrpIdTypes.is_a? Array
|
89
|
-
planGroupIds = []
|
90
|
-
cpcPlanGrpIdTypes.each do |cpcPlanGrpIdType|
|
91
|
-
planGroupId = { }
|
92
|
-
planGroupId[:plan_id] = cpcPlanGrpIdType[:cpc_plan_id]
|
93
|
-
planGroupId[:group_ids] = cpcPlanGrpIdType[:cpc_grp_ids]
|
94
|
-
planGroupIds << planGroupId
|
95
|
-
end
|
96
|
-
return planGroupIds
|
97
|
-
end
|
98
|
-
|
99
|
-
private
|
100
|
-
def self.make_planGroups( cpcPlanGrpTypes )
|
101
|
-
# 多加一行change成array
|
102
|
-
cpcPlanGrpTypes = [cpcPlanGrpTypes] unless cpcPlanGrpTypes.is_a? Array
|
103
|
-
planGroups = []
|
104
|
-
cpcPlanGrpTypes.each do |cpcPlanGrpType|
|
105
|
-
planGroup = {}
|
106
|
-
planGroup[:plan_id] = cpcPlanGrpType[:cpc_plan_id]
|
107
|
-
planGroup[:groups] = reverse_type( cpcPlanGrpType[:cpc_grp_types] )
|
108
|
-
planGroups << planGroup
|
109
|
-
end
|
110
|
-
return planGroups
|
111
|
-
end
|
112
|
-
|
113
|
-
end # class group
|
114
|
-
end # class baidu
|
115
|
-
end # API
|
116
|
-
end # module
|
@@ -1,182 +0,0 @@
|
|
1
|
-
# -*- coding:utf-8 -*-
|
2
|
-
module PPC
|
3
|
-
module API
|
4
|
-
class Sogou
|
5
|
-
class Keyword< Sogou
|
6
|
-
Service = 'Cpc'
|
7
|
-
|
8
|
-
Match_type = { 'exact' => 0, 'wide' => 1,0 => 'exact', 1 => 'wide' }
|
9
|
-
|
10
|
-
@map = [
|
11
|
-
[:id,:cpcId],
|
12
|
-
[:group_id,:cpcGrpId],
|
13
|
-
[:keyword,:cpc],
|
14
|
-
[:price,:price],
|
15
|
-
[:pc_destination,:visitUrl],
|
16
|
-
[:mobile_destination,:mobileVisitUrl],
|
17
|
-
[:match_type,:matchType],
|
18
|
-
[:pause,:pause],
|
19
|
-
[:status,:status],
|
20
|
-
[:quality,:cpcQuality]
|
21
|
-
]
|
22
|
-
@quality_map = [
|
23
|
-
[:id,:cpcId],
|
24
|
-
[:quality,:cpcQuality]
|
25
|
-
]
|
26
|
-
|
27
|
-
@status_map = [
|
28
|
-
[:id,:cpcId],
|
29
|
-
[:status,:status]
|
30
|
-
]
|
31
|
-
|
32
|
-
# 后面改成info方法
|
33
|
-
def self.get( auth, ids, debug = false )
|
34
|
-
'''
|
35
|
-
getCpcByCpcId
|
36
|
-
'''
|
37
|
-
ids = [ ids ] unless ids.is_a? Array
|
38
|
-
body = { cpcIds: ids}
|
39
|
-
response = request( auth, Service, 'getCpcByCpcId', body )
|
40
|
-
process(response, 'cpcTypes', debug){|x| reverse_type( x ) }
|
41
|
-
end
|
42
|
-
|
43
|
-
def self.add( auth, keywords, debug = false )
|
44
|
-
'''
|
45
|
-
'''
|
46
|
-
cpcTypes = make_type( keywords )
|
47
|
-
body = { cpcTypes: cpcTypes }
|
48
|
-
response = request( auth, Service, "addCpc", body )
|
49
|
-
process(response, 'cpcTypes', debug){|x| reverse_type(x) }
|
50
|
-
end
|
51
|
-
|
52
|
-
def self.update( auth, keywords, debug = false )
|
53
|
-
'''
|
54
|
-
'''
|
55
|
-
cpcTypes = make_type( keywords )
|
56
|
-
body = { cpcTypes: cpcTypes }
|
57
|
-
response = request( auth, Service, "updateCpc", body )
|
58
|
-
process(response, 'cpcTypes', debug){|x| reverse_type(x) }
|
59
|
-
end
|
60
|
-
|
61
|
-
def self.delete( auth, ids, debug = false )
|
62
|
-
"""
|
63
|
-
"""
|
64
|
-
ids = [ ids ] unless ids.is_a? Array
|
65
|
-
body = { cpcIds: ids}
|
66
|
-
response = request( auth, Service, 'deleteCpc', body )
|
67
|
-
process(response, 'nil', debug){|x| x }
|
68
|
-
end
|
69
|
-
|
70
|
-
def self.search_by_group_id( auth, group_ids, debug = false )
|
71
|
-
"""
|
72
|
-
getKeywordByGroupIds
|
73
|
-
@input: list of group id
|
74
|
-
@output: list of groupKeyword
|
75
|
-
"""
|
76
|
-
group_ids = [ group_ids ] unless group_ids.is_a? Array
|
77
|
-
body = { cpcGrpIds: group_ids }
|
78
|
-
response = request( auth, Service, "getCpcByCpcGrpId", body )
|
79
|
-
process(response, 'cpcGrpCpcs', debug){|x| make_groupKeywords( x ) }
|
80
|
-
end
|
81
|
-
|
82
|
-
def self.search_id_by_group_id( auth, group_ids, debug = false )
|
83
|
-
group_ids = [ group_ids ] unless group_ids.is_a? Array
|
84
|
-
body = { cpcGrpIds: group_ids }
|
85
|
-
response = request( auth, Service, "getCpcIdByCpcGrpId", body )
|
86
|
-
process(response, 'cpcGrpCpcIds', debug){|x| make_groupKeywordIds( x ) }
|
87
|
-
end
|
88
|
-
|
89
|
-
# sogou的keyword服务不提供质量度
|
90
|
-
def self.status( auth, ids, debug = false )
|
91
|
-
'''
|
92
|
-
Return [ { id: id, status: status} ... ]
|
93
|
-
'''
|
94
|
-
ids = [ ids ] unless ids.is_a? Array
|
95
|
-
body = { cpcIds: ids}
|
96
|
-
response = request( auth, Service, 'getCpcByCpcId', body )
|
97
|
-
|
98
|
-
process(response, 'cpcTypes', debug){ |x| reverse_type(x, @status_map) }
|
99
|
-
end
|
100
|
-
|
101
|
-
def self.quality( auth ,ids, debug = false )
|
102
|
-
'''
|
103
|
-
Return [ { id: id, quality: quality} ... ]
|
104
|
-
'''
|
105
|
-
ids = [ ids ] unless ids.is_a? Array
|
106
|
-
body = { cpcIds: ids}
|
107
|
-
response = request( auth, Service, 'getCpcByCpcId', { cpcIds: ids} )
|
108
|
-
process(response, 'cpcTypes', debug){ |x| reverse_type(x, @quality_map) }
|
109
|
-
end
|
110
|
-
|
111
|
-
private
|
112
|
-
def self.make_groupKeywordIds( cpcGrpCpcIdTypes )
|
113
|
-
cpcGrpCpcIdTypes = [cpcGrpCpcIdTypes] unless cpcGrpCpcIdTypes.is_a? Array
|
114
|
-
group_keyword_ids = []
|
115
|
-
cpcGrpCpcIdTypes.each do |cpcGrpCpcIdType|
|
116
|
-
group_keyword_id = { }
|
117
|
-
group_keyword_id[:group_id] = cpcGrpCpcIdType[:cpc_grp_id]
|
118
|
-
group_keyword_id[:keyword_ids] = cpcGrpCpcIdType[:cpc_ids]
|
119
|
-
group_keyword_ids << group_keyword_id
|
120
|
-
end
|
121
|
-
return group_keyword_ids
|
122
|
-
end
|
123
|
-
|
124
|
-
private
|
125
|
-
def self.make_groupKeywords( cpcGrpCpcTypes )
|
126
|
-
cpcGrpCpcTypes = [cpcGrpCpcTypes] unless cpcGrpCpcTypes.is_a? Array
|
127
|
-
group_keywords = []
|
128
|
-
cpcGrpCpcTypes.each do |cpcGrpCpcType|
|
129
|
-
group_keyword = {}
|
130
|
-
group_keyword[:group_id] = cpcGrpCpcType[:cpc_grp_id]
|
131
|
-
group_keyword[:keywords] = reverse_type( cpcGrpCpcType[:cpc_types] )
|
132
|
-
group_keywords << group_keyword
|
133
|
-
end
|
134
|
-
return group_keywords
|
135
|
-
end
|
136
|
-
|
137
|
-
# Override
|
138
|
-
def self.make_type( params, map = @map)
|
139
|
-
params = [ params ] unless params.is_a? Array
|
140
|
-
types = []
|
141
|
-
params.each do |param|
|
142
|
-
type = {}
|
143
|
-
map.each do |key|
|
144
|
-
# 增加对matchtype的自动转换
|
145
|
-
if key[0] == :match_type
|
146
|
-
value = param[ key[0] ]
|
147
|
-
type[ key[1] ] = Match_type[ value ] if value
|
148
|
-
else
|
149
|
-
value = param[ key[0] ]
|
150
|
-
type[ key[1] ] = value if value != nil
|
151
|
-
end
|
152
|
-
end
|
153
|
-
types << type
|
154
|
-
end
|
155
|
-
return types
|
156
|
-
end
|
157
|
-
|
158
|
-
# Overwrite
|
159
|
-
def self.reverse_type( types, map = @map )
|
160
|
-
types = [ types ] unless types.is_a? Array
|
161
|
-
params = []
|
162
|
-
types.each do |type|
|
163
|
-
param = {}
|
164
|
-
# 增加对matchtype的自动转换
|
165
|
-
map.each do |key|
|
166
|
-
if key[0] == :match_type
|
167
|
-
value = type[ key[1].to_s.snake_case.to_sym]
|
168
|
-
param[ key[0] ] = Match_type[ value ] if value
|
169
|
-
else
|
170
|
-
value = type[ key[1].to_s.snake_case.to_sym ]
|
171
|
-
param[ key[0] ] = value if value != nil
|
172
|
-
end
|
173
|
-
end # map.each
|
174
|
-
params << param
|
175
|
-
end # types.each
|
176
|
-
return params
|
177
|
-
end
|
178
|
-
|
179
|
-
end # keyword
|
180
|
-
end # Baidu
|
181
|
-
end # API
|
182
|
-
end # PPC
|
data/lib/ppc/api/sogou/plan.rb
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
module PPC
|
2
|
-
module API
|
3
|
-
class Sogou
|
4
|
-
class Plan< Sogou
|
5
|
-
Service = 'CpcPlan'
|
6
|
-
|
7
|
-
@map = [
|
8
|
-
[:id,:cpcPlanId],
|
9
|
-
[:name,:cpcPlanName],
|
10
|
-
[:budget,:budget],
|
11
|
-
[:region,:regions],
|
12
|
-
[:ip,:excludeIps] ,
|
13
|
-
[:negative,:negativeWords],
|
14
|
-
[:exact_negative,:exactNegativeWords],
|
15
|
-
[:schedule,:schedule],
|
16
|
-
[:budget_offline_time,:budgetOfflineTime],
|
17
|
-
[:show_prob,:showProb],
|
18
|
-
[:join_union ,:joinUnion],
|
19
|
-
[:device,:device],
|
20
|
-
[:price_ratio,:mobilePriceRate ],
|
21
|
-
[:pause,:pause],
|
22
|
-
[:status,:status],
|
23
|
-
]
|
24
|
-
|
25
|
-
def self.all( auth, debug = false )
|
26
|
-
response = request( auth, Service, 'getAllCpcPlan' )
|
27
|
-
process( response, 'cpcPlanTypes' , debug ){ |x| reverse_type(x) }
|
28
|
-
end
|
29
|
-
|
30
|
-
def self.ids( auth, debug = false )
|
31
|
-
response = request( auth, Service, 'getAllCpcPlanId' )
|
32
|
-
process( response, 'cpcPlanIds' , debug ){ |x| x }
|
33
|
-
end
|
34
|
-
|
35
|
-
def self.get( auth, ids, debug = false )
|
36
|
-
ids = [ ids ] unless ids.is_a? Array
|
37
|
-
body = { cpcPlanIds: ids }
|
38
|
-
response = request( auth, Service, 'getCpcPlanByCpcPlanId', body)
|
39
|
-
process( response, 'cpcPlanTypes' , debug ){ |x| reverse_type(x) }
|
40
|
-
end
|
41
|
-
|
42
|
-
def self.add( auth, plans, debug = false )
|
43
|
-
cpcPlanTypes = make_type( plans )
|
44
|
-
body = { cpcPlanTypes: cpcPlanTypes }
|
45
|
-
response = request( auth, Service, 'addCpcPlan', body)
|
46
|
-
process( response, 'cpcPlanTypes' , debug ){ |x| reverse_type(x) }
|
47
|
-
end
|
48
|
-
|
49
|
-
def self.update(auth,plans, debug = false )
|
50
|
-
cpcPlanTypes = make_type( plans )
|
51
|
-
body = { cpcPlanTypes: cpcPlanTypes }
|
52
|
-
response = request( auth, Service, 'updateCpcPlan', body)
|
53
|
-
process( response, 'cpcPlanTypes' , debug ){ |x| reverse_type(x) }
|
54
|
-
end
|
55
|
-
|
56
|
-
def self.delete(auth, ids, debug = false )
|
57
|
-
ids = [ ids ] unless ids.class == Array
|
58
|
-
body = { cpcPlanIds: ids }
|
59
|
-
response = request( auth, Service, 'deleteCpcPlan', body)
|
60
|
-
process( response, '' , debug ){ |x| x }
|
61
|
-
end
|
62
|
-
|
63
|
-
end # Service
|
64
|
-
end # baidu
|
65
|
-
end # API
|
66
|
-
end # PPC
|
data/lib/ppc/api/sogou/report.rb
DELETED
@@ -1,129 +0,0 @@
|
|
1
|
-
# -*- coding:utf-8 -*-
|
2
|
-
module PPC
|
3
|
-
module API
|
4
|
-
class Sogou
|
5
|
-
class Report< Sogou
|
6
|
-
Service = 'Report'
|
7
|
-
|
8
|
-
# 需要用到的映射集合
|
9
|
-
Type_map = { 'account' => 1, 'plan'=> 2, 'group'=> 3,
|
10
|
-
'keyword'=> 5, 'creative'=> 4, 'pair'=> 15,
|
11
|
-
'query'=> 3 }
|
12
|
-
|
13
|
-
Range_map = { 'account' => 1, 'plan' => 2, 'group' => 3,
|
14
|
-
'creative' => 4, 'keyword' => 5 }
|
15
|
-
|
16
|
-
Device_map = { 'all' => 0, 'pc' => 1, 'mobile' => 2 }
|
17
|
-
|
18
|
-
Unit_map = { 'day' => 1, 'week' => 2, 'month' => 3 }
|
19
|
-
|
20
|
-
def self.get_id( auth, params, debug = false )
|
21
|
-
request = make_reportrequest( params )
|
22
|
-
body = { reportRequestType: request }
|
23
|
-
response = request( auth, Service, 'getReportId' ,body)
|
24
|
-
process( response, 'reportId', debug ){ |x| x }
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.get_state( auth, id, debug = false)
|
28
|
-
'''
|
29
|
-
input id should be string
|
30
|
-
'''
|
31
|
-
status = {'-1'=>'Waiting' ,'0'=>'Opearting' ,'1'=>'Finished'}
|
32
|
-
body = { reportId: id }
|
33
|
-
response = request( auth, Service, 'getReportState' ,body)
|
34
|
-
process( response, 'isGenerated', debug ){ |x| status[x] }
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.get_url( auth, id, debug = false )
|
38
|
-
body = { reportId: id }
|
39
|
-
response = request( auth, Service, 'getReportPath' ,body)
|
40
|
-
process( response, 'reportFilePath', debug ){ |x| x }
|
41
|
-
end
|
42
|
-
|
43
|
-
private
|
44
|
-
def self.make_reportrequest( param )
|
45
|
-
'''
|
46
|
-
make RepoerRequestType
|
47
|
-
======================
|
48
|
-
For more docs please have a look at
|
49
|
-
::PPC::API::Baidu::Report:make_reportrequest()
|
50
|
-
'''
|
51
|
-
requesttype = {}
|
52
|
-
requesttype[:performanceData] = param[:fields] || %w(click)
|
53
|
-
requesttype[:reportType] = Type_map[ param[:type] ] if param[:type]
|
54
|
-
requesttype[:statRange] = Range_map[ param[:range] ] if param[:range]
|
55
|
-
requesttype[:unitOfTime] = Unit_map[ param[:unit] ] if param[:unit]
|
56
|
-
requesttype[:platform] = Device_map[ param[:device] ] if param[:device]
|
57
|
-
requesttype[:idOnly] = param[:id_only] if param[:id_only]!=nil
|
58
|
-
requesttype[:startDate] = parse_date( param[:startDate] )
|
59
|
-
requesttype[:endDate] = parse_date( param[:endDate] )
|
60
|
-
return requesttype
|
61
|
-
end
|
62
|
-
|
63
|
-
private
|
64
|
-
def self.parse_date( date )
|
65
|
-
"""
|
66
|
-
Cast string to time:
|
67
|
-
'YYYYMMDD' => Time
|
68
|
-
"""
|
69
|
-
if date
|
70
|
-
y = date[0..3]
|
71
|
-
m = date[4..5]
|
72
|
-
d = date[6..7]
|
73
|
-
date = Time.new( y, m, d )
|
74
|
-
else
|
75
|
-
date = (Time.now - 24*3600)
|
76
|
-
end
|
77
|
-
date.utc.iso8601
|
78
|
-
end
|
79
|
-
|
80
|
-
###########################
|
81
|
-
# intreface for Operation #
|
82
|
-
###########################
|
83
|
-
def self.download_report( auth, param, debug = false )
|
84
|
-
response = get_id( auth, param )
|
85
|
-
if response[:succ]
|
86
|
-
id = response[:result]
|
87
|
-
p "Got report id:" + id.to_s if debug
|
88
|
-
loop do
|
89
|
-
sleep 2
|
90
|
-
break if get_state( auth, id )[:result] == 'Finished'
|
91
|
-
p "Report is not generated, waiting..." if debug
|
92
|
-
end
|
93
|
-
|
94
|
-
url = get_url( auth, id )[:result]
|
95
|
-
ActiveSupport::Gzip.decompress( open(url).read )
|
96
|
-
else
|
97
|
-
raise response[:failure][:message]
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
def self.query_report( auth, param = nil, debug = false )
|
102
|
-
param = {} if not param
|
103
|
-
param[:type] ||= 'query'
|
104
|
-
param[:fields] ||= %w(click)
|
105
|
-
param[:range] ||= 'account'
|
106
|
-
param[:unit] ||= 'day'
|
107
|
-
download_report( auth, param, debug )
|
108
|
-
end
|
109
|
-
|
110
|
-
def self.creative_report( auth, param = nil, debug = false )
|
111
|
-
param = {} if not param
|
112
|
-
param[:type] ||= 'creative'
|
113
|
-
param[:fields] ||= %w( cost cpc click impression ctr )
|
114
|
-
param[:range] ||= 'account'
|
115
|
-
download_report( auth, param, debug )
|
116
|
-
end
|
117
|
-
|
118
|
-
def self.keyword_report( auth, param = nil, debug = false )
|
119
|
-
param = {} if not param
|
120
|
-
param[:type] ||= 'keyword'
|
121
|
-
param[:fields] ||= %w( cost cpc click impression ctr )
|
122
|
-
param[:range] ||= 'account'
|
123
|
-
download_report( auth, param, debug )
|
124
|
-
end
|
125
|
-
|
126
|
-
end # Repost
|
127
|
-
end # Baidu
|
128
|
-
end # API
|
129
|
-
end # PPC
|