ppc 1.0.6 → 1.3.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/.gitignore +31 -23
  3. data/LICENSE +22 -0
  4. data/README.md +5 -28
  5. data/lib/ppc/api/baidu/account.rb +47 -0
  6. data/lib/ppc/api/baidu/bulk.rb +41 -0
  7. data/lib/ppc/api/baidu/creative.rb +125 -0
  8. data/lib/ppc/api/baidu/group.rb +111 -0
  9. data/lib/ppc/api/baidu/keyword.rb +193 -0
  10. data/lib/ppc/api/baidu/plan.rb +65 -0
  11. data/lib/ppc/api/baidu/report.rb +124 -0
  12. data/lib/ppc/api/baidu.rb +132 -0
  13. data/lib/ppc/api.rb +8 -0
  14. data/lib/ppc/baidu/account.rb +55 -27
  15. data/lib/ppc/baidu/group.rb +99 -0
  16. data/lib/ppc/baidu/key.rb +38 -0
  17. data/lib/ppc/baidu/plan.rb +69 -0
  18. data/lib/ppc/baidu/report.rb +45 -13
  19. data/lib/ppc/baidu.rb +28 -25
  20. data/lib/ppc/operation/account.rb +40 -0
  21. data/lib/ppc/operation/creative.rb +28 -0
  22. data/lib/ppc/operation/group.rb +59 -0
  23. data/lib/ppc/operation/keyword.rb +32 -0
  24. data/lib/ppc/operation/plan.rb +47 -0
  25. data/lib/ppc/operation.rb +161 -0
  26. data/lib/ppc.rb +3 -7
  27. data/ppc.gemspec +4 -4
  28. data/spec/api_baidu_account_spec.rb +18 -0
  29. data/spec/api_baidu_creative_spec.rb +71 -0
  30. data/spec/api_baidu_group_spec.rb +50 -0
  31. data/spec/api_baidu_keyword_spec.rb +64 -0
  32. data/spec/api_baidu_plan_spec.rb +42 -0
  33. data/spec/api_baidu_report_spec.rb +32 -0
  34. data/spec/api_baidu_spec.rb +60 -0
  35. data/spec/baidu_account_spec.rb +32 -0
  36. data/spec/baidu_bulk_spec.rb +21 -0
  37. data/spec/baidu_group_spec.rb +56 -0
  38. data/spec/baidu_plan_spec.rb +129 -0
  39. data/spec/{report_spec.rb → baidu_report_spec.rb} +0 -0
  40. data/spec/operation_spec.rb +87 -0
  41. data/spec/operation_spec_helper.rb +53 -0
  42. data/spec/spec_helper.rb +18 -1
  43. metadata +53 -22
  44. data/Gemfile +0 -4
  45. data/LICENSE.txt +0 -22
  46. data/Rakefile +0 -2
  47. data/lib/ppc/qihu/account.rb +0 -0
  48. data/lib/ppc/qihu.rb +0 -0
  49. data/lib/ppc/sogou/bulk.rb +0 -48
  50. data/lib/ppc/sogou.rb +0 -125
  51. data/spec/account_spec.rb +0 -16
  52. data/spec/bulk_spec.rb +0 -35
  53. data/spec/plan_spec.rb +0 -17
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ppc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
- - charles
7
+ - Chienli Ma, 刘梦晨, 刘明
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-06 00:00:00.000000000 Z
11
+ date: 2015-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,34 +38,55 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- description: ppc api for google baidu etc
41
+ description: ppc api for baidu qihu sogou
42
42
  email:
43
- - charles.liu@corp.elong.com
43
+ - maqianlie@gmail.com, liuyu_tc@163.com, seoaqua@qq.com
44
44
  executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
48
  - ".gitignore"
49
49
  - ".rspec"
50
- - Gemfile
51
- - LICENSE.txt
50
+ - LICENSE
52
51
  - README.md
53
- - Rakefile
54
52
  - lib/ppc.rb
