ppc 1.0.6 → 1.3.0
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.
- checksums.yaml +4 -4
- data/.gitignore +31 -23
- data/LICENSE +22 -0
- data/README.md +5 -28
- data/lib/ppc/api/baidu/account.rb +47 -0
- data/lib/ppc/api/baidu/bulk.rb +41 -0
- data/lib/ppc/api/baidu/creative.rb +125 -0
- data/lib/ppc/api/baidu/group.rb +111 -0
- data/lib/ppc/api/baidu/keyword.rb +193 -0
- data/lib/ppc/api/baidu/plan.rb +65 -0
- data/lib/ppc/api/baidu/report.rb +124 -0
- data/lib/ppc/api/baidu.rb +132 -0
- data/lib/ppc/api.rb +8 -0
- data/lib/ppc/baidu/account.rb +55 -27
- data/lib/ppc/baidu/group.rb +99 -0
- data/lib/ppc/baidu/key.rb +38 -0
- data/lib/ppc/baidu/plan.rb +69 -0
- data/lib/ppc/baidu/report.rb +45 -13
- data/lib/ppc/baidu.rb +28 -25
- data/lib/ppc/operation/account.rb +40 -0
- data/lib/ppc/operation/creative.rb +28 -0
- data/lib/ppc/operation/group.rb +59 -0
- data/lib/ppc/operation/keyword.rb +32 -0
- data/lib/ppc/operation/plan.rb +47 -0
- data/lib/ppc/operation.rb +161 -0
- data/lib/ppc.rb +3 -7
- data/ppc.gemspec +4 -4
- data/spec/api_baidu_account_spec.rb +18 -0
- data/spec/api_baidu_creative_spec.rb +71 -0
- data/spec/api_baidu_group_spec.rb +50 -0
- data/spec/api_baidu_keyword_spec.rb +64 -0
- data/spec/api_baidu_plan_spec.rb +42 -0
- data/spec/api_baidu_report_spec.rb +32 -0
- data/spec/api_baidu_spec.rb +60 -0
- data/spec/baidu_account_spec.rb +32 -0
- data/spec/baidu_bulk_spec.rb +21 -0
- data/spec/baidu_group_spec.rb +56 -0
- data/spec/baidu_plan_spec.rb +129 -0
- data/spec/{report_spec.rb → baidu_report_spec.rb} +0 -0
- data/spec/operation_spec.rb +87 -0
- data/spec/operation_spec_helper.rb +53 -0
- data/spec/spec_helper.rb +18 -1
- metadata +53 -22
- data/Gemfile +0 -4
- data/LICENSE.txt +0 -22
- data/Rakefile +0 -2
- data/lib/ppc/qihu/account.rb +0 -0
- data/lib/ppc/qihu.rb +0 -0
- data/lib/ppc/sogou/bulk.rb +0 -48
- data/lib/ppc/sogou.rb +0 -125
- data/spec/account_spec.rb +0 -16
- data/spec/bulk_spec.rb +0 -35
- data/spec/plan_spec.rb +0 -17
data/lib/ppc/baidu/report.rb
CHANGED
@@ -16,21 +16,53 @@ module PPC
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def file_id_of_query(params = {})
|
19
|
+
begin
|
20
|
+
startDate = DateTime.parse(params[:start]).iso8601
|
21
|
+
endDate = DateTime.parse(params[:end]).iso8601
|
22
|
+
rescue Exception => e
|
23
|
+
startDate = (Time.now - 2*24*3600).utc.iso8601
|
24
|
+
endDate = (Time.now - 24*3600).utc.iso8601
|
25
|
+
end
|
19
26
|
options = {
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
27
|
+
reportRequestType: {
|
28
|
+
performanceData: params[:fields] || %w(click impression),
|
29
|
+
startDate: startDate,
|
30
|
+
endDate: endDate,
|
31
|
+
idOnly: params[:id_only]|| false,
|
32
|
+
levelOfDetails: params[:level] || 12,
|
33
|
+
format: params[:format] || 2,
|
34
|
+
reportType: params[:type] || 6,
|
35
|
+
statRange: params[:range] || 2,
|
36
|
+
unitOfTime: params[:unit] || 5,
|
37
|
+
device: params[:device] || 0
|
38
|
+
}
|
32
39
|
}
|
33
|
-
options
|
40
|
+
get_report_id(options)
|
41
|
+
end
|
42
|
+
|
43
|
+
def file_id_of_cost(params={})
|
44
|
+
begin
|
45
|
+
startDate = DateTime.parse(params[:start]).iso8601
|
46
|
+
endDate = DateTime.parse(params[:end]).iso8601
|
47
|
+
rescue Exception => e
|
48
|
+
startDate = (Time.now - 2*24*3600).utc.iso8601
|
49
|
+
endDate = (Time.now - 24*3600).utc.iso8601
|
50
|
+
end
|
51
|
+
options = {
|
52
|
+
reportRequestType: {
|
53
|
+
performanceData: params[:fields] || %w(impression click cpc cost ctr cpm position conversion),
|
54
|
+
startDate: startDate,
|
55
|
+
endDate: endDate,
|
56
|
+
levelOfDetails: params[:level] || 11, #::Baidu::SEM::LevelOfDetails::KEYWORDID,
|
57
|
+
reportType: params[:type] || 14, #::Baidu::SEM::ReportType::KEYWORDID,
|
58
|
+
statRange: params[:range] || 11, # ::Baidu::SEM::StatRange::KEYWORDID,
|
59
|
+
unitOfTime: params[:unit] || 5 #::Baidu::SEM::UnitOfTime::DAY
|
60
|
+
}
|
61
|
+
}
|
62
|
+
get_report_id(options)
|
63
|
+
end
|
64
|
+
|
65
|
+
def get_report_id(options={})
|
34
66
|
response = request('getProfessionalReportId',options)
|
35
67
|
body = response[:envelope][:body]
|
36
68
|
raise "no result" if body.nil?
|
data/lib/ppc/baidu.rb
CHANGED
@@ -1,40 +1,49 @@
|
|
1
1
|
require 'ppc/baidu/account'
|
2
2
|
require 'ppc/baidu/plan'
|
3
3
|
require 'ppc/baidu/bulk'
|
4
|
+
require 'ppc/baidu/group'
|
5
|
+
require 'ppc/baidu/key'
|
4
6
|
require 'ppc/baidu/report'
|
5
7
|
require 'awesome_print'
|
6
|
-
require '
|
8
|
+
require 'net/http'
|
9
|
+
require 'net/https'
|
10
|
+
require 'json'
|
11
|
+
# require 'savon'
|
7
12
|
module PPC
|
8
13
|
class Baidu
|
9
14
|
include ::PPC
|
10
15
|
|
11
16
|
def initialize(params = {})
|
12
17
|
@service = params[:service] + 'Service'
|
13
|
-
@port_name = params[:service] + 'Service'
|
14
18
|
@username = params[:username]
|
15
19
|
@password = params[:password]
|
16
20
|
@token = params[:token]
|
17
|
-
@client = Savon.new("https://api.baidu.com/sem/sms/v3/#{@service}?wsdl")
|
18
21
|
@debug = params[:debug] || false
|
19
22
|
end
|
20
23
|
|
21
24
|
|
22
|
-
def request(method,params = {})
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
def request(method,params = {}, with_header = false)
|
26
|
+
uri = URI("https://api.baidu.com/json/sms/v3/#{@service}/#{method}")
|
27
|
+
http_body = {
|
28
|
+
header: request_header,
|
29
|
+
body: params
|
30
|
+
}.to_json
|
31
|
+
|
32
|
+
http_header = {
|
33
|
+
'Content-Type' => 'application/json; charset=UTF-8'
|
27
34
|
}
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
response
|
35
|
+
|
36
|
+
http = Net::HTTP.new(uri.host, 443)
|
37
|
+
http.set_debug_output $stderr
|
38
|
+
http.use_ssl = true
|
39
|
+
|
40
|
+
response = http.post(uri.path, http_body, http_header)
|
41
|
+
response = (JSON.parse response.body)
|
42
|
+
# if not needed, only return body
|
43
|
+
return response['body'] unless with_header else response
|
34
44
|
end
|
35
45
|
|
36
46
|
def operations
|
37
|
-
@client.operations(@service,@service)
|
38
47
|
end
|
39
48
|
|
40
49
|
protected
|
@@ -90,18 +99,12 @@ module PPC
|
|
90
99
|
|
91
100
|
private
|
92
101
|
|
93
|
-
def make_operation(operation_name)
|
94
|
-
@client.operation(@service,@service,operation_name)
|
95
|
-
end
|
96
102
|
|
97
|
-
def
|
103
|
+
def request_header
|
98
104
|
{
|
99
|
-
:
|
100
|
-
|
101
|
-
|
102
|
-
password: @password,
|
103
|
-
token: @token
|
104
|
-
}
|
105
|
+
username: @username,
|
106
|
+
password: @password,
|
107
|
+
token: @token
|
105
108
|
}
|
106
109
|
end
|
107
110
|
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'ppc/operation'
|
2
|
+
module PPC
|
3
|
+
module Operation
|
4
|
+
class Account
|
5
|
+
include ::PPC::Operation
|
6
|
+
|
7
|
+
def info
|
8
|
+
info = call('account').info(@auth)
|
9
|
+
@id = info[:result][0][:id] if @id == nil
|
10
|
+
return info
|
11
|
+
end
|
12
|
+
|
13
|
+
def update(account)
|
14
|
+
call('account').update(@auth,account)
|
15
|
+
end
|
16
|
+
|
17
|
+
# plan methods
|
18
|
+
def plans
|
19
|
+
call('plan').all(@auth)
|
20
|
+
end
|
21
|
+
|
22
|
+
def plan_ids
|
23
|
+
call('plan').ids(@auth)
|
24
|
+
end
|
25
|
+
|
26
|
+
# plan operation
|
27
|
+
include ::PPC::Operation::Plan_operation
|
28
|
+
|
29
|
+
# group opeartion
|
30
|
+
include ::PPC::Operation::Group_operation
|
31
|
+
|
32
|
+
# keyword opeartion
|
33
|
+
include ::PPC::Operation::Keyword_operation
|
34
|
+
|
35
|
+
# creative opeartion
|
36
|
+
include ::PPC::Operation::Creative_operation
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,28 @@
|
|
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
|
@@ -0,0 +1,59 @@
|
|
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
|
@@ -0,0 +1,32 @@
|
|
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
|
@@ -0,0 +1,47 @@
|
|
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
|
@@ -0,0 +1,161 @@
|
|
1
|
+
module PPC
|
2
|
+
module Operation
|
3
|
+
|
4
|
+
attr_accessor :id
|
5
|
+
|
6
|
+
def initialize(params)
|
7
|
+
@id = params[:id]
|
8
|
+
@se = params[:se]
|
9
|
+
@auth = {
|
10
|
+
username: params[:username],
|
11
|
+
password: params[:password],
|
12
|
+
token: params[:token]
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(service)
|
17
|
+
eval "::PPC::API::#{@se.capitalize}::#{service.capitalize}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def download(params = {})
|
21
|
+
bulk = ::PPC::Baidu::Bulk.new({
|
22
|
+
username: @username,
|
23
|
+
password: @password,
|
24
|
+
token: @token,
|
25
|
+
debug: @debug
|
26
|
+
})
|
27
|
+
|
28
|
+
params[:extended] = params[:extended] || 2
|
29
|
+
|
30
|
+
begin
|
31
|
+
file_id = bulk.file_id_of_all(params)
|
32
|
+
puts "file_id: #{file_id}" if @debug
|
33
|
+
|
34
|
+
loop do
|
35
|
+
state = bulk.state(file_id)
|
36
|
+
raise "invalid file state: #{state}" unless %w(1 2 3 null).include? state
|
37
|
+
break if state == '3'
|
38
|
+
puts "waiting for #{file_id} to be ready. current state:#{state}" if @debug
|
39
|
+
sleep 3
|
40
|
+
end
|
41
|
+
puts "#{file_id} is ready" if @debug
|
42
|
+
return bulk.path(file_id)
|
43
|
+
rescue
|
44
|
+
raise BulkException.new(file_id,bulk)
|
45
|
+
end
|
46
|
+
|
47
|
+
return false
|
48
|
+
end
|
49
|
+
|
50
|
+
# ++++++++ #
|
51
|
+
# Lazy Code #
|
52
|
+
# ++++++++ #
|
53
|
+
|
54
|
+
# auxilary fucntion
|
55
|
+
def get_obj( ids, service )
|
56
|
+
'''
|
57
|
+
Return service object.
|
58
|
+
Providing single id, return single object.
|
59
|
+
Providing multiple ids, return Array of objects
|
60
|
+
'''
|
61
|
+
class_obj = eval "::PPC::Opeartion::#{service.capitalize}"
|
62
|
+
param = @auth
|
63
|
+
param[:se] = @se
|
64
|
+
objs = []
|
65
|
+
|
66
|
+
ids.each do |id|
|
67
|
+
param[:id] = id
|
68
|
+
objs << class_obj.new( param )
|
69
|
+
end
|
70
|
+
|
71
|
+
return objs[0] if objs.length == 1 else objs
|
72
|
+
end
|
73
|
+
|
74
|
+
# +++++ Plan opeartion funcitons +++++ #
|
75
|
+
module Plan_operation
|
76
|
+
def get_plan( ids )
|
77
|
+
::PPC::Opeartion::get_obj( ids, 'plan')
|
78
|
+
end
|
79
|
+
|
80
|
+
def add_plan( plans )
|
81
|
+
call('plan').add(@auth,plans)
|
82
|
+
end
|
83
|
+
|
84
|
+
def update_plan( plans )
|
85
|
+
call('plan').update(@auth,plans)
|
86
|
+
end
|
87
|
+
|
88
|
+
def delete_plan( ids )
|
89
|
+
call('plan').delete(@auth,ids)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# +++++ Group opeartion funcitons +++++ #
|
94
|
+
module Group_operation
|
95
|
+
def get_group( ids )
|
96
|
+
::PPC::Opeartion::get_obj( ids, 'group')
|
97
|
+
end
|
98
|
+
|
99
|
+
def add_group( groups )
|
100
|
+
call('group').add(@auth,groups )
|
101
|
+
end
|
102
|
+
|
103
|
+
def update_group( groups )
|
104
|
+
call('group').update( @auth, groups )
|
105
|
+
end
|
106
|
+
|
107
|
+
def delete_group( ids )
|
108
|
+
call('group').delete( @auth, ids )
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
# +++++ Keyword opeartion funcitons +++++ #
|
113
|
+
module Keyword_operation
|
114
|
+
def get_keyword( ids )
|
115
|
+
::PPC::Opeartion::get_obj( ids, 'keyword')
|
116
|
+
end
|
117
|
+
|
118
|
+
def add_keyword( keywords )
|
119
|
+
call('keyword').add( @auth, keywords )
|
120
|
+
end
|
121
|
+
|
122
|
+
def update_keyword( keywords)
|
123
|
+
call('keyword').update( @auth, keywords )
|
124
|
+
end
|
125
|
+
|
126
|
+
def delete_keyword( ids )
|
127
|
+
call('keyword').delete( @auth, ids )
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
# +++++ Creative opeartion funcitons +++++ #
|
132
|
+
module Creative_operation
|
133
|
+
def get_creative( ids )
|
134
|
+
::PPC::Opeartion::get_obj( ids, 'creative')
|
135
|
+
end
|
136
|
+
|
137
|
+
def add_creative( creatives )
|
138
|
+
call('creative').add( @auth, creatives )
|
139
|
+
end
|
140
|
+
|
141
|
+
def update_creative( creatives )
|
142
|
+
call('creative').update( @auth, creatives )
|
143
|
+
end
|
144
|
+
|
145
|
+
def delete_creative( ids )
|
146
|
+
call('creative').delete( @auth, ids )
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
end # Opeartion
|
151
|
+
end # PPC
|
152
|
+
|
153
|
+
# requires are moved to the end of the file
|
154
|
+
# because if we load files before defining the
|
155
|
+
# module ::PPC::Operation. Errors of 'uninitialized constance'
|
156
|
+
# will occur
|
157
|
+
require 'ppc/operation/account'
|
158
|
+
require 'ppc/operation/group'
|
159
|
+
require 'ppc/operation/plan'
|
160
|
+
require 'ppc/operation/keyword'
|
161
|
+
require 'ppc/operation/creative'
|
data/lib/ppc.rb
CHANGED
@@ -1,11 +1,7 @@
|
|
1
|
-
require 'ppc/
|
2
|
-
require 'ppc/
|
1
|
+
require 'ppc/api'
|
2
|
+
require 'ppc/operation'
|
3
3
|
module PPC
|
4
|
-
VERSION = "1.0
|
5
|
-
attr_reader :header,:body,:rquota,:quota,:status,:desc,:oprs,:oprtime,:code,:message
|
6
|
-
attr_accessor :username,:password,:token,:debug
|
7
|
-
def initialize(params = {})
|
8
|
-
end
|
4
|
+
VERSION = "1.3.0"
|
9
5
|
|
10
6
|
protected
|
11
7
|
def print_debug(var,varname=nil)
|
data/ppc.gemspec
CHANGED
@@ -5,10 +5,10 @@ require 'ppc'
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "ppc"
|
7
7
|
spec.version = PPC::VERSION
|
8
|
-
spec.authors = ["
|
9
|
-
spec.email = ["
|
10
|
-
spec.summary = %q{ppc api for
|
11
|
-
spec.description = %q{ppc api for
|
8
|
+
spec.authors = ["Chienli Ma, 刘梦晨, 刘明"]
|
9
|
+
spec.email = ["maqianlie@gmail.com, liuyu_tc@163.com, seoaqua@qq.com"]
|
10
|
+
spec.summary = %q{ppc api for baidu qihu sogou}
|
11
|
+
spec.description = %q{ppc api for baidu qihu sogou}
|
12
12
|
spec.homepage = "http://github.com/seoaqua/ppc"
|
13
13
|
spec.license = "MIT"
|
14
14
|
|
@@ -0,0 +1,18 @@
|
|
1
|
+
describe ::PPC::API::Baidu::Account do
|
2
|
+
auth = {}
|
3
|
+
auth[:username] = $baidu_username
|
4
|
+
auth[:password] = $baidu_password
|
5
|
+
auth[:token] = $baidu_token
|
6
|
+
|
7
|
+
it 'can get account info' do
|
8
|
+
result = ::PPC::API::Baidu::Account::info( auth )
|
9
|
+
is_success( result )
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'can update account' do
|
13
|
+
update = {budget:2990}
|
14
|
+
result = ::PPC::API::Baidu::Account::update( auth, update )
|
15
|
+
is_success( result )
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
describe ::PPC::API::Baidu::Creative do
|
2
|
+
auth = {}
|
3
|
+
auth[:username] = $baidu_username
|
4
|
+
auth[:password] = $baidu_password
|
5
|
+
auth[:token] = $baidu_token
|
6
|
+
|
7
|
+
Test_group_id = ::PPC::API::Baidu::Group::all( auth )[:result][0]['adgroupIds'][0]
|
8
|
+
Test_plan_id = ::PPC::API::Baidu::Plan::all( auth )[:result][0]['campaignId']
|
9
|
+
Test_creative_id = []
|
10
|
+
Test_domain = $baidu_domain
|
11
|
+
|
12
|
+
it 'can add creative' do
|
13
|
+
creative = { group_id: Test_group_id,
|
14
|
+
title: 'Test', preference:1,
|
15
|
+
description1:'this is rest',
|
16
|
+
description2:'also is a test',
|
17
|
+
pc_destination:Test_domain,
|
18
|
+
pc_display:Test_domain }
|
19
|
+
|
20
|
+
response = ::PPC::API::Baidu::Creative::add( auth, creative )
|
21
|
+
is_success( response )
|
22
|
+
p "HAHAHAAHAH Creative"
|
23
|
+
p response
|
24
|
+
Test_creative_id << response[:result][0][:id]
|
25
|
+
end
|
26
|
+
|
27
|
+
# # 此测试未能通过,总是会出现莫名其妙的错误。
|
28
|
+
# it 'can update creative' do
|
29
|
+
# update = { id:Test_creative_id[0],
|
30
|
+
# title:'ElongUpdateTest',
|
31
|
+
# description1:'test for update',
|
32
|
+
# pause:true}
|
33
|
+
# response = ::PPC::API::Baidu::Creative::update( auth, update, true )
|
34
|
+
# is_successed( response )
|
35
|
+
# end
|
36
|
+
|
37
|
+
it 'can activate creative' do
|
38
|
+
response = ::PPC::API::Baidu::Creative::activate( auth, Test_creative_id )
|
39
|
+
is_success( response )
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'can get status' do
|
43
|
+
response1 = ::PPC::API::Baidu::Creative::status( auth, Test_group_id, 'group' )
|
44
|
+
response2 = ::PPC::API::Baidu::Creative::status( auth, Test_creative_id, 'creative' )
|
45
|
+
response3 = ::PPC::API::Baidu::Creative::status( auth, Test_plan_id, 'plan' )
|
46
|
+
is_success( response1 )
|
47
|
+
is_success( response2 )
|
48
|
+
is_success( response3 )
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'can search id by group id' do
|
52
|
+
response = ::PPC::API::Baidu::Creative::get_by_group_id( auth, Test_group_id, 0 )
|
53
|
+
is_success( response )
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'can search creative by group id' do
|
57
|
+
response = ::PPC::API::Baidu::Creative::search_by_group_id( auth, Test_group_id, 0 )
|
58
|
+
is_success( response )
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'can search creative by creative id' do
|
62
|
+
response = ::PPC::API::Baidu::Creative::get( auth, Test_creative_id, 0 )
|
63
|
+
is_success( response )
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'can delete creative' do
|
67
|
+
response = ::PPC::API::Baidu::Creative::delete( auth, Test_creative_id )
|
68
|
+
is_success( response )
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|