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,66 +5,69 @@ module PPC
5
5
  class Sublink< Qihu
6
6
  Service = 'sublink'
7
7
 
8
- @map = [
9
- [:id,:id] ,
10
- [:group_id, :groupId],
11
- [:anchor,:text],
12
- [:url, :link],
13
- [:image, :image],
14
- [:status, :status]
15
- ]
8
+ SublinkType = {
9
+ id: :id,
10
+ group_id: :groupId,
11
+ anchor: :text,
12
+ url: :link,
13
+ image: :image,
14
+ pause: :sysStatus,
15
+ status: :status,
16
+ add_time: :addTime,
17
+ update_time: :updateTime,
18
+ cause: :cause,
19
+ }
20
+ @map = SublinkType
21
+
22
+ def self.info( auth, ids )
23
+ response = request( auth, Service, 'getInfoByIdList', { idList: ids } )
24
+ process( response, 'sublinkList'){ |x| reverse_type( x )[0] }
25
+ end
26
+
27
+ def self.all( auth, group_ids )
28
+ results = self.ids( auth, group_ids )
29
+ return results unless results[:succ]
30
+ self.get( auth , results[:result] )
31
+ end
32
+
33
+ def self.ids( auth, group_ids )
34
+ response = request( auth, Service, 'getIdListByGroupIdList', {groupIdList: group_ids} )
35
+ process( response, 'sublinkIdListList' ){ |x| x.map(&:to_i) }
36
+ end
16
37
 
17
38
  def self.get( auth, ids )
18
- body = { 'idList' => to_json_string( ids ) }
19
- response = request( auth, Service, 'getInfoByIdList', body )
20
- process( response, 'sublinkList'){ |x| reverse_type( x['item'] ) }
39
+ response = request( auth, Service, 'getInfoByIdList', { idList: ids } )
40
+ process( response, 'sublinkList'){ |x| reverse_type( x ) }
21
41
  end
22
42
 
23
43
  def self.add( auth, sublinks )
24
- sublink_types = make_type( sublinks ).to_json
25
- body = { 'sublinks' => sublink_types}
26
- response = request( auth, Service, 'add', body )
27
- process( response, 'sublinkIdList'){ |x| to_id_hash_list( x['item'] ) }
44
+ response = request( auth, Service, 'add', { sublinks: make_type( sublinks ) } )
45
+ process( response, 'sublinkIdList'){ |x| x.map{|id| {id: id} } }
28
46
  end
29
47
 
30
48
  def self.delete( auth, ids )
31
- ids = to_json_string( ids )
32
- body = { 'idList' => ids }
33
- response = request( auth, Service, 'deleteByIdList', body )
49
+ response = request( auth, Service, 'deleteByIdList', { idList: ids } )
34
50
  process( response, 'affectedRecords' ){ |x|x }
35
51
  end
36
52
 
37
- # helper function for self.add() method
38
- private
39
- def self.to_id_hash_list( str )
40
- reuturn [] if str == nil
41
- str = [str] unless str.is_a?Array
42
- x= []
43
- str.each{ |i| x << { id: i.to_i } }
44
- return x
45
- end
46
-
47
53
  def self.update( auth, sublinks )
48
- sublink_types = make_type( sublinks ).to_json
49
- body = { 'sublinks' => sublink_types}
50
- response = request( auth, Service, 'update', body )
54
+ response = request( auth, Service, 'update', { sublinks: make_type( sublinks ) } )
51
55
  process( response, 'affectedRecords', 'failKeywordIds' ){ |x| x }
52
56
  end
53
57
 
54
- # 对update的再封装实现activate方法,未测试
55
- def self.activate( auth, ids )
56
- sublinks = []
57
- ids.each{ |id| sublinks << { id: id, status:'enable'} }
58
- update( auth, sublinks )
59
- end
60
-
61
58
  def self.delete( auth, ids )
62
- ids = to_json_string( ids )
63
- body = { 'idList' => ids }
64
- response = request( auth, Service, 'deleteByIdList', body )
59
+ response = request( auth, Service, 'deleteByIdList', { idList: ids } )
65
60
  process( response, 'affectedRecords' ){ |x|x }
66
61
  end
67
62
 