53
+ - lib/ppc/api.rb
54
+ - lib/ppc/api/baidu.rb
55
+ - lib/ppc/api/baidu/account.rb
56
+ - lib/ppc/api/baidu/bulk.rb
57
+ - lib/ppc/api/baidu/creative.rb
58
+ - lib/ppc/api/baidu/group.rb
59
+ - lib/ppc/api/baidu/keyword.rb
60
+ - lib/ppc/api/baidu/plan.rb
61
+ - lib/ppc/api/baidu/report.rb
55
62
  - lib/ppc/baidu.rb
56
63
  - lib/ppc/baidu/account.rb
57
64
  - lib/ppc/baidu/bulk.rb
65
+ - lib/ppc/baidu/group.rb
66
+ - lib/ppc/baidu/key.rb
58
67
  - lib/ppc/baidu/plan.rb
59
68
  - lib/ppc/baidu/report.rb
60
- - lib/ppc/qihu.rb
61
- - lib/ppc/qihu/account.rb
62
- - lib/ppc/sogou.rb
63
- - lib/ppc/sogou/bulk.rb
69
+ - lib/ppc/operation.rb
70
+ - lib/ppc/operation/account.rb
71
+ - lib/ppc/operation/creative.rb
72
+ - lib/ppc/operation/group.rb
73
+ - lib/ppc/operation/keyword.rb
74
+ - lib/ppc/operation/plan.rb
64
75
  - ppc.gemspec
65
- - spec/account_spec.rb
66
- - spec/bulk_spec.rb
67
- - spec/plan_spec.rb
68
- - spec/report_spec.rb
76
+ - spec/api_baidu_account_spec.rb
77
+ - spec/api_baidu_creative_spec.rb
78
+ - spec/api_baidu_group_spec.rb
79
+ - spec/api_baidu_keyword_spec.rb
80
+ - spec/api_baidu_plan_spec.rb
81
+ - spec/api_baidu_report_spec.rb
82
+ - spec/api_baidu_spec.rb
83
+ - spec/baidu_account_spec.rb
84
+ - spec/baidu_bulk_spec.rb
85
+ - spec/baidu_group_spec.rb
86
+ - spec/baidu_plan_spec.rb
87
+ - spec/baidu_report_spec.rb
88
+ - spec/operation_spec.rb
89
+ - spec/operation_spec_helper.rb
69
90
  - spec/spec_helper.rb
70
91
  homepage: http://github.com/seoaqua/ppc
71
92
  licenses:
@@ -87,13 +108,23 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
108
  version: '0'
88
109
  requirements: []
89
110
  rubyforge_project:
90
- rubygems_version: 2.2.2
111
+ rubygems_version: 2.4.4
91
112
  signing_key:
92
113
  specification_version: 4
93
- summary: ppc api for google baidu etc
114
+ summary: ppc api for baidu qihu sogou
94
115
  test_files:
