ppc 1.3.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +21 -339
  3. data/README.md +46 -28
  4. data/Rakefile +1 -0
  5. data/lib/ppc.rb +1 -1
  6. data/lib/ppc/api.rb +18 -14
  7. data/lib/ppc/api/baidu.rb +5 -14
  8. data/lib/ppc/api/baidu/account.rb +28 -23
  9. data/lib/ppc/api/baidu/bulk.rb +1 -1
  10. data/lib/ppc/api/baidu/creative.rb +47 -86
  11. data/lib/ppc/api/baidu/group.rb +43 -74
  12. data/lib/ppc/api/baidu/keyword.rb +73 -166
  13. data/lib/ppc/api/baidu/phone_new_creative.rb +8 -7
  14. data/lib/ppc/api/baidu/plan.rb +51 -34
  15. data/lib/ppc/api/baidu/report.rb +9 -29
  16. data/lib/ppc/api/qihu.rb +7 -111
  17. data/lib/ppc/api/qihu/account.rb +31 -25
  18. data/lib/ppc/api/qihu/bulk.rb +1 -2
  19. data/lib/ppc/api/qihu/creative.rb +57 -74
  20. data/lib/ppc/api/qihu/group.rb +40 -63
  21. data/lib/ppc/api/qihu/keyword.rb +58 -74
  22. data/lib/ppc/api/qihu/plan.rb +52 -32
  23. data/lib/ppc/api/qihu/rank.rb +11 -10
  24. data/lib/ppc/api/qihu/report.rb +41 -94
  25. data/lib/ppc/api/qihu/sublink.rb +44 -41
  26. data/lib/ppc/api/sm.rb +3 -12
  27. data/lib/ppc/api/sm/account.rb +20 -19
  28. data/lib/ppc/api/sm/creative.rb +36 -50
  29. data/lib/ppc/api/sm/group.rb +40 -61
  30. data/lib/ppc/api/sm/keyword.rb +44 -102
  31. data/lib/ppc/api/sm/phone_new_creative.rb +9 -8
  32. data/lib/ppc/api/sm/plan.rb +36 -26
  33. data/lib/ppc/api/sm/report.rb +5 -24
  34. data/lib/ppc/api/sogou.rb +5 -55
  35. data/lib/ppc/api/sogou/account.rb +17 -17
  36. data/lib/ppc/api/sogou/creative.rb +52 -75
  37. data/lib/ppc/api/sogou/group.rb +44 -91
  38. data/lib/ppc/api/sogou/keyword.rb +60 -143
  39. data/lib/ppc/api/sogou/plan.rb +37 -23
  40. data/lib/ppc/api/sogou/report.rb +2 -19
  41. data/lib/ppc/ext.rb +0 -8
  42. data/lib/ppc/operation.rb +60 -83
  43. data/lib/ppc/operation/account.rb +13 -19
  44. data/lib/ppc/operation/creative.rb +0 -20
  45. data/lib/ppc/operation/group.rb +18 -27
  46. data/lib/ppc/operation/keyword.rb +0 -27
  47. data/lib/ppc/operation/plan.rb +34 -22
  48. data/lib/ppc/operation/report.rb +4 -4
  49. data/lib/ppc/operation/sublink.rb +8 -0
  50. data/ppc.gemspec +5 -5
  51. metadata +16 -10
  52. data/lib/ppc/api/shenma.rb +0 -64
  53. data/lib/ppc/api/shenma/report.rb +0 -135
@@ -5,116 +5,69 @@ module PPC
5
5
  class Group< Sogou
6
6
  Service = 'CpcGrp'
7
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
- ]
8
+ GroupType = {
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
+ "plan_id" => :cpc_plan_id,
19
+ "id" => :cpc_grp_id,
20
+ "plan_name" => :cpc_plan_name,
21
+ "name" => :cpc_grp_name,
22
+ "price" => :max_price,
23
+ }
24
+ @map = GroupType
19
25
 
