ppc 0.3.0 → 1.0.1

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.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/.autotest +25 -0
  3. data/.gemtest +0 -0
  4. data/History.txt +6 -0
  5. data/Manifest.txt +8 -0
  6. data/README.txt +80 -0
  7. data/Rakefile +19 -0
  8. data/bin/ppc +3 -0
  9. data/lib/ppc.rb +6 -15
  10. data/test/test_ppc.rb +0 -0
  11. metadata +41 -130
  12. data/.gitignore +0 -37
  13. data/.rspec +0 -2
  14. data/LICENSE +0 -339
  15. data/README.md +0 -78
  16. data/lib/ppc/api.rb +0 -10
  17. data/lib/ppc/api/baidu.rb +0 -138
  18. data/lib/ppc/api/baidu/account.rb +0 -47
  19. data/lib/ppc/api/baidu/bulk.rb +0 -41
  20. data/lib/ppc/api/baidu/creative.rb +0 -125
  21. data/lib/ppc/api/baidu/group.rb +0 -111
  22. data/lib/ppc/api/baidu/keyword.rb +0 -204
  23. data/lib/ppc/api/baidu/plan.rb +0 -68
  24. data/lib/ppc/api/baidu/report.rb +0 -143
  25. data/lib/ppc/api/qihu.rb +0 -107
  26. data/lib/ppc/api/qihu/account.rb +0 -86
  27. data/lib/ppc/api/qihu/creative.rb +0 -106
  28. data/lib/ppc/api/qihu/group.rb +0 -113
  29. data/lib/ppc/api/qihu/keyword.rb +0 -111
  30. data/lib/ppc/api/qihu/plan.rb +0 -64
  31. data/lib/ppc/api/qihu/report.rb +0 -159
  32. data/lib/ppc/api/shenma.rb +0 -64
  33. data/lib/ppc/api/shenma/report.rb +0 -135
  34. data/lib/ppc/api/sogou.rb +0 -122
  35. data/lib/ppc/api/sogou/account.rb +0 -42
  36. data/lib/ppc/api/sogou/creative.rb +0 -117
  37. data/lib/ppc/api/sogou/group.rb +0 -116
  38. data/lib/ppc/api/sogou/keyword.rb +0 -182
  39. data/lib/ppc/api/sogou/plan.rb +0 -66
  40. data/lib/ppc/api/sogou/report.rb +0 -129
  41. data/lib/ppc/ext.rb +0 -9
  42. data/lib/ppc/operation.rb +0 -196
  43. data/lib/ppc/operation/account.rb +0 -53
  44. data/lib/ppc/operation/creative.rb +0 -28
  45. data/lib/ppc/operation/group.rb +0 -59
  46. data/lib/ppc/operation/keyword.rb +0 -32
  47. data/lib/ppc/operation/plan.rb +0 -47
  48. data/lib/ppc/operation/report.rb +0 -19
  49. data/ppc.gemspec +0 -26
  50. data/spec/baidu/api_baidu_account_spec.rb +0 -15
  51. data/spec/baidu/api_baidu_creative_spec.rb +0 -67
  52. data/spec/baidu/api_baidu_group_spec.rb +0 -45
  53. data/spec/baidu/api_baidu_keyword_spec.rb +0 -61
  54. data/spec/baidu/api_baidu_plan_spec.rb +0 -43
  55. data/spec/baidu/api_baidu_report_spec.rb +0 -44
  56. data/spec/baidu/api_baidu_spec.rb +0 -55
  57. data/spec/operation/operation_baidu_report_spec.rb +0 -17
  58. data/spec/operation/operation_baidu_spec.rb +0 -78
  59. data/spec/operation/operation_qihu_report_spec.rb +0 -18
  60. data/spec/operation/operation_qihu_spec.rb +0 -51
  61. data/spec/operation/operation_sogou_report_spec.rb +0 -17
  62. data/spec/operation/operation_sogou_spec.rb +0 -51
  63. data/spec/operation/operation_spec_helper.rb +0 -51
  64. data/spec/qihu/api_qihu_account_spec.rb +0 -25
  65. data/spec/qihu/api_qihu_creative_spec.rb +0 -48
  66. data/spec/qihu/api_qihu_group_spec.rb +0 -40
  67. data/spec/qihu/api_qihu_keyword_spec.rb +0 -50
  68. data/spec/qihu/api_qihu_plan_spec.rb +0 -39
  69. data/spec/qihu/api_qihu_report_spec.rb +0 -54
  70. data/spec/sogou/api_sogou_account_spec.rb +0 -15
  71. data/spec/sogou/api_sogou_creative_spec.rb +0 -48
  72. data/spec/sogou/api_sogou_group_spec.rb +0 -45
  73. data/spec/sogou/api_sogou_keyword_spec.rb +0 -50
  74. data/spec/sogou/api_sogou_plan_spec.rb +0 -39
  75. data/spec/sogou/api_sogou_report_spec.rb +0 -51
  76. data/spec/spec_helper.rb +0 -134