95
- - spec/account_spec.rb
96
- - spec/bulk_spec.rb
97
- - spec/plan_spec.rb
98
- - spec/report_spec.rb
116
+ - spec/api_baidu_account_spec.rb
117
+ - spec/api_baidu_creative_spec.rb
118
+ - spec/api_baidu_group_spec.rb
119
+ - spec/api_baidu_keyword_spec.rb
120
+ - spec/api_baidu_plan_spec.rb
121
+ - spec/api_baidu_report_spec.rb
122
+ - spec/api_baidu_spec.rb
123
+ - spec/baidu_account_spec.rb
124
+ - spec/baidu_bulk_spec.rb
125
+ - spec/baidu_group_spec.rb
126
+ - spec/baidu_plan_spec.rb
127
+ - spec/baidu_report_spec.rb
128
+ - spec/operation_spec.rb
129
+ - spec/operation_spec_helper.rb
99
130
  - spec/spec_helper.rb
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in ppc.gemspec
4
- gemspec
data/LICENSE.txt DELETED
@@ -1,22 +0,0 @@
1
- Copyright (c) 2014 charles
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile DELETED
@@ -1,2 +0,0 @@
1
- require "bundler/gem_tasks"
2
-
File without changes
data/lib/ppc/qihu.rb DELETED
File without changes
@@ -1,48 +0,0 @@
1
- module PPC
2
- class Sogou
3
- class BulkException < Exception
4
- attr_reader :file_id,:bulk,:exception
5
- def initialize(file_id,bulk,exception)
6
- @file_id = file_id
7
- @bulk = bulk
8
- @exception = exception
9
- end
10
- end
11
-
12
- class Bulk < ::PPC::Sogou
13
- def initialize(params = {})
14
- params[:service] = 'AccountDownload'
15
- super(params)
16
- end
17
-
18
- def file_id_of_all(params = {})
19
- plan_ids = params[:plan_ids]
20
-
21
- unless plan_ids.nil?
22
- plan_ids = plan_ids.class == Array ? plan_ids : [plan_ids]
23
- end
24
-
25
- options = {
26
- cpcPlanIds: plan_ids || [] ,
27
- includeQuality: params[:quality] || true ,
28
- includeTemp: params[:temp] || false ,
29
- format: params[:format] || 1
30
- }
31
- response = request('getAccountFile',options)
32
-
33
- body = response[:envelope][:body]
34
- raise "no result" if body.nil?
35
- body[:get_account_file_response][:accountFileId]
36
- end
37
-
38
- def state(id)
39
- raise "empty id" if id.nil? or id.empty?
40
- request('getAccountFileStatus',{accountFileId:id})[:envelope][:body][:get_account_file_status_response][:is_generated]
41
- end
42
-
43
- def path(id)
44
- request('getAccountFilePath',{accountFileId:id})[:envelope][:body][:get_account_file_path_response][:account_file_path]
45
- end
46
- end
47
- end
48
- end
data/lib/ppc/sogou.rb DELETED
@@ -1,125 +0,0 @@
1
- require 'ppc/sogou/account'
2
- require 'ppc/sogou/plan'
3
- require 'ppc/sogou/bulk'
4
- require 'awesome_print'
5
- require 'savon'
6
-
7
- module PPC
8
- class Sogou
9
- include ::PPC
10
-
11
- def initialize(params = {})
12
- @service = params[:service] + 'Service'
13
- @port_name = params[:service] + 'Service'
14
- @username = params[:username]
15
- @password = params[:password]
16
- @token = params[:token]
17
- @client = Savon.new("http://api.agent.sogou.com:8080/sem/sms/v1/#{@service}?wsdl")
18
-
19
- @debug = params[:debug] || false
20
- end
21
-
22
- def request(method,params = {})
23
- operation = make_operation(method)
24
- operation.header = operation_header
25
- operation.body = {
26
- method+'Request' =>params
27
- }
28
- print_debug(operation.body,'operation.body') if @debug
29
- print_debug(operation.build,'operation.build') if @debug
30
- response = operation.call.hash
31
- process_response(response)
32
- print_debug(response,'response') if @debug
33
- response
34
- end
35
-
36
- def operations
37
- @client.operations(@service,@service)
38
- end
39
-
40
- protected
41
- def download(params = {})
42
- bulk = ::PPC::Sogou::Bulk.new({
43
- username: @username,
44
- password: @password,
45
- token: @token,
46
- debug: @debug
47
- })
48
-
49
- params[:extended] = params[:extended] || 2
50
-
51
- begin
52
- file_id = bulk.file_id_of_all(params)
53
- puts "file_id: #{file_id}" if @debug
54
-
55
- loop do
56
- state = bulk.state(file_id)
57
- raise "invalid file state: #{state}" unless %w(1 2 3 null).include? state
58
- break if state == '3'
59
- puts "waiting for #{file_id} to be ready. current state:#{state}" if @debug
60
- sleep 3
61
- end
62
- puts "#{file_id} is ready" if @debug
63
- return bulk.path(file_id)
64
- rescue Exception => e
65
- raise PPC::Sogou::BulkException.new(file_id,bulk,e)
66
- end
67
- end
68
-
69
- private
70
- def make_operation(operation_name)
71
- @client.operation(@service,@service,operation_name)
72
- end
73
-
74
- def operation_header
75
- {
76
- :AuthHeader=>
77
- {
78
- username: @username,
79
- password: @password,
80
- token: @token
81
- }
82
- }
83
- end
84
-
85
- def example(operation,with_header=false)
86
- operation = make_operation(operation)
87
- if with_header
88
- {
89
- example_header: operation.example_header,
90
- example_body: operation.example_body
91
- }
92
- else
93
- operation.example_body
94
- end
95
- end
96
-
97
- def process_response(response)
98
- body = response[:envelope]
99
- @header = body[:header]
100
- res_header = header[:res_header]
101
-
102
- @oprs = res_header[:oprs]
103
- @oprtime = res_header[:oprtime]
104
- @quota = res_header[:quota]
105
- @rquota = res_header[:rquota]
106
- @status = res_header[:status]
107
-
108
- @desc = res_header[:desc]
109
- case @desc
110
- when 'success'
111
- when 'failure'
112
- failures = res_header[:failures]
113
- @code = failures[:code]
114
- @message = failures[:message]
115
- when 'system failure'
116
- failures = res_header[:failures]
117
- @code = failures[:code]
118
- @message = failures[:message]
119
- else
120
- raise "unknown desc from sogou: #{@desc}"
121
- end
122
- end
123
-
124
- end
125
- end
data/spec/account_spec.rb DELETED
@@ -1,16 +0,0 @@
1
- describe ::PPC::Baidu::Account do
2
- subject{::PPC::Baidu::Account.new(
3
- debug:true,
4
- username:'',
5
- password:'',
6
- token:''
7
- )}
8
- it "could download all plan" do
9
- result = subject.all
10
- if result
11
- expect(result.keys).to include :account_file_path
12
- else
13
- expect(subject.code).to eq '901162'
14
- end
15
- end
16
- end
data/spec/bulk_spec.rb DELETED
@@ -1,35 +0,0 @@
1
- # describe ::PPC::Baidu::Bulk do
2
- # subject{::PPC::Baidu::Bulk.new(
3
- # debug:true,
4
- # username:'',
5
- # password:'',
6
- # token:'')
7
- # }
8
- # it "could get file_id_of_all" do
9
- # begin
10
- # result = subject.file_id_of_all
11
- # rescue
12
- # expect(subject.code).to eq '901162'
13
- # end
14
-
15
- # if result.nil?
16
- # expect(subject.code).to eq '901162'
17
- # else
18
- # expect(result.size).to eq 32
19
- # end
20
- # end
21
- # end
22
-
23
- describe ::PPC::Sogou::Bulk do
24
- subject{::PPC::Sogou::Bulk.new(
25
- debug:true,
26
- username:'zongheelongexact1@sogou.com',
27
- password:'elongsem2014J',
28
- token:'a2c5a0b092c0aeb63923b92c03aaa5ea')
29
- }
30
- it "could get file_id_of_all" do
31
- # result = subject.file_id_of_all
32
-
33
- p subject.path('2ee48aa67a06bf05c3fd54f84c6a4656')
34
- end
35
- end
data/spec/plan_spec.rb DELETED
@@ -1,17 +0,0 @@
1
- describe ::PPC::Baidu::Plan do
2
- subject{::PPC::Baidu::Plan.new(
3
- debug:true,
4
- username:'',
5
- password:'',
6
- se_id: '',
7
- token:''
8
- )}
9
- it "could download all plan" do
10
- result = subject.all
11
- if result
12
- expect(result.keys).to include :account_file_path
13
- else
14
- expect(subject.code).to eq '901162'
15
- end
16
- end
17
- end