20
- def self.ids( auth )
21
- """
22
- @return : Array of cpcPlanGrpIdTypes
23
- """
24
- response = request( auth, Service , "getAllCpcGrpId" )
25
- #此处返回值与key与开发文档不同
26
- process( response, 'cpcPlanGrpIds' ){ |x| make_planGroupIds( x ) }
26
+ def self.info( auth, ids)
27
+ response = request(auth, Service, "getCpcGrpByCpcGrpId", {cpcGrpIds: ids} )
28
+ process( response, 'cpc_grp_types' ){ |x| reverse_type(x)[0] }
29
+ end
30
+
31
+ def self.all( auth, plan_ids )
32
+ response = request( auth, Service ,"getCpcGrpByCpcPlanId", {cpcPlanIds: plan_ids} )
33
+ process( response, 'cpc_plan_grps' ){ |x| reverse_type( x[:cpc_grp_types] ) }
34
+ end
35
+
36
+ def self.ids( auth, plan_ids )
37
+ response = request( auth, Service ,"getCpcGrpIdByCpcPlanId", {cpcPlanIds: plan_ids} )
38
+ process( response, 'cpcPlanGrpIds' ){ |x| reverse_type( x ) }
27
39
  end
28
40
 
29
41
  def self.get( auth, ids )
30
- ids = [ ids ] unless ids.is_a? Array
31
- body = { cpcGrpIds: ids }
32
- response = request(auth, Service, "getCpcGrpByCpcGrpId",body )
33
- process( response, 'cpcGrpTypes' ){ |x| reverse_type(x) }
42
+ response = request(auth, Service, "getCpcGrpByCpcGrpId", {cpcGrpIds: ids} )
43
+ process( response, 'cpc_grp_types' ){ |x| reverse_type(x) }
34
44
  end
35
45
 
36
46
  def self.add( auth, groups )
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
-
47
+ body = {cpcGrpTypes: make_type( groups ) }
45
48
  response = request( auth, Service, "addCpcGrp", body )
46
- process( response, 'cpcGrpTypes' ){ |x| reverse_type(x) }
49
+ process( response, 'cpc_grp_types' ){ |x| reverse_type(x) }
47
50
  end
48
51
 
49
52
  def self.update( auth, groups )
50
- """
51
- @ input : one or list of AdgroupType
52
- @ output : list of AdgroupType
53
- """
54
- cpcGrpTypes = make_type( groups )
55
- body = {cpcGrpTypes: cpcGrpTypes}
56
-
53
+ body = {cpcGrpTypes: make_type( groups )}
57
54
  response = request( auth, Service, "updateCpcGrp",body )
58
- process( response, 'cpcGrpTypes' ){ |x| reverse_type(x) }
55
+ process( response, 'cpc_grp_types' ){ |x| reverse_type(x) }
59
56
  end
60
57
 
61
58
  def self.delete( auth, ids )
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, '' ){ |x| x }
69
- end
70
-
71
- def self.search_by_plan_id( auth, ids )
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' ){ |x| make_planGroups( x ) }
77
- end
78
-
79
- def self.search_id_by_plan_id( auth, ids )
80
- ids = [ ids ] unless ids.is_a? Array
81
- body = { cpcPlanIds: ids }
82
- response = request( auth, Service ,"getCpcGrpIdByCpcPlanId", body )
83
- process( response, 'cpcPlanGrpIds' ){ |x| make_planGroupIds( x ) }
59
+ response = request( auth, Service,"deleteCpcGrp", {cpcGrpIds: ids} )
60
+ process( response, '' ){ |x| x }
84
61
  end
85
62
 
86
- private
87
- def self.make_planGroupIds( cpcPlanGrpIdTypes )
88
- """
89
- Transfer Sogou API to PPC API
90
- Item: cpc_plan_group_ids
91
- """
92
- cpcPlanGrpIdTypes = [cpcPlanGrpIdTypes] unless cpcPlanGrpIdTypes.is_a? Array
93
- planGroupIds = []
94
- cpcPlanGrpIdTypes.each do |cpcPlanGrpIdType|
95
- planGroupId = {}
96
- planGroupId[:plan_id] = cpcPlanGrpIdType[:cpc_plan_id]
97
- planGroupId[:group_ids] = cpcPlanGrpIdType[:cpc_grp_ids]
98
- planGroupIds << planGroupId
99
- end
100
- return planGroupIds
63
+ def self.enable( auth, ids )
64
+ groups = ids.map{|id| {id: id, pause: false} }
65
+ self.update( auth, groups )
101
66
  end
102
67
 
