ppc 1.3.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- 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/api/sogou/report.rb
CHANGED
@@ -55,28 +55,11 @@ module PPC
|
|
55
55
|
requesttype[:unitOfTime] = Unit_map[ param[:unit] ] if param[:unit]
|
56
56
|
requesttype[:platform] = Device_map[ param[:device] ] if param[:device]
|
57
57
|
requesttype[:idOnly] = param[:id_only] if param[:id_only]!=nil
|
58
|
-
requesttype[:startDate]
|
59
|
-
requesttype[:endDate]
|
58
|
+
requesttype[:startDate] = (Time.parse( param[:startDate] ) rescue Time.now - 86400).utc.iso8601
|
59
|
+
requesttype[:endDate] = (Time.parse( param[:endDate] ) rescue Time.now - 86400).utc.iso8601
|
60
60
|
return requesttype
|
61
61
|
end
|
62
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
63
|
###########################
|
81
64
|
# intreface for Operation #
|
82
65
|
###########################
|
data/lib/ppc/ext.rb
CHANGED
data/lib/ppc/operation.rb
CHANGED
@@ -4,12 +4,9 @@ module PPC
|
|
4
4
|
attr_accessor :id
|
5
5
|
|
6
6
|
def initialize( params )
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
else
|
11
|
-
@se = params[:se]
|
12
|
-
end
|
7
|
+
raise 'please specific a search engine' if params[:se].nil?
|
8
|
+
|
9
|
+
@se = params[:se]
|
13
10
|
@id = params[:id]
|
14
11
|
@auth = {
|
15
12
|
username: params[:username],
|
@@ -20,13 +17,11 @@ module PPC
|
|
20
17
|
}
|
21
18
|
# add support for qihu360
|
22
19
|
if @se == 'qihu'
|
23
|
-
raise "you are using qihu service, please enter api_key"
|
24
|
-
@auth[:api_key] = params[:api_key]
|
25
|
-
end
|
26
|
-
if @se == 'qihu' && params[:token].nil?
|
20
|
+
raise "you are using qihu service, please enter api_key" if params[:api_key].nil?
|
27
21
|
raise "you are using qihu service, please enter api_secret" if params[:api_secret].nil?
|
28
|
-
@auth[:
|
29
|
-
@auth[:
|
22
|
+
@auth[:api_key] = params[:api_key]
|
23
|
+
@auth[:api_secret] = params[:api_secret]
|
24
|
+
@auth[:token] = qihu_refresh_token if params[:token].nil?
|
30
25
|
end
|
31
26
|
end
|
32
27
|
|
@@ -35,7 +30,7 @@ module PPC
|
|
35
30
|
cipher_aes.encrypt
|
36
31
|
cipher_aes.key = @auth[:api_secret][0,16]
|
37
32
|
cipher_aes.iv = @auth[:api_secret][16,16]
|
38
|
-
encrypted = (cipher_aes.update(Digest::MD5.hexdigest(@auth[:password])) + cipher_aes.final).unpack('H*').join
|
33
|
+
encrypted = (cipher_aes.update(Digest::MD5.hexdigest( @auth[:password])) + cipher_aes.final).unpack('H*').join
|
39
34
|
url = "https://api.e.360.cn/account/clientLogin"
|
40
35
|
response = HTTParty.post(url,
|
41
36
|
:body => {
|
@@ -59,104 +54,86 @@ module PPC
|
|
59
54
|
eval "::PPC::API::#{@se.capitalize}::#{service.capitalize}"
|
60
55
|
end
|
61
56
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
ids.each do |id|
|
79
|
-
param[:id] = id
|
80
|
-
objs << class_obj.new( param )
|
81
|
-
end
|
82
|
-
|
83
|
-
return objs.length == 1 ? objs[0] : objs
|
57
|
+
def method_missing(method_name, *args, &block)
|
58
|
+
method = method_name.to_s
|
59
|
+
unit = self.class.to_s.downcase[/(account|plan|group|keyword|creative|sublink)/]
|
60
|
+
case method
|
61
|
+
when "info"
|
62
|
+
unit == "account" ? call( unit ).send( method, @auth ) : call( unit ).send( method, @auth, [@id].flatten )
|
63
|
+
when "get", "delete", "enable", "pause", "status", "quality"
|
64
|
+
call( unit ).send( method, @auth, [@id].flatten )
|
65
|
+
when "update"
|
66
|
+
call( unit ).send( method, @auth, [args[0].merge(id: @id)].flatten )
|
67
|
+
when "activate"
|
68
|
+
call( unit ).enable( @auth, [@id].flatten )
|
69
|
+
else
|
70
|
+
super
|
71
|
+
end
|
84
72
|
end
|
85
73
|
|
86
74
|
# +++++ Plan opeartion funcitons +++++ #
|
87
75
|
module Plan_operation
|
88
|
-
def get_plan( ids )
|
89
|
-
::PPC::Opeartion::get_obj( ids, 'plan')
|
90
|
-
end
|
91
76
|
|
92
|
-
def
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
77
|
+
def method_missing(method_name, *args, &block)
|
78
|
+
if method_name.to_s[/_plan$/]
|
79
|
+
call( "plan" ).send(method_name.to_s[/^(get|add|update|delete|enable|pause)/], @auth, [args].flatten )
|
80
|
+
else
|
81
|
+
super
|
82
|
+
end
|
98
83
|
end
|
99
84
|
|
100
|
-
def delete_plan( ids )
|
101
|
-
call('plan').delete(@auth,ids)
|
102
|
-
end
|
103
85
|
end
|
104
86
|
|
105
87
|
# +++++ Group opeartion funcitons +++++ #
|
106
88
|
module Group_operation
|
107
|
-
def get_group( ids )
|
108
|
-
::PPC::Opeartion::get_obj( ids, 'group')
|
109
|
-
end
|
110
89
|
|
111
|
-
def
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
90
|
+
def method_missing(method_name, *args, &block)
|
91
|
+
if method_name.to_s[/_group$/]
|
92
|
+
call( "group" ).send(method_name.to_s[/^(get|add|update|delete|enable|pause)/], @auth, [args].flatten )
|
93
|
+
else
|
94
|
+
super
|
95
|
+
end
|
117
96
|
end
|
118
97
|
|
119
|
-
def delete_group( ids )
|
120
|
-
call('group').delete( @auth, ids )
|
121
|
-
end
|
122
98
|
end
|
123
99
|
|
124
100
|
# +++++ Keyword opeartion funcitons +++++ #
|
125
101
|
module Keyword_operation
|
126
|
-
def get_keyword( ids )
|
127
|
-
::PPC::Opeartion::get_obj( ids, 'keyword')
|
128
|
-
end
|
129
|
-
|
130
|
-
def add_keyword( keywords )
|
131
|
-
call('keyword').add( @auth, keywords )
|
132
|
-
end
|
133
102
|
|
134
|
-
def
|
135
|
-
|
103
|
+
def method_missing(method_name, *args, &block)
|
104
|
+
if method_name.to_s[/_keyword$/]
|
105
|
+
call( "keyword" ).send(method_name.to_s[/^(get|add|update|delete|enable|pause)/], @auth, [args].flatten )
|
106
|
+
else
|
107
|
+
super
|
108
|
+
end
|
136
109
|
end
|
137
110
|
|
138
|
-
def delete_keyword( ids )
|
139
|
-
call('keyword').delete( @auth, ids )
|
140
|
-
end
|
141
111
|
end
|
142
112
|
|
143
113
|
# +++++ Creative opeartion funcitons +++++ #
|
144
114
|
module Creative_operation
|
145
|
-
def get_creative( ids )
|
146
|
-
::PPC::Opeartion::get_obj( ids, 'creative')
|
147
|
-
end
|
148
|
-
|
149
|
-
def add_creative( creatives )
|
150
|
-
call('creative').add( @auth, creatives )
|
151
|
-
end
|
152
115
|
|
153
|
-
def
|
154
|
-
|
116
|
+
def method_missing(method_name, *args, &block)
|
117
|
+
if method_name.to_s[/_creative$/]
|
118
|
+
call( "creative" ).send(method_name.to_s[/^(get|add|update|delete|enable|pause)/], @auth, [args].flatten )
|
119
|
+
else
|
120
|
+
super
|
121
|
+
end
|
155
122
|
end
|
156
123
|
|
157
|
-
|
158
|
-
|
124
|
+
end
|
125
|
+
|
126
|
+
# +++++ Sublink opeartion funcitons +++++ #
|
127
|
+
module Sublink_operation
|
128
|
+
|
129
|
+
def method_missing(method_name, *args, &block)
|
130
|
+
if method_name.to_s[/_sublink$/]
|
131
|
+
call( "sublink" ).send(method_name.to_s[/^(get|add|update|delete|enable|pause)/], @auth, [args].flatten )
|
132
|
+
else
|
133
|
+
super
|
134
|
+
end
|
159
135
|
end
|
136
|
+
|
160
137
|
end
|
161
138
|
|
162
139
|
end # Opeartion
|
@@ -172,4 +149,4 @@ require 'ppc/operation/group'
|
|
172
149
|
require 'ppc/operation/plan'
|
173
150
|
require 'ppc/operation/keyword'
|
174
151
|
require 'ppc/operation/creative'
|
175
|
-
|
152
|
+
require 'ppc/operation/sublink'
|
@@ -3,33 +3,24 @@ module PPC
|
|
3
3
|
class Account
|
4
4
|
include ::PPC::Operation
|
5
5
|
|
6
|
-
# self operations
|
7
|
-
def info
|
8
|
-
info = call('account').info(@auth)
|
9
|
-
@id = info[:result][:id] if @id == nil
|
10
|
-
return info
|
11
|
-
end
|
12
|
-
|
13
|
-
def update(account)
|
14
|
-
call('account').update(@auth,account)
|
15
|
-
end
|
16
|
-
|
17
|
-
# subobject(plan) operations
|
18
6
|
def plans
|
19
|
-
call(
|
7
|
+
call( "plan" ).all( @auth )
|
20
8
|
end
|
21
9
|
|
22
10
|
def plan_ids
|
23
|
-
call(
|
11
|
+
call( "plan" ).ids( @auth )
|
24
12
|
end
|
25
13
|
|
26
|
-
|
27
|
-
|
28
|
-
call( 'keyword' ).search_by_group_id( @auth, group_id )
|
14
|
+
def keywords( group_id )
|
15
|
+
call( "keyword" ).all( @auth, group_id )
|
29
16
|
end
|
30
17
|
|
31
|
-
def keyword_ids(group_id)
|
32
|
-
call(
|
18
|
+
def keyword_ids( group_id )
|
19
|
+
call( "keyword" ).ids( @auth, group_id )
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_rank( region, keyword )
|
23
|
+
call( "rank" ).getRank( @auth, region, keyword )
|
33
24
|
end
|
34
25
|
|
35
26
|
# plan operations
|
@@ -44,6 +35,9 @@ module PPC
|
|
44
35
|
# creative opeartions
|
45
36
|
include ::PPC::Operation::Creative_operation
|
46
37
|
|
38
|
+
# sublink opeartion
|
39
|
+
include ::PPC::Operation::Sublink_operation
|
40
|
+
|
47
41
|
# report operations
|
48
42
|
include ::PPC::Operation::Report
|
49
43
|
|
@@ -3,26 +3,6 @@ module PPC
|
|
3
3
|
class Creative
|
4
4
|
include ::PPC::Operation
|
5
5
|
|
6
|
-
def info()
|
7
|
-
call( 'creative' ).get( @auth, @id )
|
8
|
-
end
|
9
|
-
|
10
|
-
def update( type )
|
11
|
-
call( 'creative' ).update( @auth, type.merge( id:@id) )
|
12
|
-
end
|
13
|
-
|
14
|
-
def activate()
|
15
|
-
call( 'creative' ).activate( @auth, @id )
|
16
|
-
end
|
17
|
-
|
18
|
-
def status()
|
19
|
-
call( 'creative' ).status( @auth, @id )
|
20
|
-
end
|
21
|
-
|
22
|
-
def delete()
|
23
|
-
call( 'creative' ).delete( @auth, @id )
|
24
|
-
end
|
25
|
-
|
26
6
|
end
|
27
7
|
end
|
28
8
|
end
|
data/lib/ppc/operation/group.rb
CHANGED
@@ -2,31 +2,29 @@ module PPC
|
|
2
2
|
module Operation
|
3
3
|
class Group
|
4
4
|
include ::PPC::Operation
|
5
|
-
|
6
|
-
def
|
7
|
-
call(
|
5
|
+
|
6
|
+
def keywords
|
7
|
+
call( "keyword" ).all( @auth, [@id].flatten )
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
11
|
-
|
12
|
-
call('group').update(@auth, info)
|
10
|
+
def keyword_ids
|
11
|
+
call( "keyword" ).ids( @auth, [@id].flatten )
|
13
12
|
end
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
call( 'keyword' ).search_by_group_id( @auth, @id )
|
14
|
+
def creatives
|
15
|
+
call( "creative" ).all( @auth, [@id].flatten )
|
18
16
|
end
|
19
17
|
|
20
|
-
def
|
21
|
-
call(
|
18
|
+
def creative_ids
|
19
|
+
call( "creative" ).ids( @auth, [@id].flatten )
|
22
20
|
end
|
23
21
|
|
24
|
-
def
|
25
|
-
call(
|
22
|
+
def sublinks
|
23
|
+
call( "sublink" ).all( @auth, [@id].flatten )
|
26
24
|
end
|
27
25
|
|
28
|
-
def
|
29
|
-
call(
|
26
|
+
def sublink_ids
|
27
|
+
call( "sublink" ).ids( @auth, [@id].flatten )
|
30
28
|
end
|
31
29
|
|
32
30
|
# keyword opeartion
|
@@ -35,25 +33,18 @@ module PPC
|
|
35
33
|
# creative opeartion
|
36
34
|
include ::PPC::Operation::Creative_operation
|
37
35
|
|
36
|
+
# sublink opeartion
|
37
|
+
include ::PPC::Operation::Sublink_operation
|
38
|
+
|
38
39
|
# Overwrite add method to provide more function
|
39
40
|
def add_keyword( keywords )
|
40
|
-
call(
|
41
|
+
call( "keyword" ).add( @auth, keywords.map{|keyword| keyword.merge(group_id: @id)} )
|
41
42
|
end
|
42
43
|
|
43
44
|
def add_creative( creatives )
|
44
|
-
call(
|
45
|
+
call( "creative" ).add( @auth, creatives.map{|creative| creative.merge(group_id: @id)} )
|
45
46
|
end
|
46
47
|
|
47
|
-
# Auxilary function
|
48
|
-
private
|
49
|
-
def add_group_id( types )
|
50
|
-
types = [types] unless types.is_a? Array
|
51
|
-
types.each do |type|
|
52
|
-
type.merge!( {group_id:@id} )
|
53
|
-
end
|
54
|
-
return types
|
55
|
-
end
|
56
|
-
|
57
48
|
end # Group
|
58
49
|
end # Operation
|
59
50
|
end # PPC
|
@@ -3,33 +3,6 @@ module PPC
|
|
3
3
|
class Keyword
|
4
4
|
include ::PPC::Operation
|
5
5
|
|
6
|
-
def info()
|
7
|
-
call( 'keyword' ).get( @auth, @id )
|
8
|
-
end
|
9
|
-
|
10
|
-
def update( type )
|
11
|
-
type.merge(id: @id) if type.is_a? Hash
|
12
|
-
call( 'keyword' ).update( @auth, type )
|
13
|
-
end
|
14
|
-
|
15
|
-
# Todo: Implement Activate method in Sogou API
|
16
|
-
def activate()
|
17
|
-
call( 'keyword' ).activate( @auth, @id )
|
18
|
-
end
|
19
|
-
|
20
|
-
def status()
|
21
|
-
call( 'keyword' ).status( @auth, @id )
|
22
|
-
end
|
23
|
-
|
24
|
-
def quality()
|
25
|
-
call( 'keyword' ).quality( @auth, @id )
|
26
|
-
end
|
27
|
-
|
28
|
-
def delete( ids = nil )
|
29
|
-
ids ||= @id
|
30
|
-
call( 'keyword' ).delete( @auth, ids )
|
31
|
-
end
|
32
|
-
|
33
6
|
end
|
34
7
|
end
|
35
8
|
end
|
data/lib/ppc/operation/plan.rb
CHANGED
@@ -4,43 +4,55 @@ module PPC
|
|
4
4
|
class Plan
|
5
5
|
include ::PPC::Operation
|
6
6
|
|
7
|
-
def
|
8
|
-
call(
|
7
|
+
def groups
|
8
|
+
call( "group" ).all( @auth, [@id].flatten )
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
12
|
-
call(
|
11
|
+
def group_ids
|
12
|
+
call( "group" ).ids( @auth, [@id].flatten )
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
16
|
-
|
17
|
-
result[:result] = result[:result][0][:groups]
|
18
|
-
return result
|
15
|
+
def keywords( group_ids )
|
16
|
+
call( "keyword" ).all( @auth, [group_ids].flatten )
|
19
17
|
end
|
20
18
|
|
21
|
-
def group_ids
|
22
|
-
|
23
|
-
|
24
|
-
|
19
|
+
def keyword_ids( group_ids )
|
20
|
+
call( "keyword" ).ids( @auth, [group_ids].flatten )
|
21
|
+
end
|
22
|
+
|
23
|
+
def creatives( group_ids )
|
24
|
+
call( "creative" ).all( @auth, [group_ids].flatten )
|
25
|
+
end
|
26
|
+
|
27
|
+
def creative_ids( group_ids )
|
28
|
+
call( "creative" ).ids( @auth, [group_ids].flatten )
|
29
|
+
end
|
30
|
+
|
31
|
+
def sublinks( group_ids )
|
32
|
+
call( "sublink" ).all( @auth, [group_ids].flatten )
|
33
|
+
end
|
34
|
+
|
35
|
+
def sublink_ids( group_ids )
|
36
|
+
call( "sublink" ).ids( @auth, [group_ids].flatten )
|
25
37
|
end
|
26
38
|
|
27
39
|
# group opeartion
|
28
40
|
include ::PPC::Operation::Group_operation
|
29
41
|
|
42
|
+
# keyword opeartion
|
43
|
+
include ::PPC::Operation::Keyword_operation
|
44
|
+
|
45
|
+
# creative opeartion
|
46
|
+
include ::PPC::Operation::Creative_operation
|
47
|
+
|
48
|
+
# sublink opeartion
|
49
|
+
include ::PPC::Operation::Sublink_operation
|
50
|
+
|
30
51
|
# Overwirte add_group method to provide more function
|
31
52
|
def add_group( groups )
|
32
|
-
call(
|
53
|
+
call( "group" ).add( @auth, groups.map{|group| group.merge(plan_id: @id)} )
|
33
54
|
end
|
34
55
|
|
35
|
-
# Auxilary function
|
36
|
-
private
|
37
|
-
def add_plan_id( types )
|
38
|
-
types = [types] unless types.is_a? Array
|
39
|
-
types.each do |type|
|
40
|
-
type.merge!({plan_id:@id})
|
41
|
-
end
|
42
|
-
return types
|
43
|
-
end
|
44
56
|
|
45
57
|
end # class plan
|
46
58
|
end # mudole Opeartion
|