ppc 1.3.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE +21 -339
- data/README.md +46 -28
- data/Rakefile +1 -0
- data/lib/ppc.rb +1 -1
- data/lib/ppc/api.rb +18 -14
- data/lib/ppc/api/baidu.rb +5 -14
- data/lib/ppc/api/baidu/account.rb +28 -23
- data/lib/ppc/api/baidu/bulk.rb +1 -1
- data/lib/ppc/api/baidu/creative.rb +47 -86
- data/lib/ppc/api/baidu/group.rb +43 -74
- data/lib/ppc/api/baidu/keyword.rb +73 -166
- data/lib/ppc/api/baidu/phone_new_creative.rb +8 -7
- data/lib/ppc/api/baidu/plan.rb +51 -34
- data/lib/ppc/api/baidu/report.rb +9 -29
- data/lib/ppc/api/qihu.rb +7 -111
- data/lib/ppc/api/qihu/account.rb +31 -25
- data/lib/ppc/api/qihu/bulk.rb +1 -2
- data/lib/ppc/api/qihu/creative.rb +57 -74
- data/lib/ppc/api/qihu/group.rb +40 -63
- data/lib/ppc/api/qihu/keyword.rb +58 -74
- data/lib/ppc/api/qihu/plan.rb +52 -32
- data/lib/ppc/api/qihu/rank.rb +11 -10
- data/lib/ppc/api/qihu/report.rb +41 -94
- data/lib/ppc/api/qihu/sublink.rb +44 -41
- data/lib/ppc/api/sm.rb +3 -12
- data/lib/ppc/api/sm/account.rb +20 -19
- data/lib/ppc/api/sm/creative.rb +36 -50
- data/lib/ppc/api/sm/group.rb +40 -61
- data/lib/ppc/api/sm/keyword.rb +44 -102
- data/lib/ppc/api/sm/phone_new_creative.rb +9 -8
- data/lib/ppc/api/sm/plan.rb +36 -26
- data/lib/ppc/api/sm/report.rb +5 -24
- data/lib/ppc/api/sogou.rb +5 -55
- data/lib/ppc/api/sogou/account.rb +17 -17
- data/lib/ppc/api/sogou/creative.rb +52 -75
- data/lib/ppc/api/sogou/group.rb +44 -91
- data/lib/ppc/api/sogou/keyword.rb +60 -143
- data/lib/ppc/api/sogou/plan.rb +37 -23
- data/lib/ppc/api/sogou/report.rb +2 -19
- data/lib/ppc/ext.rb +0 -8
- data/lib/ppc/operation.rb +60 -83
- data/lib/ppc/operation/account.rb +13 -19
- data/lib/ppc/operation/creative.rb +0 -20
- data/lib/ppc/operation/group.rb +18 -27
- data/lib/ppc/operation/keyword.rb +0 -27
- data/lib/ppc/operation/plan.rb +34 -22
- data/lib/ppc/operation/report.rb +4 -4
- data/lib/ppc/operation/sublink.rb +8 -0
- data/ppc.gemspec +5 -5
- metadata +16 -10
- data/lib/ppc/api/shenma.rb +0 -64
- data/lib/ppc/api/shenma/report.rb +0 -135
data/lib/ppc/operation/report.rb
CHANGED
@@ -3,19 +3,19 @@ module PPC
|
|
3
3
|
module Report
|
4
4
|
|
5
5
|
def download_report( param = nil, debug = false )
|
6
|
-
call(
|
6
|
+
call( "report" ).download_report( @auth, param, debug )
|
7
7
|
end
|
8
8
|
|
9
9
|
def query_report( param = nil, debug = false )
|
10
|
-
call(
|
10
|
+
call( "report" ).query_report( @auth, param, debug )
|
11
11
|
end
|
12
12
|
|
13
13
|
def creative_report( param = nil, debug = false )
|
14
|
-
call(
|
14
|
+
call( "report" ).creative_report( @auth, param, debug )
|
15
15
|
end
|
16
16
|
|
17
17
|
def keyword_report( param = nil, debug = false )
|
18
|
-
call(
|
18
|
+
call( "report" ).keyword_report( @auth, param, debug )
|
19
19
|
end
|
20
20
|
|
21
21
|
end
|
data/ppc.gemspec
CHANGED
@@ -14,12 +14,12 @@ puts """################ WARNING #################
|
|
14
14
|
Gem::Specification.new do |spec|
|
15
15
|
spec.name = "ppc"
|
16
16
|
spec.version = PPC::VERSION
|
17
|
-
spec.authors = ["Chienli Ma,
|
18
|
-
spec.email = ["maqianlie@gmail.com, liuyu_tc@163.com, seoaqua@qq.com"]
|
19
|
-
spec.summary = %q{ppc api for baidu qihu sogou}
|
20
|
-
spec.description = %q{ppc api for baidu qihu sogou}
|
17
|
+
spec.authors = ["Chienli Ma", "刘梦晨", "刘明", "范捷琦"]
|
18
|
+
spec.email = ["maqianlie@gmail.com", "liuyu_tc@163.com", "seoaqua@qq.com", "fjqqiqi@163.com"]
|
19
|
+
spec.summary = %q{ppc api for baidu qihu sogou sm}
|
20
|
+
spec.description = %q{ppc api for baidu qihu sogou sm}
|
21
21
|
spec.homepage = "https://github.com/warriors-of-the-night/ppc"
|
22
|
-
spec.license = "
|
22
|
+
spec.license = "MIT"
|
23
23
|
|
24
24
|
spec.files = `git ls-files -z`.split("\x0")
|
25
25
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
metadata
CHANGED
@@ -1,14 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ppc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Chienli Ma
|
7
|
+
- Chienli Ma
|
8
|
+
- 刘梦晨
|
9
|
+
- 刘明
|
10
|
+
- 范捷琦
|
8
11
|
autorequire:
|
9
12
|
bindir: bin
|
10
13
|
cert_chain: []
|
11
|
-
date:
|
14
|
+
date: 2016-08-04 00:00:00.000000000 Z
|
12
15
|
dependencies:
|
13
16
|
- !ruby/object:Gem::Dependency
|
14
17
|
name: httparty
|
@@ -64,9 +67,12 @@ dependencies:
|
|
64
67
|
- - ">="
|
65
68
|
- !ruby/object:Gem::Version
|
66
69
|
version: '0'
|
67
|
-
description: ppc api for baidu qihu sogou
|
70
|
+
description: ppc api for baidu qihu sogou sm
|
68
71
|
email:
|
69
|
-
- maqianlie@gmail.com
|
72
|
+
- maqianlie@gmail.com
|
73
|
+
- liuyu_tc@163.com
|
74
|
+
- seoaqua@qq.com
|
75
|
+
- fjqqiqi@163.com
|
70
76
|
executables: []
|
71
77
|
extensions: []
|
72
78
|
extra_rdoc_files: []
|
@@ -75,6 +81,7 @@ files:
|
|
75
81
|
- ".rspec"
|
76
82
|
- LICENSE
|
77
83
|
- README.md
|
84
|
+
- Rakefile
|
78
85
|
- lib/ppc.rb
|
79
86
|
- lib/ppc/api.rb
|
80
87
|
- lib/ppc/api/baidu.rb
|
@@ -97,8 +104,6 @@ files:
|
|
97
104
|
- lib/ppc/api/qihu/rank.rb
|
98
105
|
- lib/ppc/api/qihu/report.rb
|
99
106
|
- lib/ppc/api/qihu/sublink.rb
|
100
|
-
- lib/ppc/api/shenma.rb
|
101
|
-
- lib/ppc/api/shenma/report.rb
|
102
107
|
- lib/ppc/api/sm.rb
|
103
108
|
- lib/ppc/api/sm/account.rb
|
104
109
|
- lib/ppc/api/sm/bulk.rb
|
@@ -124,6 +129,7 @@ files:
|
|
124
129
|
- lib/ppc/operation/keyword.rb
|
125
130
|
- lib/ppc/operation/plan.rb
|
126
131
|
- lib/ppc/operation/report.rb
|
132
|
+
- lib/ppc/operation/sublink.rb
|
127
133
|
- ppc.gemspec
|
128
134
|
- spec/baidu/api_baidu_account_spec.rb
|
129
135
|
- spec/baidu/api_baidu_creative_spec.rb
|
@@ -163,7 +169,7 @@ files:
|
|
163
169
|
- spec/spec_helper.rb
|
164
170
|
homepage: https://github.com/warriors-of-the-night/ppc
|
165
171
|
licenses:
|
166
|
-
-
|
172
|
+
- MIT
|
167
173
|
metadata: {}
|
168
174
|
post_install_message:
|
169
175
|
rdoc_options: []
|
@@ -181,10 +187,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
181
187
|
version: '0'
|
182
188
|
requirements: []
|
183
189
|
rubyforge_project:
|
184
|
-
rubygems_version: 2.
|
190
|
+
rubygems_version: 2.5.1
|
185
191
|
signing_key:
|
186
192
|
specification_version: 4
|
187
|
-
summary: ppc api for baidu qihu sogou
|
193
|
+
summary: ppc api for baidu qihu sogou sm
|
188
194
|
test_files:
|
189
195
|
- spec/baidu/api_baidu_account_spec.rb
|
190
196
|
- spec/baidu/api_baidu_creative_spec.rb
|
data/lib/ppc/api/shenma.rb
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
module PPC
|
2
|
-
module API
|
3
|
-
class Baidu
|
4
|
-
@map = nil
|
5
|
-
@@debug = false
|
6
|
-
|
7
|
-
def self.debug_on
|
8
|
-
@@debug = true
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.debug_off
|
12
|
-
@@debug = false
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.request( auth, path, params = {} )
|
16
|
-
'''
|
17
|
-
request should return whole http response including header
|
18
|
-
'''
|
19
|
-
uri = URI("https://e.sm.cn#{path}")
|
20
|
-
http_body = {
|
21
|
-
header: {
|
22
|
-
username: auth[:username],
|
23
|
-
password: auth[:password],
|
24
|
-
token: auth[:token],
|
25
|
-
target: auth[:tarvget]
|
26
|
-
},
|
27
|
-
body: params
|
28
|
-
}.to_json
|
29
|
-
|
30
|
-
http_header = {
|
31
|
-
'Content-Type' => 'application/json; charset=UTF-8'
|
32
|
-
}
|
33
|
-
|
34
|
-
http = Net::HTTP.new(uri.host, 443)
|
35
|
-
# 是否显示http通信输出
|
36
|
-
http.set_debug_output( $stdout ) if @@debug
|
37
|
-
http.use_ssl = true
|
38
|
-
|
39
|
-
response = http.post(uri.path, http_body, http_header)
|
40
|
-
response = JSON.parse( response.body )
|
41
|
-
end
|
42
|
-
|
43
|
-
def self.process( response, key, &func)
|
44
|
-
'''
|
45
|
-
Process Http response. If operation successes, return value of given keys.
|
46
|
-
You can process the result using function &func, or do nothing by passing
|
47
|
-
block {|x|x}
|
48
|
-
===========================
|
49
|
-
@Output: resultType{ desc: boolean, failure: Array, result: Array }
|
50
|
-
|
51
|
-
failure is the failures part of response\'s header
|
52
|
-
result is the processed response body.
|
53
|
-
'''
|
54
|
-
p response
|
55
|
-
result = {}
|
56
|
-
result[:succ] = response['header']['desc']=='success'? true : false
|
57
|
-
result[:failure] = response['header']['failures']
|
58
|
-
result[:result] = func[ response['body'][key] ]
|
59
|
-
return result
|
60
|
-
end # process
|
61
|
-
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
@@ -1,135 +0,0 @@
|
|
1
|
-
# -*- coding:utf-8 -*-
|
2
|
-
module PPC
|
3
|
-
module API
|
4
|
-
class Shenma
|
5
|
-
class Report< Shenma
|
6
|
-
Service = 'Report'
|
7
|
-
|
8
|
-
# 需要用到的映射集合
|
9
|
-
Type_map = { 'account' =>2, 'plan'=> 10, 'group'=> 11,
|
10
|
-
'keyword'=> 14, 'creative'=> 12, 'region'=> 3,
|
11
|
-
'query'=> 6, 'phone' => 22, 'app' => 23 }
|
12
|
-
|
13
|
-
Level_map = { 'account' => 2, 'plan' => 3, 'group' => 5,
|
14
|
-
'creative' => 7, 'keyword' => 11, 'phone' => 22,
|
15
|
-
'app' => 23, 'pair' => 12 }
|
16
|
-
|
17
|
-
Unit_map = { 'day' => 5, 'month' => 3, 'default' => 8 }
|
18
|
-
|
19
|
-
def self.get_id( auth, params, debug = false )
|
20
|
-
request = make_reportrequest( params )
|
21
|
-
body = { ReportRequestType: request }
|
22
|
-
response = request( auth, '/report/getReport' ,body)
|
23
|
-
process( response, 'reportId', debug ){ |x| x }
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.get_state( auth, id, debug = false)
|
27
|
-
'''
|
28
|
-
input id should be string
|
29
|
-
'''
|
30
|
-
status = {1=>'Waiting' ,2=>'Opearting' ,3=>'Finished'}
|
31
|
-
body = { taskId: id }
|
32
|
-
response = request( auth, '/task/getTaskState' ,body)
|
33
|
-
process( response, 'isGenerated', debug ){ |x| status[x] }
|
34
|
-
end
|
35
|
-
|
36
|
-
# todo : rewrite method
|
37
|
-
def self.download( auth, id, debug = false )
|
38
|
-
body = { fileId: id }
|
39
|
-
response = request( auth, '/file/download' ,body)
|
40
|
-
process( response, 'reportPath', 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]
|
53
|
-
requesttype[:reportType] = Type_map[ param[:type] ] if param[:type]
|
54
|
-
requesttype[:levelOfDetails] = Level_map[ param[:level] ] if param[:level]
|
55
|
-
requesttype[:statRange] = Level_map[ param[:range] ] if param[:range]
|
56
|
-
requesttype[:unitOfTime] = Unit_map[ param[:unit] ] if param[:unit]
|
57
|
-
requesttype[:idOnly] = param[:id_only] || false
|
58
|
-
requesttype[:statIds] = param[:ids] if param[:ids] != nil
|
59
|
-
requesttype[:startDate] = parse_date( param[:startDate] )
|
60
|
-
requesttype[:endDate] = parse_date( param[:endDate] )
|
61
|
-
return requesttype
|
62
|
-
end
|
63
|
-
|
64
|
-
private
|
65
|
-
def self.parse_date( date )
|
66
|
-
"""
|
67
|
-
Cast string to time:
|
68
|
-
'YYYYMMDD' => Time
|
69
|
-
"""
|
70
|
-
if date
|
71
|
-
y = date[0..3]
|
72
|
-
m = date[4..5]
|
73
|
-
d = date[6..7]
|
74
|
-
date = Time.new( y, m, d )
|
75
|
-
else
|
76
|
-
date = (Time.now - 24*3600)
|
77
|
-
end
|
78
|
-
date.to_s[0,10]
|
79
|
-
end
|
80
|
-
|
81
|
-
def download_report( auth, param, debug = false )
|
82
|
-
response = call('report').get_id( auth, param )
|
83
|
-
if response[:succ]
|
84
|
-
id = response[:result]
|
85
|
-
p "Got report id:" + id.to_s if debug
|
86
|
-
loop do
|
87
|
-
sleep 2
|
88
|
-
break if call('report').get_state( auth, id )[:result] == 'Finished'
|
89
|
-
p "Report is not generated, waiting..." if debug
|
90
|
-
end
|
91
|
-
# need to rewrite the download method here.
|
92
|
-
url = call('report').get_url( auth, id )[:result]
|
93
|
-
return open(url).read.force_encoding('gb18030').encode('utf-8')
|
94
|
-
else
|
95
|
-
raise response[:failure][0]["message"]
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
###########################
|
100
|
-
# intreface for Operation #
|
101
|
-
###########################
|
102
|
-
def query_report( auth, param = nil, debug = false )
|
103
|
-
param = {} if not param
|
104
|
-
param[:type] ||= 'query'
|
105
|
-
param[:fields] ||= %w(click)
|
106
|
-
param[:level] ||= 'pair'
|
107
|
-
param[:range] ||= 'account'
|
108
|
-
param[:unit] ||= 'day'
|
109
|
-
download_report( param, debug )
|
110
|
-
end
|
111
|
-
|
112
|
-
def creative_report( auth, param = nil, debug = false )
|
113
|
-
param = {} if not param
|
114
|
-
param[:type] ||= 'creative'
|
115
|
-
param[:fields] ||= %w( cost cpc click impression ctr )
|
116
|
-
param[:level] ||= 'creative'
|
117
|
-
param[:range] ||= 'creative'
|
118
|
-
param[:unit] ||= 'day'
|
119
|
-
download_report( param, debug )
|
120
|
-
end
|
121
|
-
|
122
|
-
def keyword_report( auth, param = nil, debug = false )
|
123
|
-
param = {} if not param
|
124
|
-
param[:type] ||= 'keyword'
|
125
|
-
param[:fields] ||= %w( cost cpc click impression ctr )
|
126
|
-
param[:level] ||= 'keywordid'
|
127
|
-
param[:range] ||= 'keywordid'
|
128
|
-
param[:unit] ||= 'day'
|
129
|
-
download_report( param, debug )
|
130
|
-
end
|
131
|
-
|
132
|
-
end # Repost
|
133
|
-
end # Baidu
|
134
|
-
end # API
|
135
|
-
end # PPC
|