103
- private
104
- def self.make_planGroups( cpcPlanGrpTypes )
105
- """
106
- Transfer Sogou API to PPC API
107
- """
108
- # 多加一行change成array
109
- cpcPlanGrpTypes = [cpcPlanGrpTypes] unless cpcPlanGrpTypes.is_a? Array
110
- planGroups = []
111
- cpcPlanGrpTypes.each do |cpcPlanGrpType|
112
- planGroup = {}
113
- planGroup[:plan_id] = cpcPlanGrpType[:cpc_plan_id]
114
- planGroup[:groups] = reverse_type( cpcPlanGrpType[:cpc_grp_types] )
115
- planGroups << planGroup
116
- end
117
- return planGroups
68
+ def self.pause( auth, ids )
69
+ groups = ids.map{|id| {id: id, pause: true} }
70
+ self.update( auth, groups )
118
71
  end
119
72
 
120
73
  end # class group
@@ -8,178 +8,95 @@ module PPC
8
8
  class Keyword< Sogou
9
9
  Service = 'Cpc'
10
10
 
11
- #Match_type = { 'exact' => 0, 'wide' => 1,0 => 'exact', 1 => 'wide' }
12
- Match_type = { 'exact' => 0, 'phrase' => 2, 'wide' => 1,'0' => 'exact', '2' => 'phrase', '1' => 'wide' }
13
-
14
- @map = [
15
- [:id,:cpcId],
16
- [:group_id,:cpcGrpId],
17
- [:keyword,:cpc],
18
- [:price,:price],
19
- [:pc_destination,:visitUrl],
20
- [:mobile_destination,:mobileVisitUrl],
21
- [:match_type,:matchType],
22
- [:pause,:pause],
23
- [:status,:status],
24
- [:quality,:cpcQuality]
25
- ]
26
- @quality_map = [
27
- [:id,:cpcId],
28
- [:quality,:cpcQuality]
29
- ]
11
+ Match_type = { 'exact' => 0, 'phrase' => 2, 'wide' => 1,'0' => 'exact', '2' => 'phrase', '1' => 'wide' }
12
+ @match_types = Match_type
13
+ KeywordType = {
14
+ id: :cpcId,
15
+ group_id: :cpcGrpId,
16
+ keyword: :cpc,
17
+ price: :price,
18
+ pc_destination: :visitUrl,
19
+ mobile_destination: :mobileVisitUrl,
20
+ match_type: :matchType,
21
+ pause: :pause,
22
+ status: :status,
23
+ quality: :cpcQuality,
24
+ "group_id" => :cpc_grp_id,
25
+ "keyword_ids" => :cpc_ids,
26
+ "keywords" => :cpc_types,
27
+ "id" => :cpc_id,
28
+ "pc_destination" => :visit_url,
29
+ "quality" => :cpc_quality,
30
+ "mobile_destination" => :mobile_visit_url,
31
+ }
32
+ @map = KeywordType
30
33
 
31
- @status_map = [
32
- [:id,:cpcId],
33
- [:status,:status]
34
- ]
34
+ @quality_map = {
35
+ id: :cpcId,
36
+ quality: :cpcQuality,
37
+ }
38
+
39
+ @status_map = {
40
+ id: :cpcId,
41
+ status: :status,
42
+ }
43
+
44
+ def self.info( auth, ids )
45
+ response = request( auth, Service, 'getCpcByCpcId', {cpcIds: ids} )
46
+ process(response, 'cpcTypes'){|x| reverse_type( x )[0] }
47
+ end
48
+
49
+ def self.all( auth, ids )
50
+ response = request( auth, Service, "getCpcByCpcGrpId", {cpcGrpIds: ids} )
51
+ process(response, 'cpcGrpCpcs'){|x| ids.count == 1 ? reverse_type(x[:cpc_types]) : x.map{|y| reverse_type(y[:cpc_types])}.flatten }
52
+ end
53
+
54
+ def self.ids( auth, ids )
55
+ response = request( auth, Service, "getCpcIdByCpcGrpId", {cpcGrpIds: ids} )
56
+ process(response, 'cpcGrpCpcIds'){|x| reverse_type( x ) }
57
+ end
35
58
 
36
- # 后面改成info方法
37
59
  def self.get( auth, ids )
38
- '''
39
- getCpcByCpcId
40
- '''
41
- ids = [ ids ] unless ids.is_a? Array
42
- body = { cpcIds: ids}
43
- response = request( auth, Service, 'getCpcByCpcId', body )
60
+ response = request( auth, Service, 'getCpcByCpcId', {cpcIds: ids} )
44
61
  process(response, 'cpcTypes'){|x| reverse_type( x ) }