data/lib/ppc/ext.rb DELETED
@@ -1,9 +0,0 @@
1
- class String
2
- def snake_case
3
- self.gsub(/::/, '/').
4
- gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
5
- gsub(/([a-z\d])([A-Z])/,'\1_\2').
6
- tr("-", "_").
7
- downcase
8
- end
9
- end
data/lib/ppc/operation.rb DELETED
@@ -1,196 +0,0 @@
1
- module PPC
2
- module Operation
3
-
4
- attr_accessor :id
5
-
6
- def initialize( params )
7
-
8
- if params[:se] == nil
9
- raise 'please specific a search engine'
10
- else
11
- @se = params[:se]
12
- end
13
- @id = params[:id]
14
- @auth = {
15
- username: params[:username],
16
- password: params[:password],
17
- # 在qihu360的api中,apikey就是auth[:token]
18
- token: params[:token]
19
- }
20
- # add support for qihu360
21
- if @se == 'qihu' && params[:accessToken] == nil
22
- raise "you are using qihu service, please enter cipherkey" if params[:cipherkey] == nil
23
- raise "you are using qihu service, please enter cipheriv" if params[:cipheriv] == nil
24
- cipher = { key: params[:cipherkey], iv: params[:cipheriv] }
25
- @auth[:accessToken] = qihu_refresh_token( @auth, cipher )
26
- else
27
- @auth[:accessToken] = params[:accessToken]
28
- end
29
- end
30
-
31
- def qihu_refresh_token( auth, cipher )
32
- cipher_aes = OpenSSL::Cipher::AES.new(128, :CBC)
33
- cipher_aes.encrypt
34
- cipher_aes.key = cipher[:key]
35
- cipher_aes.iv = cipher[:iv]
36
- encrypted = (cipher_aes.update(Digest::MD5.hexdigest( auth[:password] )) + cipher_aes.final).unpack('H*').join
37
- url = "https://api.e.360.cn/account/clientLogin"
38
- response = HTTParty.post(url,
39
- :body => {
40
- :username => auth[:username],
41
- :passwd => encrypted[0,64]
42
- },
43
- :headers => {'apiKey' => auth[:token] }
44
- )
45
- data = response.parsed_response
46
- data["account_clientLogin_response"]["accessToken"]
47
- end
48
-
49
- def call(service)
50
- eval "::PPC::API::#{@se.capitalize}::#{service.capitalize}"
51
- end
52
-
53
- def download(params = {})
54
- bulk = ::PPC::Baidu::Bulk.new({
55
- username: @username,
56
- password: @password,
57
- token: @token,
58
- debug: @debug
59
- })
60
-
61
- params[:extended] = params[:extended] || 2
62
-
63
- begin
64
- file_id = bulk.file_id_of_all(params)
65
- puts "file_id: #{file_id}" if @debug
66
-
67
- loop do
68
- state = bulk.state(file_id)
69
- raise "invalid file state: #{state}" unless %w(1 2 3 null).include? state
70
- break if state == '3'
71
- puts "waiting for #{file_id} to be ready. current state:#{state}" if @debug
72
- sleep 3
73
- end
74
- puts "#{file_id} is ready" if @debug
75
- return bulk.path(file_id)
76
- rescue
77
- raise BulkException.new(file_id,bulk)
78
- end
79
-
80
- return false
81
- end
82
-
83
- # ++++++++ #
84
- # Lazy Code #
85
- # ++++++++ #
86
-
87
- # helper fucntion
88
- def get_obj( ids, service )
89
- '''
90
- Return service object.
91
- Providing single id, return single object.
92
- Providing multiple ids, return Array of objects
93
- '''
94
- class_obj = eval "::PPC::Opeartion::#{service.capitalize}"
95
- param = @auth
96
- param[:se] = @se
97
- objs = []
98
-
99
- ids.each do |id|
100
- param[:id] = id
101
- objs << class_obj.new( param )
102
- end
103
-
104
- return objs.length == 1 ? objs[0] : objs
105
- end
106
-
107
- # +++++ Plan opeartion funcitons +++++ #
108
- module Plan_operation
109
- def get_plan( ids )
110
- ::PPC::Opeartion::get_obj( ids, 'plan')
111
- end
112
-
113
- def add_plan( plans )
114
- call('plan').add(@auth,plans)
115
- end
116
-
117
- def update_plan( plans )
118
- call('plan').update(@auth,plans)
119
- end
120
-
121
- def delete_plan( ids )
122
- call('plan').delete(@auth,ids)
123
- end
124
- end
125
-
126
- # +++++ Group opeartion funcitons +++++ #
127
- module Group_operation
128
- def get_group( ids )
129
- ::PPC::Opeartion::get_obj( ids, 'group')
130
- end
131
-
132
- def add_group( groups )
133
- call('group').add(@auth,groups )
134
- end
135
-
136
- def update_group( groups )
137
- call('group').update( @auth, groups )
138
- end
139
-
140
- def delete_group( ids )
141
- call('group').delete( @auth, ids )
142
- end
143
- end
144
-
145
- # +++++ Keyword opeartion funcitons +++++ #
146
- module Keyword_operation
147
- def get_keyword( ids )
148
- ::PPC::Opeartion::get_obj( ids, 'keyword')
149
- end
150
-
151
- def add_keyword( keywords )
152
- call('keyword').add( @auth, keywords )
153
- end
154
-
155
- def update_keyword( keywords)
156
- call('keyword').update( @auth, keywords )
157
- end
158
-
159
- def delete_keyword( ids )
160
- call('keyword').delete( @auth, ids )
161
- end
162
- end
163
-
164
- # +++++ Creative opeartion funcitons +++++ #
165
- module Creative_operation
166
- def get_creative( ids )
167
- ::PPC::Opeartion::get_obj( ids, 'creative')
168
- end
169
-
170
- def add_creative( creatives )
171
- call('creative').add( @auth, creatives )
172
- end
173
-
174
- def update_creative( creatives )
175
- call('creative').update( @auth, creatives )
176
- end
177
-
178
- def delete_creative( ids )
179
- call('creative').delete( @auth, ids )
180
- end
181
- end
182
-
183
- end # Opeartion
184
- end # PPC
185
-
186
- # requires are moved to the end of the file
187
- # because if we load files before defining the
188
- # module ::PPC::Operation. Errors of 'uninitialized constance'
189
- # will occur
190
- require 'ppc/operation/report'
191
- require 'ppc/operation/account'
192
- require 'ppc/operation/group'
193
- require 'ppc/operation/plan'
194
- require 'ppc/operation/keyword'
195
- require 'ppc/operation/creative'
196
-
@@ -1,53 +0,0 @@
1
- module PPC
2
- module Operation
3
- class Account
4
- include ::PPC::Operation
5
-
6
- # self operations
7
- def info
8
- info = call('account').info(@auth)
9
- p info
10
- @id = info[:result][:id] if @id == nil
11
- return info
12
- end
13
-
14
- def update(account)
15
- call('account').update(@auth,account)
16
- end
17
-
18
- # subobject(plan) operations
19
- def plans
20
- call('plan').all(@auth)
21
- end
22
-
23
- def plan_ids
24
- call('plan').ids(@auth)
25
- end
26
-
27
- # some useful keyword operations
28
- def keywords(group_id)
29
- call( 'keyword' ).search_by_group_id( @auth, group_id )
30
- end
31
-
32
- def keyword_ids(group_id)
33
- call( 'keyword' ).search_id_by_group_id( @auth, group_id )
34
- end
35
-
36
- # plan operations
37
- include ::PPC::Operation::Plan_operation
38
-
39
- # group opeartions
40
- include ::PPC::Operation::Group_operation
41
-
42
- # keyword opeartions
43
- include ::PPC::Operation::Keyword_operation
44
-
45
- # creative opeartions
46
- include ::PPC::Operation::Creative_operation
47
-
48
- # report operations
49
- include ::PPC::Operation::Report
50
-
51
- end
52
- end
53
- end
@@ -1,28 +0,0 @@
1
- module PPC
2
- module Operation
3
- class Creative
4
- include ::PPC::Operation
5
-
6
- def info()
7
- ::PPC::API::Baidu::Creative::get( @auth, @id )
8
- end
9
-
10
- def update( keywordType )
11
- ::PPC::API::Baidu::Keyword::update( @auth, keywordType )
12
- end
13
-
14
- def activate()
15
- ::PPC::API::Baidu::Creative::activate( @auth, @id )
16
- end
17
-
18
- def status()
19
- ::PPC::API::Baidu::Creative::status( @auth, @id )
20
- end
21
-
22
- def delete()
23
- ::PPC::API::Baidu::Creative::delete( @auth, @id )
24
- end
25
-
26
- end
27
- end
28
- end
@@ -1,59 +0,0 @@
1
- module PPC
2
- module Operation
3
- class Group
4
- include ::PPC::Operation
5
-
6
- def info()
7
- call('group').get(@auth, @id)
8
- end
9
-
10
- def update( info )
11
- info[:id] = @id unless info[:id]
12
- call('group').update(@auth, info)
13
- end
14
-
15
- # =============================== #
16
- def keywords()
17
- call( 'keyword' ).search_by_group_id( @auth, @id )
18
- end
19
-
20
- def keyword_ids()
21
- call( 'keyword' ).search_id_by_group_id( @auth, @id )
22
- end
23
-
24
- def creatives()
25
- call( 'creative' ).search_by_group_id( @auth, @id )
26
- end
27
-
28
- def creative_ids()
29
- call( 'creative' ).search_id_by_group_id( @auth, @id )
30
- end
31
-
32
- # keyword opeartion
33
- include ::PPC::Operation::Keyword_operation
34
-
35
- # creative opeartion
36
- include ::PPC::Operation::Creative_operation
37
-
38
- # Overwrite add method to provide more function
39
- def add_keyword( keywords )
40
- call('keyword').add( @auth, add_group_id( keywords ) )
41
- end
42
-
43
- def add_creative( creatives )
44
- call('creative').add( @auth, add_group_id( creatives ) )
45
- end
46
-
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
- end # Group
58
- end # Operation
59
- end # PPC
@@ -1,32 +0,0 @@
1
- module PPC
2
- module Operation
3
- class Keyword
4
- include ::PPC::Operation
5
-
6
- def info()
7
- ::PPC::API::Baidu::Keyword::get( @auth, @id )
8
- end
9
-
10
- def update( type )
11
- ::PPC::API::Baidu::Keyword::update( @auth, type.merge( id:@id) )
12
- end
13
-
14
- def activate()
15
- ::PPC::API::Baidu::Keyword::activate( @auth, @id )
16
- end
17
-
18
- def status()
19
- ::PPC::API::Baidu::Keyword::status( @auth, @id )
20
- end
21
-
22
- def quality()
23
- ::PPC::API::Baidu::Keyword::quality( @auth, @id )
24
- end
25
-
26
- def delete()
27
- ::PPC::API::Baidu::Keyword::delete( @auth, @id )
28
- end
29
-
30
- end
31
- end
32
- end
@@ -1,47 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- module PPC
3
- module Operation
4
- class Plan
5
- include ::PPC::Operation
6
-
7
- def info
8
- call('plan').get(@auth,@id)
9
- end
10
-
11
- def update( plan )
12
- call('plan').update( @auth, plan.merge( id:@id ) )
13
- end
14
-
15
- def groups()
16
- result = call('group').search_by_plan_id(@auth, @id)
17
- result[:result] = result[:result][0][:groups]
18
- return result
19
- end
20
-
21
- def group_ids()
22
- result = call('group').search_id_by_plan_id(@auth, @id)
23
- result[:result] = result[:result][0][:group_ids]
24
- return result
25
- end
26
-
27
- # group opeartion
28
- include ::PPC::Operation::Group_operation
29
-
30
- # Overwirte add_group method to provide more function
31
- def add_group( groups )
32
- call('group').add( @auth, add_plan_id( groups ) )
33
- end
34
-
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
-
45
- end # class plan
46
- end # mudole Opeartion
47
- end # PPC
@@ -1,19 +0,0 @@
1
- module PPC
2
- module Operation
3
- module Report
4
-
5
- def query_report( param = nil, debug = false )
6
- call('report').query_report( @auth, param, debug )
7
- end
8
-
9
- def creative_report( param = nil, debug = false )
10
- call('report').creative_report( @auth, param, debug )
11
- end
12
-
13
- def keyword_report( param = nil, debug = false )
14
- call('report').keyword_report( @auth, param, debug )
15
- end
16
-
17
- end
18
- end
19
- end