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
@@ -0,0 +1,50 @@
1
+ describe ::PPC::API::Baidu::Group do
2
+ auth = {}
3
+ auth[:username] = $baidu_username
4
+ auth[:password] = $baidu_password
5
+ auth[:token] = $baidu_token
6
+
7
+ Test_plan_id = []
8
+ Test_group_id = []
9
+
10
+ it 'can get all group' do
11
+ response = ::PPC::API::Baidu::Group::ids( auth )
12
+ is_successed( response )
13
+ pair = response['body']['campaignAdgroupIds'][0]
14
+ Test_plan_id << pair['campaignId']
15
+ end
16
+
17
+ it 'can add group' do
18
+ group = { name: 'test_group', plan_id:Test_plan_id[0], price:500 }
19
+ response = ::PPC::API::Baidu::Group::add( auth, group )
20
+ is_success( response )
21
+ Test_group_id << response[:result][0][:id]
22
+ end
23
+
24
+ it 'can update group' do
25
+ group = { id: Test_group_id[0], price:600 }
26
+ response = ::PPC::API::Baidu::Group::update( auth, group )
27
+ is_success( response )
28
+ end
29
+
30
+ it 'can search group by group id' do
31
+ response = ::PPC::API::Baidu::Group::get( auth, Test_group_id )
32
+ is_success( response )
33
+ end
34
+
35
+ it 'can search group id by group id' do
36
+ response = ::PPC::API::Baidu::Group::search_id_by_plan_id( auth, Test_plan_id )
37
+ is_success( response )
38
+ end
39
+
40
+ it 'search by plan id' do
41
+ response = ::PPC::API::Baidu::Group::search_by_plan_id( auth, Test_plan_id )
42
+ is_success( response )
43
+ end
44
+
45
+ it 'can delete group' do
46
+ response = ::PPC::API::Baidu::Group::delete( auth, Test_group_id )
47
+ is_success( response )
48
+ end
49
+
50
+ end
@@ -0,0 +1,64 @@
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
@@ -0,0 +1,42 @@
1
+ describe ::PPC::API::Baidu::Plan do
2
+ auth = {}
3
+ auth[:username] = $baidu_username
4
+ auth[:password] = $baidu_password
5
+ auth[:token] = $baidu_token
6
+
7
+ Test_plan_id = []
8
+
9
+ it "can get all plans" do
10
+ response = ::PPC::API::Baidu::Plan::all( auth )
11
+ is_success( response )
12
+ end
13
+
14
+ it "can get all plan id" do
15
+ response = ::PPC::API::Baidu::Plan::ids( auth )
16
+ is_success( response )
17
+ end
18
+
19
+ it "can add plan" do
20
+ test_plan = { name: "test_plan1", negative: ["test"] }
21
+ response = ::PPC::API::Baidu::Plan::add( auth, test_plan )
22
+ is_success( response )
23
+ Test_plan_id << response['body']['campaignTypes'][0]['campaignId']
24
+ end
25
+
26
+ it "can get plan by id" do
27
+ response = ::PPC::API::Baidu::Plan::get( auth, Test_plan_id )
28
+ is_success( response )
29
+ end
30
+
31
+ it 'can update plan' do
32
+ update = { id: Test_plan_id[0], name:"test_plan_update"}
33
+ response = ::PPC::API::Baidu::Plan::update( auth, update )
34
+ is_success( response )
35
+ end
36
+
37
+ it "can delete plan" do
38
+ response = ::PPC::API::Baidu::Plan::delete( auth, Test_plan_id )
39
+ is_success( response )
40
+ end
41
+
42
+ end
@@ -0,0 +1,32 @@
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
@@ -0,0 +1,60 @@
1
+ require 'json'
2
+ require 'ppc/api/baidu/account'
3
+ describe ::PPC::API::Baidu do
4
+
5
+ fake_response = "{\"header\":{\"desc\":\"success\",\"failures\":[],\"oprs\":1,\"oprtime\":0,
6
+ \"quota\":2,\"rquota\":34047,\"status\":0},\"body\":{
7
+ \"accountInfoType\":{\"userid\":5707012,\"balance\":0.0,\"cost\":0.0,
8
+ \"payment\":0.0,\"budgetType\":1,\"budget\":3000.0,\"regionTarget\":[9999999],
9
+ \"excludeIp\":[],\"openDomains\":[\"elong.com\"],\"regDomain\":\"elong.com\",
10
+ \"budgetOfflineTime\":[],\"weeklyBudget\":[],\"userStat\":null,\"isDynamicCreative\":null,
11
+ \"dynamicCreativeParam\":null,\"opt\":null}}}"
12
+
13
+ response = JSON.parse fake_response
14
+
15
+ Expected_success_result = [:id, :balance, :cost, :payment,
16
+ :budget_type, :budget, :region, :exclude_ip,
17
+ :open_domains, :reg_domain, :offline_time,
18
+ :weekly_budget ]
19
+
20
+ Expected_failure_result = ["code", "message", "position", "content"]
21
+
22
+ it 'can process response' do
23
+ response = ::PPC::API::Baidu::process( response, 'accountInfoType' ){|x| ::PPC::API::Baidu::Account::reverse_type(x)}
24
+
25
+ p "HAHA"*12
26
+ p response
27
+
28
+ expect( response[:result][0].keys ).to eq Expected_success_result
29
+ end
30
+
31
+ # params for make_type and reverse_type test
32
+ test_map =
33
+ [
34
+ [ :id , :campaignId],
35
+ [ :name , :campaignName],
36
+ [ :exclude_ip, :excludeIp],
37
+ [ :exact_negative , :exactNegativeWords],
38
+ ]
39
+
40
+ test_type = { }
41
+ test_type['campaignId'] = 123
42
+ test_type['campaignName'] = 'test_plan'
43
+ test_type['excludeIp'] = [321,5432,52,1]
44
+ test_type['exactNegativeWords'] = ['wu','liaode']
45
+
46
+ test_param = { }
47
+ test_param[ :id] = 123
48
+ test_param[ :name] = 'testplan'
49
+ test_param[ :exclude_ip] = [321,5432,52,1]
50
+ test_param[ :exact_negative] = ['test','plan']
51
+
52
+ expected_type = [{:campaignId=>123, :campaignName=>"testplan", :excludeIp=>[321, 5432, 52, 1], :exactNegativeWords=>["wu", "liaode"]}]
53
+ expexted_params = [{:id=>123, :name=>"test_plan", :exclude_ip=>[321, 5432, 52, 1], :exact_negative=>["wu", "liaode"]}]
54
+
55
+ it 'can make and reverse type' do
56
+ expect( ::PPC::API::Baidu::make_type( test_param , test_map) ).to eq expected_type
57
+ expect( ::PPC::API::Baidu::reverse_type(test_type, test_map) ).to eq expexted_params
58
+ end
59
+
60
+ end
@@ -0,0 +1,32 @@
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
@@ -0,0 +1,21 @@
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
@@ -0,0 +1,56 @@
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
@@ -0,0 +1,129 @@
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
File without changes
@@ -0,0 +1,87 @@
1
+ require 'operation_spec_helper'
2
+
3
+ Auth = {}
4
+ Auth[:username] = $baidu_username
5
+ Auth[:password] = $baidu_password
6
+ Auth[:token] = $baidu_token
7
+ Auth[:se] = 'baidu'
8
+ preparation = ::PPC::API::Baidu::Group::ids( Auth )
9
+ Test_plan_id = preparation[:result][0][:plan_id]
10
+ Test_group_id = preparation[:result][0][:group_ids][0]
11
+
12
+
13
+ describe ::PPC::Operation::Account do
14
+ subject{
15
+ ::PPC::Operation::Account.new( Auth )
16
+ }
17
+
18
+ it_should_behave_like( "it can operate itself", {budget:2990})
19
+ it_should_behave_like( "it can get all sub_objects", 'plan')
20
+
21
+ it_should_behave_like( "it can operate sub_objects", 'plan', {name:'operation_test_plan'},
22
+ {name:'updated_operation_test_plan'})
23
+
24
+ it_should_behave_like( "it can operate sub_objects", 'group',
25
+ {name:'test_operation_group',plan_id:Test_plan_id, price:500},
26
+ {name:'updated_operation_test_group'} )
27
+
28
+ it_should_behave_like( "it can operate sub_objects", 'keyword',
29
+ { keyword:'testKeyword', group_id:Test_group_id, match_type:'exact'},
30
+ { match_type:'wide'})
31
+
32
+ it_should_behave_like( "it can operate sub_objects", 'creative',
33
+ { group_id: Test_group_id,
34
+ title: 'OperationTestCreative', preference:1,
35
+ description1:'this is rest',
36
+ description2:'also is a test',
37
+ pc_destination:$baidu_domain,
38
+ pc_display:$baidu_domain },
39
+ {title:'OperationTestCreative', description1:'what the fuck'})
40
+ end
41
+
42
+ describe ::PPC::Operation::Plan do
43
+ # get test subject
44
+ subject{
45
+ ::PPC::Operation::Plan.new( Auth.merge({id:Test_plan_id}) )
46
+ }
47
+
48
+ it_should_behave_like( "it can operate itself", {budget:2000})
49
+ it_should_behave_like( "it can operate sub_objects", 'group',
50
+ {name:'test_operation_group', price:500},
51
+ {name:'updated_operation_test_group'} )
52
+ it_should_behave_like( "it can get all sub_objects", 'group')
53
+ end
54
+
55
+ describe ::PPC::Operation::Group do
56
+ # get test subject
57
+ subject{
58
+ ::PPC::Operation::Group.new( Auth.merge({id:Test_group_id}) )
59
+ }
60
+
61
+ it_should_behave_like( "it can operate itself", {price:200})
62
+ it_should_behave_like( "it can operate sub_objects", 'keyword',
63
+ { keyword:'testKeyword', group_id:Test_group_id, match_type:'exact'},
64
+ { match_type:'wide'})
65
+ it_should_behave_like( "it can get all sub_objects", 'keyword')
66
+ end
67
+
68
+ # describe ::PPC::Operation::Keyword do
69
+ # # get test subject
70
+ # subject{
71
+ # ::PPC::Operation::Keyword.new( Auth.merge({id:?}) )
72
+ # }
73
+
74
+ # it_should_behave_like( "it can operate itself", {price:200})
75
+ # end
76
+
77
+ # describe ::PPC::Operation::Creative do
78
+ # # get test subject
79
+ # subject{
80
+ # ::PPC::Operation::Creative.new( Auth.merge({id:?}) )
81
+ # }
82
+
83
+ # it_should_behave_like( "it can operate itself", {price:200})
84
+ # end
85
+
86
+
87
+
@@ -0,0 +1,53 @@
1
+ shared_examples "it can operate itself" do
2
+ | update |
3
+ it 'can get info' do
4
+ result = subject.info
5
+ is_success( result )
6
+ end
7
+
8
+ it 'can update it self' do
9
+ result = subject.update( update )
10
+ is_success( result )
11
+ end
12
+ end
13
+
14
+ # 在这之前要describ object
15
+ shared_examples "it can operate sub_objects" do
16
+ |object_name, add_info, update_info |
17
+ object_id = 0
18
+
19
+ it 'can add object' do
20
+ method_name = "add_"+object_name
21
+ result = subject.send( method_name.to_sym, add_info )
22
+ is_success( result )
23
+ p "HAHAHAAAHA"*12
24
+ p result
25
+ object_id = result[:result][0][:id]
26
+ end
27
+
28
+ it 'can update object' do
29
+ method_name = "update_"+object_name
30
+ result = subject.send( method_name.to_sym, update_info.merge( {id:object_id} ) )
31
+ is_success( result )
32
+ end
33
+
34
+ it 'can delete object' do
35
+ method_name = "delete_"+object_name
36
+ result = subject.send( method_name.to_sym, object_id )
37
+ is_success( result )
38
+ end
39
+ end
40
+
41
+ shared_examples "it can get all sub_objects" do
42
+ | object_name|
43
+ it 'can get all objects'do
44
+ result = subject.send( (object_name + 's').to_sym )
45
+ is_success( result )
46
+ end
47
+
48
+ it 'can get all object ids' do
49
+ result = subject.send( (object_name + '_ids').to_sym )
50
+ is_success( result )
51
+ end
52
+ end
53
+
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # -*- coding:utf-8 -*-
1
2
  # This file was generated by the `rspec --init` command. Conventionally, all
2
3
  # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
4
  # The generated `.rspec` file contains `--require spec_helper` which will cause this
@@ -78,4 +79,20 @@ RSpec.configure do |config|
78
79
  end
79
80
 
80
81
 
81
- require 'ppc'
82
+ require 'ppc'
83
+
84
+ $baidu_domain = ''
85
+ $baidu_username = ''
86
+ $baidu_password = ''
87
+ $baidu_token = ''
88
+ $qihu_username = ''
89
+ $qihu_password = ''
90
+ $qihu_token = ''
91
+ $sogou_username = ''
92
+ $sogou_password = ''
93
+ $sogou_token = ''
94
+
95
+ def is_success( result )
96
+ expect( result[:succ] ).to eq true
97
+ end
98
+