45
62
  end
46
63
 
47
64
  def self.add( auth, keywords )
48
- '''
49
- '''
50
- cpcTypes = make_type( keywords )
51
- body = { cpcTypes: cpcTypes }
65
+ body = { cpcTypes: make_type( keywords ) }
52
66
  response = request( auth, Service, "addCpc", body )
53
67
  process(response, 'cpcTypes'){|x| reverse_type(x) }
54
68
  end
55
69
 
56
70
  def self.update( auth, keywords )
57
- '''
58
- '''
59
- cpcTypes = make_type( keywords )
60
- body = { cpcTypes: cpcTypes }
71
+ body = { cpcTypes: make_type( keywords ) }
61
72
  response = request( auth, Service, "updateCpc", body )
62
73
  process(response, 'cpcTypes'){|x| reverse_type(x) }
63
74
  end
64
75
 
65
76
  def self.delete( auth, ids )
66
- """
67
- """
68
- ids = [ ids ] unless ids.is_a? Array
69
- body = { cpcIds: ids}
70
- response = request( auth, Service, 'deleteCpc', body )
77
+ response = request( auth, Service, 'deleteCpc', {cpcIds: ids} )
71
78
  process(response, ''){|x| x }
72
79
  end
73
80
 
74
- def self.search_by_group_id( auth, group_ids )
75
- """
76
- getKeywordByGroupIds
77
- @input: list of group id
78
- @output: list of groupKeyword
79
- """
80
- group_ids = [ group_ids ] unless group_ids.is_a? Array
81
- body = { cpcGrpIds: group_ids }
82
- response = request( auth, Service, "getCpcByCpcGrpId", body )
83
- process(response, 'cpcGrpCpcs'){|x| make_groupKeywords( x ) }
81
+ def self.enable( auth, ids )
82
+ keywords = ids.map{|id| {id: id, pause: false} }
83
+ self.update( auth, keywords )
84
84
  end
85
85
 
86
- def self.search_id_by_group_id( auth, group_ids )
87
- group_ids = [ group_ids ] unless group_ids.is_a? Array
88
- body = { cpcGrpIds: group_ids }
89
- response = request( auth, Service, "getCpcIdByCpcGrpId", body )
90
- process(response, 'cpcGrpCpcIds'){|x| make_groupKeywordIds( x ) }
86
+ def self.pause( auth, ids )
87
+ keywords = ids.map{|id| {id: id, pause: true} }
88
+ self.update( auth, keywords )
91
89
  end
92
90
 
93
91
  # sogou的keyword服务不提供质量度和状态,从getInfo方法中查询
94
92
  def self.status( auth, ids )
95
- '''
96
- Return [ { id: id, status: status} ... ]
97
- '''
98
- ids = [ ids ] unless ids.is_a? Array
99
- body = { cpcIds: ids}
100
- response = request( auth, Service, 'getCpcByCpcId', body )
101
- process(response, 'cpcTypes'){ |x| reverse_type(x, @status_map) }
93
+ response = request( auth, Service, 'getCpcByCpcId', {cpcIds: ids} )
94
+ process(response, 'cpcTypes'){|x| reverse_type(x, @status_map) }
102
95
  end
103
96
 
104
97
  def self.quality( auth ,ids )