63
+ def self.enable( auth, ids )
64
+ self.update( auth, ids.map{ |id| { id: id, status: 'enable'} } )
65
+ end
66
+
67
+ def self.pause( auth, ids )
68
+ self.update( auth, ids.map{ |id| { id: id, status: 'pause'} } )
69
+ end
70
+
68
71
  end
69
72
  end
70
73
  end
@@ -30,21 +30,12 @@ module PPC
30
30
  result = {}
31
31
  result[:succ] = response['header']['desc'] =='success'
32
32
  result[:failure] = response['header']['failures']
33
- if !response['body'].nil? && response['body'][key]
34
- result[:result] = func[ response['body'][key] ]
35
- end
36
- result[:no_quota] = is_no_quota(response['header']['failures'], '8501')
33
+ result[:result] = func[ response['body'][key] ] rescue nil
34
+ result[:no_quota] = (response['header']['failures']['code'] == '8501') rescue false
35
+ result[:rquota] = response["header"]["leftQuota"] rescue 0
37
36
  result
38
37
  end # process
39
38
 
40
- def self.reverse_type( types, maps = @map )
41
- types = [ types ] unless types.is_a? Array
42
- types.map do |item|
43
- maps.each{|m| item.filter_and_replace_key(m[0],m[1].to_s)}
44
- item
45
- end
46
- end
47
-
48
39
  end # Sm
49
40
  end # API
50
41
  end # PPC
@@ -4,25 +4,27 @@ module PPC
4
4
  class Account < Sm
5
5
  Service = 'account'
6
6
 
7
- @map = [
8
- [:id,:userId],
9
- [:balance,:balance],
10
- [:cost,:cost],
11
- [:payment,:payment],
12
- [:budget_type,:budgetType],
13
- [:budget,:budget],
14
- [:region,:regionTarget],
15
- [:exclude_ip,:excludeIp],
16
- [:open_domains,:openDomains],
17
- [:reg_domain,:regDomain],
18
- [:offline_time,:budgetOfflineTime],
19
- [:weekly_budget,:weeklyBudget]
20
- ]
7
+ AccountType = {
8
+ id: :userId,
9
+ name: :userName,
10
+ balance: :balance,
11
+ cost: :cost,
12
+ payment: :payment,
13
+ budget_type: :budgetType,
14
+ budget: :budget,
15
+ region: :regionTarget,
16
+ exclude_ip: :excludeIp,
17
+ open_domains: :openDomains,
18
+ reg_domain: :regDomain,
19
+ offline_time: :budgetOfflineTime,
20
+ weekly_budget: :weeklyBudget,
21
+ status: :userStat,
22
+ }
23
+ @map = AccountType
21
24
 
22
25
  def self.info( auth )
23
26
  response = request(auth, Service, 'getAccount', {requestData: ["account_all"]})
24
- p response
25
- return process( response, 'accountInfoType' ){ |x|reverse_type(x)[0] }
27
+ process( response, 'accountInfoType' ){ |x|reverse_type(x)[0] }
26
28
  end
27
29
 
28
30
  def self.update(auth, param = {} )
@@ -32,10 +34,9 @@ module PPC
32
34
  @return : account info_type
