ppc 1.3.0 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -1
- data/LICENSE +334 -17
- data/README.md +75 -3
- data/lib/ppc.rb +3 -1
- data/lib/ppc/api.rb +137 -2
- data/lib/ppc/api/baidu.rb +20 -99
- data/lib/ppc/api/baidu/account.rb +21 -21
- data/lib/ppc/api/baidu/bulk.rb +39 -3
- data/lib/ppc/api/baidu/creative.rb +33 -33
- data/lib/ppc/api/baidu/group.rb +14 -14
- data/lib/ppc/api/baidu/keyword.rb +57 -46
- data/lib/ppc/api/baidu/phone_new_creative.rb +51 -0
- data/lib/ppc/api/baidu/plan.rb +34 -31
- data/lib/ppc/api/baidu/rank.rb +23 -0
- data/lib/ppc/api/baidu/report.rb +100 -81
- data/lib/ppc/api/qihu.rb +150 -0
- data/lib/ppc/api/qihu/account.rb +86 -0
- data/lib/ppc/api/qihu/bulk.rb +35 -0
- data/lib/ppc/api/qihu/creative.rb +108 -0
- data/lib/ppc/api/qihu/group.rb +96 -0
- data/lib/ppc/api/qihu/keyword.rb +113 -0
- data/lib/ppc/api/qihu/plan.rb +64 -0
- data/lib/ppc/api/qihu/rank.rb +25 -0
- data/lib/ppc/api/qihu/report.rb +159 -0
- data/lib/ppc/api/qihu/sublink.rb +71 -0
- data/lib/ppc/api/shenma.rb +64 -0
- data/lib/ppc/api/shenma/report.rb +135 -0
- data/lib/ppc/api/sm.rb +50 -0
- data/lib/ppc/api/sm/account.rb +44 -0
- data/lib/ppc/api/sm/bulk.rb +69 -0
- data/lib/ppc/api/sm/creative.rb +86 -0
- data/lib/ppc/api/sm/group.rb +94 -0
- data/lib/ppc/api/sm/keyword.rb +132 -0
- data/lib/ppc/api/sm/phone_new_creative.rb +51 -0
- data/lib/ppc/api/sm/plan.rb +63 -0
- data/lib/ppc/api/sm/report.rb +136 -0
- data/lib/ppc/api/sogou.rb +118 -0
- data/lib/ppc/api/sogou/account.rb +42 -0
- data/lib/ppc/api/sogou/bulk.rb +69 -0
- data/lib/ppc/api/sogou/creative.rb +117 -0
- data/lib/ppc/api/sogou/group.rb +123 -0
- data/lib/ppc/api/sogou/keyword.rb +188 -0
- data/lib/ppc/api/sogou/plan.rb +66 -0
- data/lib/ppc/api/sogou/report.rb +129 -0
- data/lib/ppc/ext.rb +17 -0
- data/lib/ppc/operation.rb +50 -36
- data/lib/ppc/operation/account.rb +19 -7
- data/lib/ppc/operation/creative.rb +7 -7
- data/lib/ppc/operation/group.rb +2 -2
- data/lib/ppc/operation/keyword.rb +11 -8
- data/lib/ppc/operation/report.rb +23 -0
- data/ppc.gemspec +14 -4
- data/spec/baidu/api_baidu_account_spec.rb +16 -0
- data/spec/baidu/api_baidu_creative_spec.rb +73 -0
- data/spec/{api_baidu_group_spec.rb → baidu/api_baidu_group_spec.rb} +12 -17
- data/spec/baidu/api_baidu_keyword_spec.rb +61 -0
- data/spec/baidu/api_baidu_phone_spec.rb +22 -0
- data/spec/{api_baidu_plan_spec.rb → baidu/api_baidu_plan_spec.rb} +11 -10
- data/spec/baidu/api_baidu_report_spec.rb +44 -0
- data/spec/{api_baidu_spec.rb → baidu/api_baidu_spec.rb} +10 -15
- data/spec/operation/operation_baidu_report_spec.rb +17 -0
- data/spec/operation/operation_baidu_spec.rb +126 -0
- data/spec/operation/operation_qihu_report_spec.rb +18 -0
- data/spec/operation/operation_qihu_spec.rb +94 -0
- data/spec/operation/operation_sm_report_spec.rb +21 -0
- data/spec/operation/operation_sogou_report_spec.rb +17 -0
- data/spec/operation/operation_sogou_spec.rb +88 -0
- data/spec/{operation_spec_helper.rb → operation/operation_spec_helper.rb} +3 -5
- data/spec/qihu/api_qihu_account_spec.rb +29 -0
- data/spec/qihu/api_qihu_creative_spec.rb +48 -0
- data/spec/qihu/api_qihu_group_spec.rb +40 -0
- data/spec/qihu/api_qihu_keyword_spec.rb +50 -0
- data/spec/qihu/api_qihu_plan_spec.rb +39 -0
- data/spec/qihu/api_qihu_report_spec.rb +54 -0
- data/spec/qihu/api_qihu_sublink_spec.rb +36 -0
- data/spec/sm/api_sm_account_spec.rb +8 -0
- data/spec/sm/api_sm_creative_spec.rb +52 -0
- data/spec/sm/api_sm_group_spec.rb +75 -0
- data/spec/sm/api_sm_keyword_spec.rb +59 -0
- data/spec/sm/api_sm_plan_spec.rb +39 -0
- data/spec/sm/api_sm_report_spec.rb +30 -0
- data/spec/sogou/api_sogou_account_spec.rb +17 -0
- data/spec/sogou/api_sogou_creative_spec.rb +51 -0
- data/spec/sogou/api_sogou_group_spec.rb +50 -0
- data/spec/sogou/api_sogou_keyword_spec.rb +54 -0
- data/spec/sogou/api_sogou_plan_spec.rb +43 -0
- data/spec/sogou/api_sogou_report_spec.rb +51 -0
- data/spec/spec_helper.rb +49 -10
- metadata +140 -46
- data/lib/ppc/baidu.rb +0 -152
- data/lib/ppc/baidu/account.rb +0 -88
- data/lib/ppc/baidu/bulk.rb +0 -52
- data/lib/ppc/baidu/group.rb +0 -99
- data/lib/ppc/baidu/key.rb +0 -38
- data/lib/ppc/baidu/plan.rb +0 -85
- data/lib/ppc/baidu/report.rb +0 -82
- data/spec/api_baidu_account_spec.rb +0 -18
- data/spec/api_baidu_creative_spec.rb +0 -71
- data/spec/api_baidu_keyword_spec.rb +0 -64
- data/spec/api_baidu_report_spec.rb +0 -32
- data/spec/baidu_account_spec.rb +0 -32
- data/spec/baidu_bulk_spec.rb +0 -21
- data/spec/baidu_group_spec.rb +0 -56
- data/spec/baidu_plan_spec.rb +0 -129
- data/spec/baidu_report_spec.rb +0 -24
- data/spec/operation_spec.rb +0 -87
data/lib/ppc/baidu/report.rb
DELETED
@@ -1,82 +0,0 @@
|
|
1
|
-
module PPC
|
2
|
-
class Baidu
|
3
|
-
class ReportException < Exception
|
4
|
-
attr_reader :file_id,:report,:exception
|
5
|
-
def initialize(file_id,report,exception)
|
6
|
-
@file_id = file_id
|
7
|
-
@report = report
|
8
|
-
@exception = exception
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
class Report < ::PPC::Baidu
|
13
|
-
def initialize(params = {})
|
14
|
-
params[:service] = 'Report'
|
15
|
-
super
|
16
|
-
end
|
17
|
-
|
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
|
26
|
-
options = {
|
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
|
-
}
|
39
|
-
}
|
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={})
|
66
|
-
response = request('getProfessionalReportId',options)
|
67
|
-
body = response[:envelope][:body]
|
68
|
-
raise "no result" if body.nil?
|
69
|
-
body[:get_professional_report_id_response][:report_id]
|
70
|
-
end
|
71
|
-
|
72
|
-
def state(id)
|
73
|
-
raise "empty id" if id.nil? or id.empty?
|
74
|
-
request('getReportState',{reportId:id})[:envelope][:body][:get_report_state_response][:is_generated]
|
75
|
-
end
|
76
|
-
|
77
|
-
def path(id)
|
78
|
-
request('getReportFileUrl',{reportId:id})[:envelope][:body][:get_report_file_url_response][:report_file_path]
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
@@ -1,18 +0,0 @@
|
|
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
|
@@ -1,71 +0,0 @@
|
|
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
|
@@ -1,64 +0,0 @@
|
|
1
|
-
describe ::PPC::API::Baidu::Keyword 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::ids( auth )[:result][0]['adgroupIds'][0]
|
8
|
-
Test_plan_id = ::PPC::API::Baidu::Plan::all( auth )[:result][0]['campaignId']
|
9
|
-
Test_keyword_id = []
|
10
|
-
|
11
|
-
Test_domain = $baidu_domain
|
12
|
-
|
13
|
-
it 'can search keyword by group id' do
|
14
|
-
response = ::PPC::API::Baidu::Keyword::search_by_group_id( auth, Test_group_id )
|
15
|
-
is_success( response )
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'can add keyword' do
|
19
|
-
keyword = { group_id: Test_group_id, keyword: 'Test', match_type:'exact' }
|
20
|
-
response = ::PPC::API::Baidu::Keyword::add( auth, keyword )
|
21
|
-
is_success( response )
|
22
|
-
Test_keyword_id << response[:result][0][:id]
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'can update keyword' do
|
26
|
-
update = { id:Test_keyword_id[0], pc_destination: Test_domain, pause:true}
|
27
|
-
response = ::PPC::API::Baidu::Keyword::update( auth, update )
|
28
|
-
is_success( response )
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'can activate keyword' do
|
32
|
-
response = ::PPC::API::Baidu::Keyword::activate( auth, Test_keyword_id )
|
33
|
-
is_success( response )
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'can get status' do
|
37
|
-
response1 = ::PPC::API::Baidu::Keyword::status( auth, Test_group_id, 'group' )
|
38
|
-
response2 = ::PPC::API::Baidu::Keyword::status( auth, Test_keyword_id, 'keyword' )
|
39
|
-
response3 = ::PPC::API::Baidu::Keyword::status( auth, Test_plan_id, 'plan' )
|
40
|
-
is_success( response1 )
|
41
|
-
is_success( response2 )
|
42
|
-
is_success( response3 )
|
43
|
-
end
|
44
|
-
|
45
|
-
# it 'can get quality' do
|
46
|
-
# response1 = ::PPC::API::Baidu::Keyword::quality( auth, Test_group_id, 'group', true )
|
47
|
-
# response2 = ::PPC::API::Baidu::Keyword::quality( auth, Test_keyword_id, 'keyword', true )
|
48
|
-
# response3 = ::PPC::API::Baidu::Keyword::quality( auth, Test_plan_id, 'plan', true )
|
49
|
-
# is_successed( response1 )
|
50
|
-
# is_successed( response2 )
|
51
|
-
# is_successed( response3 )
|
52
|
-
# end
|
53
|
-
|
54
|
-
it 'can get 10-quality' do
|
55
|
-
response = ::PPC::API::Baidu::Keyword::quality( auth, Test_keyword_id, 'keyword', 'pc' )
|
56
|
-
is_success( response )
|
57
|
-
end
|
58
|
-
|
59
|
-
it 'can delete keyword' do
|
60
|
-
response = ::PPC::API::Baidu::Keyword::delete( auth, Test_keyword_id )
|
61
|
-
is_success( response )
|
62
|
-
end
|
63
|
-
|
64
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
describe ::PPC::API::Baidu::Report do
|
2
|
-
auth = {}
|
3
|
-
auth[:username] = $baidu_username
|
4
|
-
auth[:password] = $baidu_password
|
5
|
-
auth[:token] = $baidu_token
|
6
|
-
|
7
|
-
Test_report_id = []
|
8
|
-
|
9
|
-
it 'can get real time report' do
|
10
|
-
param = { type: 'plan', level:'plan',range:'plan',unit:'week',device:'all' }
|
11
|
-
response = ::PPC::API::Baidu::Report::get_realtime( auth, param, 'data' )
|
12
|
-
is_success( response )
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'can get professional report id' do
|
16
|
-
param = { type: 'plan', level:'plan',range:'plan',unit:'week',device:'all' }
|
17
|
-
response = ::PPC::API::Baidu::Report::get_id( auth, param )
|
18
|
-
is_success( response )
|
19
|
-
Test_report_id << response[:result]
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'can get professional report status' do
|
23
|
-
response = ::PPC::API::Baidu::Report::get_status( auth, Test_report_id[0] )
|
24
|
-
is_success( response )
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'can get professional report download URL' do
|
28
|
-
response = ::PPC::API::Baidu::Report::get_file_url( auth, Test_report_id[0] )
|
29
|
-
is_success( response )
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
data/spec/baidu_account_spec.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
describe ::PPC::Baidu::Account do
|
2
|
-
subject{::PPC::Baidu::Account.new(
|
3
|
-
debug:true,
|
4
|
-
username:$baidu_username,
|
5
|
-
password:$baidu_password,
|
6
|
-
token:$baidu_token
|
7
|
-
)}
|
8
|
-
|
9
|
-
it "prints all info" do
|
10
|
-
expect(subject.info.keys).to eq ["userid", "balance", "cost", "payment", "budgetType", "budget", "regionTarget", "excludeIp", "openDomains", "regDomain", "budgetOfflineTime", "weeklyBudget", "userStat", "isDynamicCreative", "dynamicCreativeParam", "opt"]
|
11
|
-
end
|
12
|
-
|
13
|
-
it "prints all updated info" do
|
14
|
-
info = { budget_type: 1, budget: 3000 }
|
15
|
-
response = subject.update( info )
|
16
|
-
|
17
|
-
expect(response.keys).to eq ["userid", "balance", "cost", "payment", "budgetType", "budget", "regionTarget", "excludeIp", "openDomains", "regDomain", "budgetOfflineTime", "weeklyBudget", "userStat", "isDynamicCreative", "dynamicCreativeParam", "opt"]
|
18
|
-
expect(response["budgetType"]).to eq 1
|
19
|
-
expect(response["budget"]).to eq 3000
|
20
|
-
end
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
# it "could download all plan" do
|
25
|
-
# result = subject.all
|
26
|
-
# if result
|
27
|
-
# expect(result.keys).to include :account_file_path
|
28
|
-
# else
|
29
|
-
# expect(subject.code).to eq '901162'
|
30
|
-
# end
|
31
|
-
# end
|
32
|
-
end
|
data/spec/baidu_bulk_spec.rb
DELETED
@@ -1,21 +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
|
data/spec/baidu_group_spec.rb
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
describe ::PPC::Baidu::Group do
|
2
|
-
subject{::PPC::Baidu::Group.new(
|
3
|
-
debug:true,
|
4
|
-
username:$baidu_username,
|
5
|
-
password:$baidu_password,
|
6
|
-
token:$baidu_token
|
7
|
-
)}
|
8
|
-
|
9
|
-
Test_group1 = {plan_id: 8537330, name:"test_group1",maxprice: 500 }
|
10
|
-
Test_group2 = {plan_id: 8537330, name:"test_group2",maxprice: 500 }
|
11
|
-
Test_groups = [ Test_group1, Test_group2 ]
|
12
|
-
$test_group_ids = []
|
13
|
-
$test_plan_ids = []
|
14
|
-
|
15
|
-
it " can get all group info " do
|
16
|
-
response = subject.all()
|
17
|
-
response.each{ |campaign|
|
18
|
-
expect( campaign.keys ).to eq ["campaignId", "adgroupIds"]
|
19
|
-
$test_plan_ids << campaign["campaignId"]
|
20
|
-
}
|
21
|
-
end
|
22
|
-
|
23
|
-
it " can add group " do
|
24
|
-
response = subject.add( Test_groups, true )
|
25
|
-
expect( response['header']['desc'] ).to eq 'success'
|
26
|
-
|
27
|
-
# store test_group _id s
|
28
|
-
response = response['body']['adgroupTypes']
|
29
|
-
response.each{ |group|
|
30
|
-
$test_group_ids << group[ 'adgroupId' ]
|
31
|
-
}
|
32
|
-
end
|
33
|
-
|
34
|
-
it " can update group " do
|
35
|
-
updates = [ { group_id: $test_group_ids[0], maxprice:550 } ,
|
36
|
-
{ group_id: $test_group_ids[1], maxprice:550 } ]
|
37
|
-
response = subject.update( updates, true )
|
38
|
-
expect( response['header']['desc'] ).to eq 'success'
|
39
|
-
end
|
40
|
-
|
41
|
-
it "can search group by group id" do
|
42
|
-
response = subject.search_by_groupid( $test_group_ids , true)
|
43
|
-
expect( response["header"]["desc"] ).to eq "success"
|
44
|
-
end
|
45
|
-
|
46
|
-
it " can delete group " do
|
47
|
-
response = subject.delete( $test_group_ids )
|
48
|
-
expect( response ).to eq "success"
|
49
|
-
end
|
50
|
-
|
51
|
-
it "can search group by planId" do
|
52
|
-
response = subject.search_by_planid( $test_plan_ids , true)
|
53
|
-
expect( response["header"]["desc"] ).to eq "success"
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
data/spec/baidu_plan_spec.rb
DELETED
@@ -1,129 +0,0 @@
|
|
1
|
-
describe ::PPC::Baidu::Plan do
|
2
|
-
subject{::PPC::Baidu::Plan.new(
|
3
|
-
debug:true,
|
4
|
-
username:$baidu_username,
|
5
|
-
password:$baidu_password,
|
6
|
-
token:$baidu_token
|
7
|
-
)}
|
8
|
-
|
9
|
-
|
10
|
-
it "can update one plan" do
|
11
|
-
random_plan_id = subject.ids.first
|
12
|
-
new_name = "测试计划#{Time.now.to_i}"
|
13
|
-
response = subject.update_by_id(random_plan_id,{campaignName: new_name})
|
14
|
-
expect(response.class).to be Array
|
15
|
-
expect(response.first.class).to be Hash
|
16
|
-
expect(response.first['campaignName']).to eq new_name
|
17
|
-
end
|
18
|
-
|
19
|
-
it "can update two plans" do
|
20
|
-
random_plan_id1 = subject.ids[0]
|
21
|
-
random_plan_id2 = subject.ids[1]
|
22
|
-
|
23
|
-
new_name1 = "测试计划1_#{Time.now.to_i}"
|
24
|
-
new_name2 = "测试计划2_#{Time.now.to_i}"
|
25
|
-
|
26
|
-
plans = []
|
27
|
-
plans << {campaignId: random_plan_id1,campaignName: new_name1}
|
28
|
-
plans << {campaignId: random_plan_id2,campaignName: new_name2}
|
29
|
-
response = subject.update(plans)
|
30
|
-
expect(response.class).to be Array
|
31
|
-
expect(response.first.class).to be Hash
|
32
|
-
expect(response[0]['campaignName']).to eq new_name1
|
33
|
-
expect(response[1]['campaignName']).to eq new_name2
|
34
|
-
end
|
35
|
-
it "can get all plans" do
|
36
|
-
response = subject.plans
|
37
|
-
expect(response.class).to be Array
|
38
|
-
expect(response.first.class).to be Hash
|
39
|
-
expect(response.first['campaignId']).to be > 0
|
40
|
-
end
|
41
|
-
|
42
|
-
it "can add a plan" do
|
43
|
-
response = subject.add({name:"测试计划#{Time.now.to_i}"})
|
44
|
-
expect(response).to have_key 'campaignId'
|
45
|
-
expect(response['campaignId']).to be > 0
|
46
|
-
end
|
47
|
-
|
48
|
-
it "can add two plans" do
|
49
|
-
plan1 = {name:"测试计划1#{Time.now.to_i}"}
|
50
|
-
plan2 = {name:"测试计划2#{Time.now.to_i}"}
|
51
|
-
|
52
|
-
response = subject.add([plan1,plan2])
|
53
|
-
expect(response.class).to be Array
|
54
|
-
expect(response.first['campaignId']).to be > 0
|
55
|
-
expect(response[1]['campaignId']).to be > 0
|
56
|
-
end
|
57
|
-
|
58
|
-
it "can get all plan ids" do
|
59
|
-
response = subject.ids()
|
60
|
-
expect(response.class).to be Array
|
61
|
-
end
|
62
|
-
|
63
|
-
it "can get plans by one id" do
|
64
|
-
id = subject.ids().first
|
65
|
-
response = subject.get(id)
|
66
|
-
expect(response.class).to be Hash
|
67
|
-
expect(response['campaignId']).to be id
|
68
|
-
expect(response).to have_key 'campaignName'
|
69
|
-
end
|
70
|
-
|
71
|
-
it "can delete one plan by the id" do
|
72
|
-
ids = subject.ids()
|
73
|
-
response = subject.delete(ids.first)
|
74
|
-
expect(response).to be true
|
75
|
-
end
|
76
|
-
|
77
|
-
it "can delete two plans by the ids" do
|
78
|
-
ids = subject.ids()
|
79
|
-
pending if ids.size < 2
|
80
|
-
response = subject.delete(ids[0..1])
|
81
|
-
expect(response).to be true
|
82
|
-
end
|
83
|
-
# it "could download all plan" do
|
84
|
-
# result = subject.all
|
85
|
-
# if result
|
86
|
-
# expect(result.keys).to include :account_file_path
|
87
|
-
# else
|
88
|
-
# expect(subject.code).to eq '901162'
|
89
|
-
# end
|
90
|
-
# end
|
91
|
-
it "enables one plan by id" do
|
92
|
-
id = subject.ids().first
|
93
|
-
|
94
|
-
response = subject.enable(id)
|
95
|
-
expect(response.class).to be Array
|
96
|
-
expect(response.first.class).to be Hash
|
97
|
-
expect(response.first['pause']).to be false
|
98
|
-
end
|
99
|
-
|
100
|
-
it "enables two plans by ids" do
|
101
|
-
id1 = subject.ids()[0]
|
102
|
-
id2 = subject.ids()[1]
|
103
|
-
|
104
|
-
response = subject.enable([id1,id2])
|
105
|
-
expect(response.class).to be Array
|
106
|
-
expect(response.first.class).to be Hash
|
107
|
-
expect(response[0]['pause']).to be false
|
108
|
-
expect(response[1]['pause']).to be false
|
109
|
-
end
|
110
|
-
|
111
|
-
it "pauses one plan by id" do
|
112
|
-
id = subject.ids().first
|
113
|
-
|
114
|
-
response = subject.pause(id)
|
115
|
-
expect(response.class).to be Array
|
116
|
-
expect(response.first.class).to be Hash
|
117
|
-
expect(response.first['pause']).to be true
|
118
|
-
end
|
119
|
-
|
120
|
-
it "pauses two plans by ids" do
|
121
|
-
id1 = subject.ids()[0]
|
122
|
-
id2 = subject.ids()[1]
|
123
|
-
response = subject.pause([id1,id2])
|
124
|
-
expect(response.class).to be Array
|
125
|
-
expect(response.first.class).to be Hash
|
126
|
-
expect(response[0]['pause']).to be true
|
127
|
-
expect(response[1]['pause']).to be true
|
128
|
-
end
|
129
|
-
end
|