105
- '''
106
- Return [ { id: id, quality: quality} ... ]
107
- '''
108
- ids = [ ids ] unless ids.is_a? Array
109
- body = { cpcIds: ids}
110
- response = request( auth, Service, 'getCpcByCpcId', { cpcIds: ids} )
111
- process(response, 'cpcTypes'){ |x| reverse_type(x, @quality_map) }
112
- end
113
-
114
- private
115
- def self.make_groupKeywordIds( cpcGrpCpcIdTypes )
116
- """
117
- Transfer Sogou API to PPC API
118
- """
119
- cpcGrpCpcIdTypes = [cpcGrpCpcIdTypes] unless cpcGrpCpcIdTypes.is_a? Array
120
- group_keyword_ids = []
121
- cpcGrpCpcIdTypes.each do |cpcGrpCpcIdType|
122
- group_keyword_id = { }
123
- group_keyword_id[:group_id] = cpcGrpCpcIdType[:cpc_grp_id]
124
- group_keyword_id[:keyword_ids] = cpcGrpCpcIdType[:cpc_ids]
125
- group_keyword_ids << group_keyword_id
126
- end
127
- return group_keyword_ids
128
- end
129
-
130
- private
131
- def self.make_groupKeywords( cpcGrpCpcTypes )
132
- cpcGrpCpcTypes = [cpcGrpCpcTypes] unless cpcGrpCpcTypes.is_a? Array
133
- group_keywords = []
134
- cpcGrpCpcTypes.each do |cpcGrpCpcType|
135
- group_keyword = {}
136
- group_keyword[:group_id] = cpcGrpCpcType[:cpc_grp_id]
137
- group_keyword[:keywords] = reverse_type( cpcGrpCpcType[:cpc_types] )
138
- group_keywords << group_keyword
139
- end
140
- return group_keywords
141
- end
142
-
143
- # Override
144
- def self.make_type( params, map = @map)
145
- params = [ params ] unless params.is_a? Array
146
- types = []
147
- params.each do |param|
148
- type = {}
149
- map.each do |key|
150
- # 增加对matchtype的自动转换
151
- if key[0] == :match_type
152
- value = param[ key[0] ]
153
- type[ key[1] ] = Match_type[ value ] if value
154
- else
155
- value = param[ key[0] ]
156
- type[ key[1] ] = value if value != nil
157
- end
158
- end
159
- types << type
160
- end
161
- return types
162
- end
163
-
164
- # Overwrite
165
- def self.reverse_type( types, map = @map )
166
- types = [ types ] unless types.is_a? Array
167
- params = []
168
- types.each do |type|
169
- param = {}
170
- # 增加对matchtype的自动转换
171
- map.each do |key|
172
- if key[0] == :match_type
173
- value = type[ key[1].to_s.snake_case.to_sym]
174
- param[ key[0] ] = Match_type[ value ] if value
175
- else
176
- value = type[ key[1].to_s.snake_case.to_sym ]
177
- param[ key[0] ] = value if value != nil
178
- end
179
- end # map.each
180
- params << param
181
- end # types.each
182
- return params
98
+ response = request( auth, Service, 'getCpcByCpcId', {cpcIds: ids} )
99
+ process(response, 'cpcTypes'){|x| reverse_type(x, @quality_map) }
183
100
  end
184
101
 
185
102
  end # keyword
@@ -4,23 +4,31 @@ module PPC
4
4
  class Plan< Sogou
5
5
  Service = 'CpcPlan'
6
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
- ]
7
+ PlanType = {
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
+ "id" => :cpc_plan_id,
24
+ "name" => :cpc_plan_name,
25
+ }
26
+ @map = PlanType
27
+
28
+ def self.info( auth, ids )
29
+ response = request( auth, Service, 'getCpcPlanByCpcPlanId', {cpcPlanIds: ids} )
30
+ process( response, 'cpcPlanTypes' ){ |x| reverse_type(x)[0] }
31
+ end
24
32
 
25
33
  def self.all( auth )
26
34
  response = request( auth, Service, 'getAllCpcPlan' )
@@ -33,9 +41,7 @@ module PPC
33
41
  end
34
42
 
35
43
  def self.get( auth, ids )
36
- ids = [ ids ] unless ids.is_a? Array
37
- body = { cpcPlanIds: ids }
38
- response = request( auth, Service, 'getCpcPlanByCpcPlanId', body)
44
+ response = request( auth, Service, 'getCpcPlanByCpcPlanId', {cpcPlanIds: ids} )
39
45
  process( response, 'cpcPlanTypes' ){ |x| reverse_type(x) }
40
46
  end
41
47
 
@@ -54,11 +60,19 @@ module PPC
54
60
  end
55
61
 
56
62
  def self.delete(auth, ids )
57
- ids = [ ids ] unless ids.class == Array
58
- body = { cpcPlanIds: ids }
59
- response = request( auth, Service, 'deleteCpcPlan', body)
63
+ response = request( auth, Service, 'deleteCpcPlan', {cpcPlanIds: ids} )
60
64
  process( response, '' ){ |x| x }
61
65
  end
66
+
67
+ def self.enable( auth, ids )
68
+ plans = ids.map{|id| {id: id, pause: false} }
69
+ self.update( auth, plans )
70
+ end
71
+
72
+ def self.pause( auth, ids )
73
+ plans = ids.map{|id| {id: id, pause: true} }
74
+ self.update( auth, plans )
75
+ end
62
76
 
63
77
  end # Service
64
78
  end # baidu