33
35
  """
34
36
  # for account service, there is not bulk operation
35
- infoType = make_type( param )[0]
36
- body = { accountInfoType: infoType }
37
+ body = { accountInfoType: make_type( param )[0] }
37
38
  response = request(auth, Service, 'updateAccount', body)
38
- return process( response, 'accountInfoType' ){ |x|reverse_type(x)[0] }
39
+ process( response, 'accountInfoType' ){ |x|reverse_type(x)[0] }
39
40
  end
40
41
 
41
42
  end
@@ -5,16 +5,34 @@ module PPC
5
5
  class Creative< Sm
6
6
  Service = 'creative'
7
7
 
8
- @map =[
9
- [:id, :creativeId],
10
- [:group_id, :adgroupId],
11
- [:title, :title],
12
- [:description1, :description1],
13
- [:pause, :pause],
14
- [:mobile_destination, :destinationUrl],
15
- [:mobile_display, :displayUrl],
16
- [:status, :status]
17
- ]
8
+ CreativeType = {
9
+ id: :creativeId,
10
+ group_id: :adgroupId,
11
+ title: :title,
12
+ description1: :description1,
13
+ pause: :pause,
14
+ mobile_destination: :destinationUrl,
15
+ mobile_display: :displayUrl,
16
+ status: :status,
17
+ creative_ids: :creativeIds,
18
+ creatives: :creativeTypes,
19
+ }
20
+ @map = CreativeType
21
+
22
+ def self.info(auth, ids)
23
+ response = request(auth, Service, 'getCreativeByCreativeId', {creativeIds: ids})
24
+ process(response, 'creativeTypes'){|x| reverse_type(x)[0]}
25
+ end
26
+
27
+ def self.all(auth, ids)
28
+ response = request(auth, Service, 'getCreativeByAdgroupId', {adgroupIds: ids})
29
+ process(response, 'groupCreatives'){|x| x.map{|y| y["creativeTypes"].map{|z| reverse_type(z)}}.flatten }
30
+ end
31
+
32
+ def self.ids(auth, ids)
33
+ response = request(auth, Service, 'getCreativeIdByAdgroupId', {adgroupIds: ids})
34
+ process(response, 'groupCreativeIds'){|x| reverse_type(x)}
35
+ end
18
36
 
19
37
  def self.add(auth, creatives)
20
38
  body = {creativeTypes: make_type(creatives)}
@@ -23,9 +41,7 @@ module PPC
23
41
  end
24
42
 
25
43
  def self.get(auth, ids)
26
- ids = [ids] unless ids.is_a? Array
27
- body = {creativeIds: ids}
28
- response = request(auth, Service, 'getCreativeByCreativeId', body)
44
+ response = request(auth, Service, 'getCreativeByCreativeId', {creativeIds: ids})
29
45
  process(response, 'creativeTypes'){|x| reverse_type(x)}
30
46
  end
31
47
 
@@ -36,48 +52,18 @@ module PPC
36
52
  end
37
53
 
38
54
  def self.delete(auth, ids)
39
- ids = [ids] unless ids.is_a? Array
40
- body = {creativeIds: ids}
41
- response = request(auth, Service, 'deleteCreative', body, 'delete')
55
+ response = request(auth, Service, 'deleteCreative', {creativeIds: ids}, 'delete')
42
56
  process(response, 'result'){|x| x}
43
57
  end
44
58
 
45
- def self.search_id_by_group_id(auth, ids)
46
- ids = [ids] unless ids.is_a? Array
47
- body = {adgroupIds: ids}
48
- response = request(auth, Service, 'getCreativeIdByAdgroupId', body)
49
- process(response, 'groupCreativeIds'){|x| make_groupCreativeIds(x)}
50
- end
51
-
52
- def self.search_by_group_id(auth, ids)
53
- ids = [ids] unless ids.is_a? Array
54
- body = {adgroupIds: ids}
55
- response = request(auth, Service, 'getCreativeByAdgroupId', body)
56
- process(response, 'groupCreatives'){|x| make_groupCreatives(x)}
57
- end
58
-
59
- private
60
- def self.make_groupCreativeIds( groupCreativeIds )
61
- group_creative_ids = []
62
- groupCreativeIds.each do |groupCreativeId|
63
- group_creative_id = { }
64
- group_creative_id[:group_id] = groupCreativeId['adgroupId']
65
- group_creative_id[:creative_ids] = groupCreativeId['creativeIds']
66
- group_creative_ids << group_creative_id
67
- end
68
- return group_creative_ids
59
+ def self.enable( auth, ids )
60
+ creatives = ids.map{|id| {id: id, pause: false} }
61
+ self.update( auth, creatives )
69
62
  end
70
63
 
71
- private
72
- def self.make_groupCreatives( groupCreatives )
73
- group_creatives = []
74
- groupCreatives.each do |groupCreative |
75
- group_creative = {}
76
- group_creative[:group_id] = groupCreative['adgroupId']
77
- group_creative[:creatives] = reverse_type( groupCreative['creativeTypes'] )
78
- group_creatives << group_creative
79
- end
80
- return group_creatives
64
+ def self.pause( auth, ids )
65
+ creatives = ids.map{|id| {id: id, pause: true} }
66
+ self.update( auth, creatives )
81
67
  end
82
68
 
83
69
  end
@@ -5,87 +5,66 @@ module PPC
5
5
  class Group < Sm
6
6
  Service = 'adgroup'
7
7
 
8
- @map =[
9
- [:plan_id, :campaignId],
10
- [:id, :adgroupId],
11
- [:name, :adgroupName],
12
- [:price, :maxPrice],
13
- [:negative, :negativeWords],
14
- [:exact_negative, :exactNegativeWords],
15
- [:pause, :pause],
16
- [:status, :status],
17
- [:os, :adPlatformOS]
18
- ]
8
+ GroupType = {
9
+ plan_id: :campaignId,
10
+ id: :adgroupId,
11
+ name: :adgroupName,
12
+ price: :maxPrice,
13
+ negative: :negativeWords,
14
+ exact_negative: :exactNegativeWords,
15
+ pause: :pause,
16
+ status: :status,
17
+ os: :adPlatformOS,
18
+ group_ids: :adgroupIds,
19
+ groups: :adgroupTypes,
20
+ }
21
+ @map = GroupType
19
22
 
20
- def self.ids( auth )
21
- response = request(auth, Service, "getAllAdgroupId")
22
- process(response, 'campaignAdgroupIds'){|x| make_planGroupIds(x)}
23
+ def self.info(auth, ids)
24
+ response = request(auth, Service, "getAdgroupByAdgroupId", {adgroupIds: ids} )
25
+ process(response, 'adgroupTypes'){|x| reverse_type(x)[0] }
26
+ end
27
+
28
+ def self.all( auth, plan_ids )
29
+ response = request(auth, Service, "getAdgroupByCampaignId", {campaignIds: plan_ids} )
30
+ process(response, 'campaignAdgroups' ){ |x| reverse_type(x.map{|temp| temp["adgroupTypes"]}.flatten) }
31
+ end
32
+
33
+ def self.ids( auth, plan_ids )
34
+ response = request(auth, Service, "getAdgroupIdByCampaignId", {campaignIds: plan_ids} )
35
+ process(response, 'campaignAdgroupIds'){ |x| reverse_type( x ) }
23
36
  end
24
37
 
25
38
  def self.get(auth, ids)
26
- ids = [ ids ] unless ids.is_a? Array
27
- body = {adgroupIds: ids}
28
- response = request(auth, Service, "getAdgroupByAdgroupId", body)
29
- process(response, 'adgroupTypes'){|x| reverse_type(x)}
39
+ response = request(auth, Service, "getAdgroupByAdgroupId", {adgroupIds: ids} )
40
+ process(response, 'adgroupTypes'){|x| reverse_type(x) }
30
41
  end
31
42
 
32
43
  def self.add(auth, groups)
33
- adgroup_types = make_type(groups)
34
- body = {adgroupTypes: adgroup_types}
44
+ body = {adgroupTypes: make_type(groups)}
35
45
  response = request(auth, Service, "addAdgroup", body)
36
- process(response, 'adgroupTypes'){|x| reverse_type(x)}
46
+ process(response, 'adgroupTypes'){|x| reverse_type(x) }
37
47
  end
38
48
 
39
49
  def self.update(auth, groups)
40
- adgroup_types = make_type(groups)
41
- body = {adgroupTypes: adgroup_types}
50
+ body = {adgroupTypes: make_type(groups)}
42
51
  response = request(auth, Service, "updateAdgroup", body)
43
- process(response, 'adgroupTypes'){|x| reverse_type(x)}
52
+ process(response, 'adgroupTypes'){|x| reverse_type(x) }
44
53
  end
45
54
 
46
55
  def self.delete(auth, ids)
47
- ids = [ids] unless ids.is_a? Array
48
- body = {adgroupIds: ids}
49
- response = request(auth, Service, "deleteAdgroup", body, "delete")
56
+ response = request(auth, Service, "deleteAdgroup", {adgroupIds: ids} , "delete")
50
57
  process(response, 'result'){ |x| x }
51
58
  end
52
59
 
53
- def self.search_by_plan_id(auth, ids)
54
- ids = [ ids ] unless ids.class == Array
55
- body = { campaignIds: ids }
56
- response = request(auth, Service, "getAdgroupByCampaignId", body)
57
- process(response, 'campaignAdgroups' ){ |x| make_planGroups( x ) }
58
- end
59
-
60
- def self.search_id_by_plan_id( auth, ids )
61
- ids = [ ids ] unless ids.class == Array
62
- body = { campaignIds: ids }
63
- response = request(auth, Service, "getAdgroupIdByCampaignId", body)
64
- process(response, 'campaignAdgroupIds'){ |x| make_planGroupIds( x ) }
65
- end
66
-
67
- private
68
- def self.make_planGroupIds( campaignAdgroupIds )
69
- planGroupIds = []
70
- campaignAdgroupIds.each do |campaignAdgroupId|
71
- planGroupId = { }
72
- planGroupId[:plan_id] = campaignAdgroupId['campaignId']
73
- planGroupId[:group_ids] = campaignAdgroupId['adgroupIds']
74
- planGroupIds << planGroupId
75
- end
76
- return planGroupIds
60
+ def self.enable( auth, ids )
61
+ groups = ids.map{|id| {id: id, pause: false} }
62
+ self.update( auth, groups )
77
63
  end
78
64
 
79
- private
80
- def self.make_planGroups( campaignAdgroups )
81
- planGroups = []
82
- campaignAdgroups.each do |campaignAdgroup|
83
- planGroup = {}
84
- planGroup[:plan_id] = campaignAdgroup['campaignId']
85
- planGroup[:groups] = reverse_type( campaignAdgroup['adgroupTypes'] )
86
- planGroups << planGroup
87
- end
88
- return planGroups
65
+ def self.pause( auth, ids )
66
+ groups = ids.map{|id| {id: id, pause: true} }
67
+ self.update( auth, groups )
89
68
  end
90
69
 
91
70
  end # class group
@@ -4,126 +4,68 @@ module PPC
4
4
  class Sm
5
5
  class Keyword < Sm
6
6
  Service = 'keyword'
7
-
8
- Match_type = { 'exact' => 0, 'phrase' => 1, 'wide' => 2, 0 => 'exact', 1 => 'phrase' , 2 => 'wide' }
9
7
 
10
- @map = [
11
- [:id, :keywordId],
12
- [:group_id, :adgroupId],
13
- [:keyword, :keyword],
14
- [:price, :price],
15
- [:mobile_destination, :destinationUrl],
16
- [:match_type, :matchType],
17
- [:status, :status],
18
- [:pause, :pause]
19
- ]
8
+ Match_type = { 'exact' => 0, 'phrase' => 1, 'wide' => 2, 0 => 'exact', 1 => 'phrase' , 2 => 'wide' }
9
+ @match_types = Match_type
10
+ KeywordType = {
11
+ id: :keywordId,
12
+ group_id: :adgroupId,
13
+ keyword: :keyword,
14
+ price: :price,
15
+ mobile_destination: :destinationUrl,
16
+ match_type: :matchType,
17
+ status: :status,
18
+ pause: :pause,
19
+ keyword_ids: :keywordIds,
20
+ keywords: :keywordTypes,
21
+ }
22
+ @map = KeywordType
20
23
 
21
- def self.get(auth, ids)
22
- ids = [ids] unless ids.is_a? Array
23
- body = {keywordIds: ids}
24
- response = request(auth, Service, 'getKeywordByKeywordId', body)
25
- return process(response, 'keywordTypes'){|x| reverse_type(x)}
24
+ def self.info(auth, ids)
25
+ response = request(auth, Service, 'getKeywordByKeywordId', {keywordIds: ids})
26
+ process(response, 'keywordTypes'){|x| reverse_type(x)[0] }
26
27
  end
27
28
 
28
- def self.add(auth, keywords)
29
- keyword_types = make_type(keywords)
30
- body = {keywordTypes: keyword_types}
31
- response = request(auth, Service, "addKeyword", body)
32
- return process(response, 'keywordTypes'){|x| reverse_type(x)}
29
+ def self.all(auth, group_ids)
30
+ response = request(auth, Service, "getKeywordByAdgroupId", {adgroupIds: group_ids} )
31
+ process(response, 'groupKeywords'){|x| reverse_type( x.map{|temp| temp["keywordTypes"]}.flatten ) }
33
32
  end
34
33
 
35
- def self.update(auth, keywords)
36
- keyword_types = make_type(keywords)
37
- body = {keywordTypes: keyword_types}
38
- response = request(auth, Service, "updateKeyword", body)
39
- return process(response, 'keywordTypes'){|x| reverse_type(x)}
34
+ def self.ids(auth, group_ids)
35
+ response = request(auth, Service, "getKeywordIdByAdgroupId", {adgroupIds: group_ids} )
36
+ process(response, 'groupKeywordIds'){|x| reverse_type(x)}
40
37
  end
41
38
 
42
- def self.delete(auth, ids)
43
- ids = [ids] unless ids.is_a? Array
44
- body = {keywordIds: ids}
45
- response = request(auth, Service, 'deleteKeyword', body, 'delete')
46
- return process(response, 'result'){|x| x }
47
- end
48
-
49
- def self.search_by_group_id(auth, group_ids)
50
- group_ids = [group_ids] unless group_ids.is_a? Array
51
- body = {adgroupIds: group_ids}
52
- response = request(auth, Service, "getKeywordByAdgroupId", body)
53
- return process(response, 'groupKeywords'){|x| make_groupKeywords(x)}
39
+ def self.get(auth, ids)
40
+ response = request(auth, Service, 'getKeywordByKeywordId', {keywordIds: ids})
41
+ process(response, 'keywordTypes'){|x| reverse_type(x)}
54
42
  end
55
43
 
56
- def self.search_id_by_group_id(auth, group_ids)
57
- group_ids = [group_ids] unless group_ids.is_a? Array
58
- body = {adgroupIds: group_ids}
59
- response = request(auth, Service, "getKeywordIdByAdgroupId", body)
60
- return process(response, 'groupKeywordIds'){|x| make_groupKeywordIds(x)}
44
+ def self.add(auth, keywords)
45
+ body = {keywordTypes: make_type(keywords) }
46
+ response = request(auth, Service, "addKeyword", body)
47
+ process(response, 'keywordTypes'){|x| reverse_type(x)}
61
48
  end
62
49
 
63
- private
64
- def self.make_groupKeywordIds( groupKeywordIds )
65
- group_keyword_ids = []
66
- groupKeywordIds.each do |groupKeywordId|
67
- group_keyword_id = { }
68
- group_keyword_id[:group_id] = groupKeywordId['adgroupId']
69
- group_keyword_id[:keyword_ids] = groupKeywordId['keywordIds']
70
- group_keyword_ids << group_keyword_id
71
- end
72
- return group_keyword_ids
50
+ def self.update(auth, keywords)
51
+ body = {keywordTypes: make_type(keywords) }
52
+ response = request(auth, Service, "updateKeyword", body)
53
+ process(response, 'keywordTypes'){|x| reverse_type(x)}
73
54
  end
74
55
 
75
- private
76
- def self.make_groupKeywords( groupKeywords )
77
- group_keywords = []
78
- groupKeywords.each do |groupKeyword|
79
- group_keyword = {}
80
- group_keyword[:group_id] = groupKeyword['adgroupId']
81
- group_keyword[:keywords] = reverse_type( groupKeyword['keywordTypes'] )
82
- group_keywords << group_keyword
83
- end
84
- return group_keywords
56
+ def self.delete(auth, ids)
57
+ response = request(auth, Service, 'deleteKeyword', {keywordIds: ids}, 'delete')
58
+ process(response, 'result'){|x| x }
85
59
  end
86
60
 
87
- # Override
88
- def self.make_type( params, map = @map)
89
- params = [ params ] unless params.is_a? Array
90
- types = []
91
- params.each do |param|
92
- type = {}
93
- map.each do |key|
94
- # 增加对matchtype的自动转换
95
- if key[0] == :match_type
96
- value = param[ key[0] ]
97
- type[ key[1] ] = Match_type[ value ] if value
98
- else
99
- value = param[ key[0] ]
100
- type[ key[1] ] = value if value
101
- end
102
- end
103
- types << type
104
- end
105
- return types
61
+ def self.enable( auth, ids )
62
+ keywords = ids.map{|id| {id: id, pause: false} }
63
+ self.update( auth, keywords )
106
64
  end
107
65
 
108
- # Overwrite
109
- def self.reverse_type( types, map = @map )
110
- types = [ types ] unless types.is_a? Array
111
- params = []
112
- types.each do |type|
113
- param = {}
114
- # 增加对matchtype的自动转换
115
- map.each do |key|
116
- if key[0] == :match_type
117
- value = type[ key[1].to_s ]
118
- param[ key[0] ] = Match_type[ value ] if value
119
- else
120
- value = type[ key[1].to_s ]
121
- param[ key[0] ] = value if value
122
- end
123
- end # map.each
124
- params << param
125
- end # types.each
126
- return params
66
+ def self.pause( auth, ids )
67
+ keywords = ids.map{|id| {id: id, pause: true} }
68
+ self.update( auth, keywords )
127
69
  end
128
70
 
129
71
  end # keyword