ppc 1.3.0 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -1
- data/LICENSE +334 -17
- data/README.md +75 -3
- data/lib/ppc.rb +3 -1
- data/lib/ppc/api.rb +137 -2
- data/lib/ppc/api/baidu.rb +20 -99
- data/lib/ppc/api/baidu/account.rb +21 -21
- data/lib/ppc/api/baidu/bulk.rb +39 -3
- data/lib/ppc/api/baidu/creative.rb +33 -33
- data/lib/ppc/api/baidu/group.rb +14 -14
- data/lib/ppc/api/baidu/keyword.rb +57 -46
- data/lib/ppc/api/baidu/phone_new_creative.rb +51 -0
- data/lib/ppc/api/baidu/plan.rb +34 -31
- data/lib/ppc/api/baidu/rank.rb +23 -0
- data/lib/ppc/api/baidu/report.rb +100 -81
- data/lib/ppc/api/qihu.rb +150 -0
- data/lib/ppc/api/qihu/account.rb +86 -0
- data/lib/ppc/api/qihu/bulk.rb +35 -0
- data/lib/ppc/api/qihu/creative.rb +108 -0
- data/lib/ppc/api/qihu/group.rb +96 -0
- data/lib/ppc/api/qihu/keyword.rb +113 -0
- data/lib/ppc/api/qihu/plan.rb +64 -0
- data/lib/ppc/api/qihu/rank.rb +25 -0
- data/lib/ppc/api/qihu/report.rb +159 -0
- data/lib/ppc/api/qihu/sublink.rb +71 -0
- data/lib/ppc/api/shenma.rb +64 -0
- data/lib/ppc/api/shenma/report.rb +135 -0
- data/lib/ppc/api/sm.rb +50 -0
- data/lib/ppc/api/sm/account.rb +44 -0
- data/lib/ppc/api/sm/bulk.rb +69 -0
- data/lib/ppc/api/sm/creative.rb +86 -0
- data/lib/ppc/api/sm/group.rb +94 -0
- data/lib/ppc/api/sm/keyword.rb +132 -0
- data/lib/ppc/api/sm/phone_new_creative.rb +51 -0
- data/lib/ppc/api/sm/plan.rb +63 -0
- data/lib/ppc/api/sm/report.rb +136 -0
- data/lib/ppc/api/sogou.rb +118 -0
- data/lib/ppc/api/sogou/account.rb +42 -0
- data/lib/ppc/api/sogou/bulk.rb +69 -0
- data/lib/ppc/api/sogou/creative.rb +117 -0
- data/lib/ppc/api/sogou/group.rb +123 -0
- data/lib/ppc/api/sogou/keyword.rb +188 -0
- data/lib/ppc/api/sogou/plan.rb +66 -0
- data/lib/ppc/api/sogou/report.rb +129 -0
- data/lib/ppc/ext.rb +17 -0
- data/lib/ppc/operation.rb +50 -36
- data/lib/ppc/operation/account.rb +19 -7
- data/lib/ppc/operation/creative.rb +7 -7
- data/lib/ppc/operation/group.rb +2 -2
- data/lib/ppc/operation/keyword.rb +11 -8
- data/lib/ppc/operation/report.rb +23 -0
- data/ppc.gemspec +14 -4
- data/spec/baidu/api_baidu_account_spec.rb +16 -0
- data/spec/baidu/api_baidu_creative_spec.rb +73 -0
- data/spec/{api_baidu_group_spec.rb → baidu/api_baidu_group_spec.rb} +12 -17
- data/spec/baidu/api_baidu_keyword_spec.rb +61 -0
- data/spec/baidu/api_baidu_phone_spec.rb +22 -0
- data/spec/{api_baidu_plan_spec.rb → baidu/api_baidu_plan_spec.rb} +11 -10
- data/spec/baidu/api_baidu_report_spec.rb +44 -0
- data/spec/{api_baidu_spec.rb → baidu/api_baidu_spec.rb} +10 -15
- data/spec/operation/operation_baidu_report_spec.rb +17 -0
- data/spec/operation/operation_baidu_spec.rb +126 -0
- data/spec/operation/operation_qihu_report_spec.rb +18 -0
- data/spec/operation/operation_qihu_spec.rb +94 -0
- data/spec/operation/operation_sm_report_spec.rb +21 -0
- data/spec/operation/operation_sogou_report_spec.rb +17 -0
- data/spec/operation/operation_sogou_spec.rb +88 -0
- data/spec/{operation_spec_helper.rb → operation/operation_spec_helper.rb} +3 -5
- data/spec/qihu/api_qihu_account_spec.rb +29 -0
- data/spec/qihu/api_qihu_creative_spec.rb +48 -0
- data/spec/qihu/api_qihu_group_spec.rb +40 -0
- data/spec/qihu/api_qihu_keyword_spec.rb +50 -0
- data/spec/qihu/api_qihu_plan_spec.rb +39 -0
- data/spec/qihu/api_qihu_report_spec.rb +54 -0
- data/spec/qihu/api_qihu_sublink_spec.rb +36 -0
- data/spec/sm/api_sm_account_spec.rb +8 -0
- data/spec/sm/api_sm_creative_spec.rb +52 -0
- data/spec/sm/api_sm_group_spec.rb +75 -0
- data/spec/sm/api_sm_keyword_spec.rb +59 -0
- data/spec/sm/api_sm_plan_spec.rb +39 -0
- data/spec/sm/api_sm_report_spec.rb +30 -0
- data/spec/sogou/api_sogou_account_spec.rb +17 -0
- data/spec/sogou/api_sogou_creative_spec.rb +51 -0
- data/spec/sogou/api_sogou_group_spec.rb +50 -0
- data/spec/sogou/api_sogou_keyword_spec.rb +54 -0
- data/spec/sogou/api_sogou_plan_spec.rb +43 -0
- data/spec/sogou/api_sogou_report_spec.rb +51 -0
- data/spec/spec_helper.rb +49 -10
- metadata +140 -46
- data/lib/ppc/baidu.rb +0 -152
- data/lib/ppc/baidu/account.rb +0 -88
- data/lib/ppc/baidu/bulk.rb +0 -52
- data/lib/ppc/baidu/group.rb +0 -99
- data/lib/ppc/baidu/key.rb +0 -38
- data/lib/ppc/baidu/plan.rb +0 -85
- data/lib/ppc/baidu/report.rb +0 -82
- data/spec/api_baidu_account_spec.rb +0 -18
- data/spec/api_baidu_creative_spec.rb +0 -71
- data/spec/api_baidu_keyword_spec.rb +0 -64
- data/spec/api_baidu_report_spec.rb +0 -32
- data/spec/baidu_account_spec.rb +0 -32
- data/spec/baidu_bulk_spec.rb +0 -21
- data/spec/baidu_group_spec.rb +0 -56
- data/spec/baidu_plan_spec.rb +0 -129
- data/spec/baidu_report_spec.rb +0 -24
- data/spec/operation_spec.rb +0 -87
data/lib/ppc.rb
CHANGED
data/lib/ppc/api.rb
CHANGED
@@ -1,8 +1,143 @@
|
|
1
|
+
require 'awesome_print'
|
2
|
+
require 'net/http'
|
3
|
+
require 'net/https'
|
4
|
+
require 'httparty'
|
5
|
+
require 'json'
|
6
|
+
require 'savon'
|
7
|
+
require 'active_support'
|
1
8
|
require 'ppc/api/baidu'
|
9
|
+
require 'ppc/api/sogou'
|
10
|
+
require 'ppc/api/qihu'
|
11
|
+
require 'ppc/api/sm'
|
2
12
|
|
3
13
|
module PPC
|
4
14
|
module API
|
5
|
-
|
6
|
-
|
15
|
+
|
16
|
+
@map = nil
|
17
|
+
@debug = false
|
18
|
+
|
19
|
+
def debug_on
|
20
|
+
@debug = true
|
21
|
+
end
|
22
|
+
|
23
|
+
def debug_off
|
24
|
+
@debug = false
|
25
|
+
end
|
26
|
+
|
27
|
+
def request_uri(param = {})
|
28
|
+
raise 'you need build the uri'
|
29
|
+
end
|
30
|
+
|
31
|
+
def request_http_body(auth, params = {})
|
32
|
+
{
|
33
|
+
header: {
|
34
|
+
username: auth[:username],
|
35
|
+
password: auth[:password],
|
36
|
+
token: auth[:token],
|
37
|
+
target: auth[:target]
|
38
|
+
},
|
39
|
+
body: params
|
40
|
+
}.to_json
|
41
|
+
end
|
42
|
+
|
43
|
+
def request_http_header(auth)
|
44
|
+
{'Content-Type' => 'application/json; charset=UTF-8'}
|
45
|
+
end
|
46
|
+
|
47
|
+
def request(auth, service, method, params = {}, http_method = 'post')
|
48
|
+
'''
|
49
|
+
request should return whole http response including header
|
50
|
+
'''
|
51
|
+
uri = request_uri(service: service, method: method)
|
52
|
+
http_body = request_http_body(auth, params)
|
53
|
+
http_header = request_http_header(auth)
|
54
|
+
|
55
|
+
# set request proxy
|
56
|
+
if ENV["PROXY_HOST"]
|
57
|
+
proxy_port = ENV["PROXY_PORT"] ? ENV["PROXY_PORT"].to_i : 80
|
58
|
+
http = Net::HTTP.new(uri.host, 443, ENV["PROXY_HOST"], proxy_port)
|
59
|
+
else
|
60
|
+
http = Net::HTTP.new(uri.host, 443)
|
61
|
+
end
|
62
|
+
|
63
|
+
# 是否显示http通信输出
|
64
|
+
http.set_debug_output( $stdout ) if @debug
|
65
|
+
http.use_ssl = true
|
66
|
+
if http_method == 'delete'
|
67
|
+
req = Net::HTTP::Delete.new(uri.path, http_header)
|
68
|
+
req.body = http_body
|
69
|
+
response = http.request req
|
70
|
+
else
|
71
|
+
response = http.post(uri.path, http_body, http_header)
|
72
|
+
end
|
73
|
+
begin JSON.parse(response.body) rescue response.body end
|
74
|
+
end
|
75
|
+
|
76
|
+
def process( response, key, &func)
|
77
|
+
'''
|
78
|
+
Process Http response. If operation successes, return value of given keys.
|
79
|
+
You can process the result using function &func, or do nothing by passing
|
80
|
+
block {|x|x}
|
81
|
+
===========================
|
82
|
+
@Output: resultType{ desc: boolean, failure: Array, result: Array }
|
83
|
+
|
84
|
+
failure is the failures part of response\'s header
|
85
|
+
result is the processed response body.
|
86
|
+
'''
|
87
|
+
raise 'you need build the response result'
|
88
|
+
end
|
89
|
+
|
90
|
+
def is_no_quota(failure, code)
|
91
|
+
return false if failure.nil?
|
92
|
+
failure = [failure].flatten
|
93
|
+
return false if failure.size.zero?
|
94
|
+
return failure[0]["code"] == code
|
95
|
+
end
|
96
|
+
|
97
|
+
def make_type( params, maps = @map)
|
98
|
+
'''
|
99
|
+
tranfesr ppc api to search engine api
|
100
|
+
@ input
|
101
|
+
params : list of hash complying with PPC gem api
|
102
|
+
map : list of pairs(lists) of symbol complying with following api
|
103
|
+
map = [
|
104
|
+
[ ppc_key, api_key ],
|
105
|
+
[ ppc_key, api_key ],
|
106
|
+
[ ppc_key, api_key ],
|
107
|
+
...
|
108
|
+
]
|
109
|
+
Ex:
|
110
|
+
baidu_group_map = [ [ :id, :adgroupId],
|
111
|
+
[ :price, :maxPrice],
|
112
|
+
... ]
|
113
|
+
===================
|
114
|
+
@ output:
|
115
|
+
types : list of hash that complying with search engine api
|
116
|
+
'''
|
117
|
+
params = [ params ] unless params.is_a? Array
|
118
|
+
params.map do |item|
|
119
|
+
item.select!{|key| maps.map{|m| m[0]}.include? key}
|
120
|
+
maps.each{|m| item.filter_and_replace_key(m[1],m[0])}
|
121
|
+
item
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def reverse_type( types, maps = @map )
|
126
|
+
'''
|
127
|
+
transfer search engine api to ppc api
|
128
|
+
@ input
|
129
|
+
types : list of hash that complying with search engine api
|
130
|
+
map : list of pairs(lists) of symbol, for more details please
|
131
|
+
read docs of make_type()
|
132
|
+
===================
|
133
|
+
@ output:
|
134
|
+
params : list of hash complying with PPC gem api
|
135
|
+
'''
|
136
|
+
types = [ types ] unless types.is_a? Array
|
137
|
+
types.map do |item|
|
138
|
+
maps.each{|m| item.filter_and_replace_key(m[0],m[1])}
|
139
|
+
item
|
140
|
+
end
|
141
|
+
end
|
7
142
|
end
|
8
143
|
end
|
data/lib/ppc/api/baidu.rb
CHANGED
@@ -6,127 +6,48 @@ require 'ppc/api/baidu/group'
|
|
6
6
|
require 'ppc/api/baidu/keyword'
|
7
7
|
require 'ppc/api/baidu/report'
|
8
8
|
require 'ppc/api/baidu/creative'
|
9
|
-
require '
|
10
|
-
require '
|
11
|
-
|
12
|
-
require 'json'
|
9
|
+
require 'ppc/api/baidu/phone_new_creative'
|
10
|
+
require 'ppc/api/baidu/rank'
|
11
|
+
|
13
12
|
module PPC
|
14
13
|
module API
|
15
|
-
class Baidu
|
16
|
-
|
17
|
-
@map = nil
|
18
|
-
|
19
|
-
def self.request( auth, service, method, params = {} )
|
20
|
-
'''
|
21
|
-
request should return whole http response including header
|
22
|
-
'''
|
23
|
-
uri = URI("https://api.baidu.com/json/sms/v3/#{service}Service/#{method}")
|
24
|
-
http_body = {
|
25
|
-
header: {
|
26
|
-
username: auth[:username],
|
27
|
-
password: auth[:password],
|
28
|
-
token: auth[:token]
|
29
|
-
},
|
30
|
-
body: params
|
31
|
-
}.to_json
|
32
|
-
|
33
|
-
http_header = {
|
34
|
-
'Content-Type' => 'application/json; charset=UTF-8'
|
35
|
-
}
|
14
|
+
class Baidu
|
36
15
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
response = http.post(uri.path, http_body, http_header)
|
42
|
-
response = JSON.parse response.body
|
43
|
-
|
44
|
-
# return response if with_header else response['body']
|
16
|
+
extend ::PPC::API
|
17
|
+
|
18
|
+
def self.request_uri(param)
|
19
|
+
URI("https://api.baidu.com/json/sms/v3/#{param[:service]}Service/#{param[:method]}")
|
45
20
|
end
|
46
21
|
|
47
|
-
def self.process(
|
22
|
+
def self.process(response, key, &func)
|
48
23
|
'''
|
49
24
|
Process Http response. If operation successes, return value of given keys.
|
50
25
|
You can process the result using function &func, or do nothing by passing
|
51
26
|
block {|x|x}
|
52
27
|
===========================
|
53
28
|
@Output: resultType{ desc: boolean, failure: Array, result: Array }
|
29
|
+
|
54
30
|
failure is the failures part of response\'s header
|
55
31
|
result is the processed response body.
|
56
32
|
'''
|
57
|
-
# 保留 debug 功能
|
58
|
-
return response if debug
|
59
|
-
|
60
33
|
result = {}
|
61
|
-
result[:succ] = response['header']['desc']=='success'
|
34
|
+
result[:succ] = response['header']['desc'] =='success'
|
62
35
|
result[:failure] = response['header']['failures']
|
63
|
-
|
64
|
-
|
65
|
-
end # process
|
66
|
-
|
67
|
-
def self.make_type( params, map = @map)
|
68
|
-
'''
|
69
|
-
tranfesr ppc api to search engine api
|
70
|
-
@ input
|
71
|
-
params : list of hash complying with PPC gem api
|
72
|
-
map : list of pairs(lists) of symbol complying with following api
|
73
|
-
map = [
|
74
|
-
[ ppc_key, api_key ],
|
75
|
-
[ ppc_key, api_key ],
|
76
|
-
[ ppc_key, api_key ],
|
77
|
-
...
|
78
|
-
]
|
79
|
-
Ex:
|
80
|
-
baidu_group_map = [ [ :id, :adgroupId],
|
81
|
-
[ :price, :maxPrice],
|
82
|
-
... ]
|
83
|
-
===================
|
84
|
-
@ output:
|
85
|
-
: types : list of hash that complying with search engine api
|
86
|
-
'''
|
87
|
-
params = [ params ] unless params.is_a? Array
|
88
|
-
|
89
|
-
types = []
|
90
|
-
params.each do |param|
|
91
|
-
type = {}
|
92
|
-
|
93
|
-
map.each do |key|
|
94
|
-
value = param[ key[0] ]
|
95
|
-
type[ key[1] ] = value if value
|
96
|
-
end
|
97
|
-
|
98
|
-
types << type
|
36
|
+
if !response['body'].nil? && response['body'][key]
|
37
|
+
result[:result] = func[ response['body'][key] ]
|
99
38
|
end
|
100
|
-
|
39
|
+
result[:no_quota] = is_no_quota(response['header']['failures'], '8501')
|
40
|
+
return result
|
101
41
|
end
|
102
42
|
|
103
|
-
def self.reverse_type( types,
|
104
|
-
'''
|
105
|
-
transfer search engine api to ppc api
|
106
|
-
@ input
|
107
|
-
types : list of hash that complying with search engine api
|
108
|
-
map : list of pairs(lists) of symbol, for more details please
|
109
|
-
read docs of make_type()
|
110
|
-
===================
|
111
|
-
@ output:
|
112
|
-
params : list of hash complying with PPC gem api
|
113
|
-
'''
|
43
|
+
def self.reverse_type( types, maps = @map )
|
114
44
|
types = [ types ] unless types.is_a? Array
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
param = {}
|
119
|
-
|
120
|
-
map.each do |key|
|
121
|
-
value = type[ key[1].to_s ]
|
122
|
-
param[ key[0] ] = value if value
|
123
|
-
end
|
124
|
-
|
125
|
-
params << param
|
45
|
+
types.map do |item|
|
46
|
+
maps.each{|m| item.filter_and_replace_key(m[0],m[1].to_s)}
|
47
|
+
item
|
126
48
|
end
|
127
|
-
return params
|
128
49
|
end
|
129
50
|
|
130
|
-
|
51
|
+
end # Baidu
|
131
52
|
end # API
|
132
53
|
end # PPC
|
@@ -5,30 +5,30 @@ module PPC
|
|
5
5
|
Service = 'Account'
|
6
6
|
|
7
7
|
@map = [
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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
25
|
|
26
|
-
def self.info(auth
|
26
|
+
def self.info( auth )
|
27
27
|
response = request(auth,Service,'getAccountInfo' )
|
28
|
-
return process( response, 'accountInfoType'
|
28
|
+
return process( response, 'accountInfoType' ){ |x|reverse_type(x)[0] }
|
29
29
|
end
|
30
30
|
|
31
|
-
def self.update(auth, param = {}
|
31
|
+
def self.update(auth, param = {} )
|
32
32
|
"""
|
33
33
|
update account info
|
34
34
|
@ params : account_info_type
|
@@ -38,7 +38,7 @@ module PPC
|
|
38
38
|
infoType = make_type( param )[0]
|
39
39
|
body = { accountInfoType: infoType }
|
40
40
|
response = request(auth,Service,'updateAccountInfo', body)
|
41
|
-
return process( response, 'accountInfoType'
|
41
|
+
return process( response, 'accountInfoType' ){ |x|reverse_type(x)[0] }
|
42
42
|
end
|
43
43
|
|
44
44
|
end
|
data/lib/ppc/api/baidu/bulk.rb
CHANGED
@@ -23,16 +23,52 @@ module PPC
|
|
23
23
|
extended: params[:extended] || 0
|
24
24
|
}
|
25
25
|
response = request( auth, Service, 'getAllObjects',options )
|
26
|
-
response
|
26
|
+
process( response, 'fileId'){ |x| x }
|
27
27
|
end
|
28
28
|
|
29
29
|
def self.state( auth, id)
|
30
30
|
raise "empty id" if id.nil? or id.empty?
|
31
|
-
request(auth, Service, 'getFileState',{fileId:id})
|
31
|
+
response = request(auth, Service, 'getFileState',{fileId:id})
|
32
|
+
process( response, 'isGenerated'){ |x| x }
|
32
33
|
end
|
33
34
|
|
34
35
|
def self.path( auth, id)
|
35
|
-
request( auth, Service, 'getFilePath',{fileId:id})
|
36
|
+
response = request( auth, Service, 'getFilePath',{fileId:id})
|
37
|
+
process( response, 'filePaths' ){ |x| x }
|
38
|
+
end
|
39
|
+
|
40
|
+
###########################
|
41
|
+
# interface for operation #
|
42
|
+
###########################
|
43
|
+
def self.download( auth, params = {} )
|
44
|
+
"""
|
45
|
+
"""
|
46
|
+
params[:extended] = params[:extended] || 2
|
47
|
+
begin
|
48
|
+
file_id = get_all_object( auth, params )
|
49
|
+
if file_id[:succ]
|
50
|
+
file_id = file_id[:result]
|
51
|
+
else
|
52
|
+
raise file_id[:failure][0]['message']
|
53
|
+
end
|
54
|
+
|
55
|
+
puts "file_id: #{file_id}" if @debug
|
56
|
+
|
57
|
+
loop do
|
58
|
+
state = state( auth, file_id )[:result].to_s
|
59
|
+
raise "invalid file state: #{state}" unless %w(1 2 3 null).include? state
|
60
|
+
break if state == '3'
|
61
|
+
puts "waiting for #{file_id} to be ready. current state:#{state}" if @debug
|
62
|
+
sleep 3
|
63
|
+
end
|
64
|
+
|
65
|
+
puts "#{file_id} is ready" if @debug
|
66
|
+
return path( auth, file_id )
|
67
|
+
|
68
|
+
rescue => e
|
69
|
+
p "Error encounter:#{e.to_s}"
|
70
|
+
end
|
71
|
+
return false
|
36
72
|
end
|
37
73
|
|
38
74
|
end
|
@@ -6,26 +6,26 @@ module PPC
|
|
6
6
|
Service = 'Creative'
|
7
7
|
|
8
8
|
@map =[
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
+
[:mobile_destination,:mobileDestinationUrl],
|
17
|
+
[:mobile_display,:mobileDisplayUrl],
|
18
|
+
[:pause,:pause],
|
19
|
+
[:preference,:devicePreference]
|
20
|
+
]
|
21
21
|
|
22
|
-
def self.add( auth, creatives
|
22
|
+
def self.add( auth, creatives )
|
23
23
|
body = { creativeTypes: make_type( creatives ) }
|
24
24
|
response = request( auth, Service, 'addCreative', body )
|
25
|
-
process( response, 'creativeTypes'
|
25
|
+
process( response, 'creativeTypes' ){ |x| reverse_type(x) }
|
26
26
|
end
|
27
27
|
|
28
|
-
def self.get( auth, ids,
|
28
|
+
def self.get( auth, ids, getTemp = 0 )
|
29
29
|
'''
|
30
30
|
\'getCreativeByCreativeId\'
|
31
31
|
@ input : creative ids
|
@@ -34,49 +34,49 @@ module PPC
|
|
34
34
|
ids = [ ids ] unless ids.is_a? Array
|
35
35
|
body = { creativeIds: ids, getTemp: getTemp }
|
36
36
|
response = request( auth, Service, 'getCreativeByCreativeId', body )
|
37
|
-
process( response, 'creativeTypes'
|
37
|
+
process( response, 'creativeTypes' ){ |x| reverse_type(x) }
|
38
38
|
end
|
39
39
|
|
40
|
-
def self.update( auth, creatives
|
40
|
+
def self.update( auth, creatives )
|
41
41
|
'''
|
42
42
|
根据实际使用情况,更新的时候creative title为必填选
|
43
43
|
'''
|
44
44
|
body = { creativeTypes: make_type( creatives ) }
|
45
|
-
response = request( auth, Service, '
|
46
|
-
process( response, 'creativeTypes'
|
45
|
+
response = request( auth, Service, 'updateCreative', body )
|
46
|
+
process( response, 'creativeTypes' ){ |x| reverse_type(x) }
|
47
47
|
end
|
48
48
|
|
49
|
-
def self.delete( auth, ids
|
49
|
+
def self.delete( auth, ids )
|
50
50
|
ids = [ ids ] unless ids.is_a? Array
|
51
51
|
body = { creativeIds: ids }
|
52
52
|
response = request( auth, Service, 'deleteCreative', body )
|
53
|
-
process( response, 'result'
|
53
|
+
process( response, 'result' ){ |x| x }
|
54
54
|
end
|
55
55
|
|
56
|
-
def self.activate( auth, ids
|
56
|
+
def self.activate( auth, ids )
|
57
57
|
ids = [ ids ] unless ids.is_a? Array
|
58
58
|
body = { creativeIds: ids }
|
59
59
|
response = request( auth, Service, 'activateCreative', body )
|
60
|
-
process( response, 'creativeTypes'
|
60
|
+
process( response, 'creativeTypes' ){ |x| reverse_type(x) }
|
61
61
|
end
|
62
62
|
|
63
|
-
def self.status( auth, ids, type
|
63
|
+
def self.status( auth, ids, type )
|
64
64
|
ids = [ ids ] unless ids.is_a? Array
|
65
65
|
|
66
66
|
type = case type
|
67
67
|
when 'plan' then 3
|
68
|
-
when 'group'
|
69
|
-
when 'creative'
|
68
|
+
when 'group' then 5
|
69
|
+
when 'creative' then 7
|
70
70
|
else
|
71
71
|
Exception.new( 'type must among: \'plan\',\'group\' and \'key\' ')
|
72
72
|
end
|
73
73
|
|
74
74
|
body = { ids: ids, type: type }
|
75
75
|
response = request( auth, Service, 'getCreativeStatus', body )
|
76
|
-
process( response, 'CreativeStatus'
|
76
|
+
process( response, 'CreativeStatus' ){ |x| x }
|
77
77
|
end
|
78
78
|
|
79
|
-
def self.search_id_by_group_id( auth, ids,
|
79
|
+
def self.search_id_by_group_id( auth, ids, getTemp = 0 )
|
80
80
|
'''
|
81
81
|
\'getCreativeIdByAdgroupId\'
|
82
82
|
@ input: group ids
|
@@ -85,14 +85,14 @@ module PPC
|
|
85
85
|
ids = [ ids ] unless ids.is_a? Array
|
86
86
|
body = { adgroupIds: ids, getTemp: getTemp }
|
87
87
|
response = request( auth, Service, 'getCreativeIdByAdgroupId', body )
|
88
|
-
process( response, 'groupCreativeIds'
|
88
|
+
process( response, 'groupCreativeIds' ){ |x| make_groupCreativeIds( x ) }
|
89
89
|
end
|
90
90
|
|
91
|
-
def self.search_by_group_id( auth, ids,
|
91
|
+
def self.search_by_group_id( auth, ids, getTemp = 0 )
|
92
92
|
ids = [ ids ] unless ids.is_a? Array
|
93
93
|
body = { adgroupIds: ids, getTemp: getTemp }
|
94
94
|
response = request( auth, Service, 'getCreativeByAdgroupId', body )
|
95
|
-
process( response, 'groupCreatives'
|
95
|
+
process( response, 'groupCreatives' ){ |x| make_groupCreatives( x ) }
|
96
96
|
end
|
97
97
|
|
98
98
|
private
|
@@ -110,10 +110,10 @@ module PPC
|
|
110
110
|
private
|
111
111
|
def self.make_groupCreatives( groupCreatives )
|
112
112
|
group_creatives = []
|
113
|
-
|
113
|
+
groupCreatives.each do |groupCreative |
|
114
114
|
group_creative = {}
|
115
115
|
group_creative[:group_id] = groupCreative['adgroupId']
|
116
|
-
group_creative[:
|
116
|
+
group_creative[:creatives] = reverse_type( groupCreative['creativeTypes'] )
|
117
117
|
group_creatives << group_creative
|
118
118
|
end
|
119
119
|
return group_creatives
|