ppc 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +37 -0
  3. data/.rspec +2 -0
  4. data/LICENSE +339 -0
  5. data/README.md +78 -0
  6. data/lib/ppc.rb +17 -0
  7. data/lib/ppc/api.rb +10 -0
  8. data/lib/ppc/api/baidu.rb +138 -0
  9. data/lib/ppc/api/baidu/account.rb +47 -0
  10. data/lib/ppc/api/baidu/bulk.rb +41 -0
  11. data/lib/ppc/api/baidu/creative.rb +125 -0
  12. data/lib/ppc/api/baidu/group.rb +111 -0
  13. data/lib/ppc/api/baidu/keyword.rb +204 -0
  14. data/lib/ppc/api/baidu/plan.rb +68 -0
  15. data/lib/ppc/api/baidu/report.rb +143 -0
  16. data/lib/ppc/api/qihu.rb +107 -0
  17. data/lib/ppc/api/qihu/account.rb +86 -0
  18. data/lib/ppc/api/qihu/creative.rb +106 -0
  19. data/lib/ppc/api/qihu/group.rb +113 -0
  20. data/lib/ppc/api/qihu/keyword.rb +111 -0
  21. data/lib/ppc/api/qihu/plan.rb +64 -0
  22. data/lib/ppc/api/qihu/report.rb +159 -0
  23. data/lib/ppc/api/shenma.rb +64 -0
  24. data/lib/ppc/api/shenma/report.rb +135 -0
  25. data/lib/ppc/api/sogou.rb +122 -0
  26. data/lib/ppc/api/sogou/account.rb +42 -0
  27. data/lib/ppc/api/sogou/creative.rb +117 -0
  28. data/lib/ppc/api/sogou/group.rb +116 -0
  29. data/lib/ppc/api/sogou/keyword.rb +182 -0
  30. data/lib/ppc/api/sogou/plan.rb +66 -0
  31. data/lib/ppc/api/sogou/report.rb +129 -0
  32. data/lib/ppc/ext.rb +9 -0
  33. data/lib/ppc/operation.rb +196 -0
  34. data/lib/ppc/operation/account.rb +53 -0
  35. data/lib/ppc/operation/creative.rb +28 -0
  36. data/lib/ppc/operation/group.rb +59 -0
  37. data/lib/ppc/operation/keyword.rb +32 -0
  38. data/lib/ppc/operation/plan.rb +47 -0
  39. data/lib/ppc/operation/report.rb +19 -0
  40. data/ppc.gemspec +26 -0
  41. data/spec/baidu/api_baidu_account_spec.rb +15 -0
  42. data/spec/baidu/api_baidu_creative_spec.rb +67 -0
  43. data/spec/baidu/api_baidu_group_spec.rb +45 -0
  44. data/spec/baidu/api_baidu_keyword_spec.rb +61 -0
  45. data/spec/baidu/api_baidu_plan_spec.rb +43 -0
  46. data/spec/baidu/api_baidu_report_spec.rb +44 -0
  47. data/spec/baidu/api_baidu_spec.rb +55 -0
  48. data/spec/operation/operation_baidu_report_spec.rb +17 -0
  49. data/spec/operation/operation_baidu_spec.rb +78 -0
  50. data/spec/operation/operation_qihu_report_spec.rb +18 -0
  51. data/spec/operation/operation_qihu_spec.rb +51 -0
  52. data/spec/operation/operation_sogou_report_spec.rb +17 -0
  53. data/spec/operation/operation_sogou_spec.rb +51 -0
  54. data/spec/operation/operation_spec_helper.rb +51 -0
  55. data/spec/qihu/api_qihu_account_spec.rb +25 -0
  56. data/spec/qihu/api_qihu_creative_spec.rb +48 -0
  57. data/spec/qihu/api_qihu_group_spec.rb +40 -0
  58. data/spec/qihu/api_qihu_keyword_spec.rb +50 -0
  59. data/spec/qihu/api_qihu_plan_spec.rb +39 -0
  60. data/spec/qihu/api_qihu_report_spec.rb +54 -0
  61. data/spec/sogou/api_sogou_account_spec.rb +15 -0
  62. data/spec/sogou/api_sogou_creative_spec.rb +48 -0
  63. data/spec/sogou/api_sogou_group_spec.rb +45 -0
  64. data/spec/sogou/api_sogou_keyword_spec.rb +50 -0
  65. data/spec/sogou/api_sogou_plan_spec.rb +39 -0
  66. data/spec/sogou/api_sogou_report_spec.rb +51 -0
  67. data/spec/spec_helper.rb +134 -0
  68. metadata +177 -0
@@ -0,0 +1,44 @@
1
+ describe ::PPC::API::Baidu::Report do
2
+ auth = $baidu_auth
3
+
4
+ test_report_id = []
5
+
6
+ it 'can get professional report id' do
7
+ param = { type: 'plan', level:'plan',range:'plan',unit:'week',device:'all' }
8
+ response = ::PPC::API::Baidu::Report::get_id( auth, param )
9
+ is_success( response )
10
+ test_report_id << response[:result]
11
+ end
12
+
13
+ it 'can get professional report status' do
14
+ response = ::PPC::API::Baidu::Report::get_status( auth, test_report_id[0] )
15
+ is_success( response )
16
+ end
17
+
18
+ # it 'can get professional report download URL' do
19
+ # response = ::PPC::API::Baidu::Report::get_file_url( auth, test_report_id[0] )
20
+ # is_success( response )
21
+ # end
22
+ end
23
+
24
+ describe "::PPC::API::Baidu::Report Operation interface" do
25
+ auth = $baidu_auth
26
+
27
+ subject{
28
+ ::PPC::API::Baidu::Report
29
+ }
30
+ # opetation report test
31
+ it 'can get report' do
32
+ endDate = ( Time.now-2*3600*24).to_s[0..9].split('-').join
33
+ startDate =( Time.now-27*3600*24).to_s[0..9].split('-').join
34
+
35
+ p "startDate:#{startDate}"
36
+ p "endDate:#{endDate}"
37
+
38
+ param = {startDate:startDate, endDate:endDate}
39
+ subject.query_report( auth, param, true )
40
+ subject.keyword_report( auth, param, true )
41
+ subject.creative_report( auth,param, true )
42
+ end
43
+
44
+ end
@@ -0,0 +1,55 @@
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
+ expect( response[:result][0].keys ).to eq expected_success_result
25
+ end
26
+
27
+ # params for make_type and reverse_type test
28
+ test_map = [
29
+ [ :id , :campaignId],
30
+ [ :name , :campaignName],
31
+ [ :exclude_ip, :excludeIp],
32
+ [ :exact_negative , :exactNegativeWords],
33
+ ]
34
+
35
+ test_type = { }
36
+ test_type['campaignId'] = 123
37
+ test_type['campaignName'] = 'test_plan'
38
+ test_type['excludeIp'] = [321,5432,52,1]
39
+ test_type['exactNegativeWords'] = ['wu','liaode']
40
+
41
+ test_param = { }
42
+ test_param[ :id] = 123
43
+ test_param[ :name] = 'testplan'
44
+ test_param[ :exclude_ip] = [321,5432,52,1]
45
+ test_param[ :exact_negative] = ['wu','liaode']
46
+
47
+ expected_type = [{:campaignId=>123, :campaignName=>"testplan", :excludeIp=>[321, 5432, 52, 1], :exactNegativeWords=>["wu", "liaode"]}]
48
+ expexted_params = [{:id=>123, :name=>"test_plan", :exclude_ip=>[321, 5432, 52, 1], :exact_negative=>["wu", "liaode"]}]
49
+
50
+ it 'can make and reverse type' do
51
+ expect( ::PPC::API::Baidu::make_type( test_param , test_map) ).to eq expected_type
52
+ expect( ::PPC::API::Baidu::reverse_type(test_type, test_map) ).to eq expexted_params
53
+ end
54
+
55
+ end
@@ -0,0 +1,17 @@
1
+ describe ::PPC::Operation::Account do
2
+ subject{
3
+ ::PPC::Operation::Account.new( $baidu_auth )
4
+ }
5
+ # opetation report test
6
+ it 'can get report' do
7
+ endDate = ( Time.now-2*3600*24).to_s[0..9].split('-').join
8
+ startDate =( Time.now-27*3600*24).to_s[0..9].split('-').join
9
+
10
+ p "startDate:#{startDate},endDate:#{endDate}"
11
+ param = {startDate:startDate, endDate:endDate}
12
+
13
+ subject.query_report( param, true )
14
+ subject.keyword_report( param, true )
15
+ subject.creative_report( param, true )
16
+ end
17
+ end
@@ -0,0 +1,78 @@
1
+ require 'time'
2
+ require './operation_spec_helper'
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
+ describe ::PPC::Operation::Account do
13
+ subject{
14
+ ::PPC::Operation::Account.new( auth )
15
+ }
16
+
17
+ it_should_behave_like( "object", {budget:2990})
18
+ it_should_behave_like( "object parent", 'plan')
19
+
20
+ it_should_behave_like( "object operator", 'plan', {name:'operation_test_plan'},
21
+ {name:'updated_operation_test_plan'})
22
+
23
+ it_should_behave_like( "object operator", 'group',
24
+ {name:'test_operation_group',plan_id:test_plan_id, price:500},
25
+ {name:'updated_operation_test_group'} )
26
+
27
+ it_should_behave_like( "object operator", 'keyword',
28
+ { keyword:'testKeyword', group_id:test_group_id, match_type:'exact'},
29
+ { match_type:'wide'})
30
+
31
+ it_should_behave_like( "object operator", 'creative',
32
+ { group_id: test_group_id,
33
+ title: 'OperationTestCreative', preference:1,
34
+ description1:'this is rest',
35
+ description2:'also is a test',
36
+ pc_destination:$baidu_domain,
37
+ pc_display:$baidu_domain },
38
+ {title:'OperationTestCreative',
39
+ description1:'this is a updated test',
40
+ pc_destination:$baidu_domain,
41
+ mobil_destination:$baidu_domain})
42
+
43
+ # opetation report test
44
+ it 'can get report' do
45
+ endDate = Time.now.utc.iso8601
46
+ startDate =( Time.now-30*3600*24).utc.iso8601
47
+ pa = {startDate:startDate, endDate:endDate}
48
+ subject.query_report(pa)
49
+ subject.keyword_report(pa)
50
+ subject.creative_report(pa)
51
+ end
52
+ end
53
+
54
+ describe ::PPC::Operation::Plan do
55
+ # get test subject
56
+ subject{
57
+ ::PPC::Operation::Plan.new( auth.merge({id:test_plan_id}) )
58
+ }
59
+ it_should_behave_like( "object", {budget:2000})
60
+ it_should_behave_like( "object operator", 'group',
61
+ {name:'test_operation_group', price:500},
62
+ {name:'updated_operation_test_group'} )
63
+ it_should_behave_like( "object parent", 'group')
64
+ end
65
+
66
+ describe ::PPC::Operation::Group do
67
+ # get test subject
68
+ subject{
69
+ ::PPC::Operation::Group.new( auth.merge({id:test_group_id}) )
70
+ }
71
+
72
+ it_should_behave_like( "object", {price:200})
73
+ it_should_behave_like( "object operator", 'keyword',
74
+ { keyword:'testKeyword', group_id:test_group_id, match_type:'exact'},
75
+ { match_type:'wide'})
76
+ it_should_behave_like( "object parent", 'keyword')
77
+ end
78
+
@@ -0,0 +1,18 @@
1
+ auth = $qihu_auth
2
+
3
+ describe ::PPC::Operation::Account do
4
+ subject{
5
+ ::PPC::Operation::Account.new( auth )
6
+ }
7
+ # opetation report test
8
+ it 'can get report' do
9
+ endDate = ( Time.now-2*3600*24).to_s[0..9].split('-').join
10
+ startDate =( Time.now-27*3600*24).to_s[0..9].split('-').join
11
+
12
+ p "startDate:#{startDate},endDate:#{endDate}"
13
+ param = {startDate:startDate, endDate:endDate}
14
+
15
+ subject.keyword_report( param, true )
16
+ subject.creative_report( param, true )
17
+ end
18
+ end
@@ -0,0 +1,51 @@
1
+ require './operation_spec_helper'
2
+
3
+ auth = $qihu_auth
4
+
5
+ test_plan_id = 717479502
6
+ test_group_id = 1203987666
7
+
8
+ describe ::PPC::Operation::Account do
9
+ subject{
10
+ ::PPC::Operation::Account.new( auth )
11
+ }
12
+
13
+ it_should_behave_like( "object", {budget:2990})
14
+
15
+ it_should_behave_like( "object operator", 'plan', {name:'operation_test_plan'},
16
+ {name:'updated_operation_test_plan'})
17
+
18
+ it_should_behave_like( "object operator", 'group',
19
+ {name:'test_operation_group',plan_id:test_plan_id, price:500},
20
+ {name:'updated_operation_test_group'} )
21
+ end
22
+
23
+ describe ::PPC::Operation::Plan do
24
+ # get test subject
25
+ subject{
26
+ ::PPC::Operation::Plan.new( auth.merge({id:test_plan_id}) )
27
+ }
28
+
29
+ it_should_behave_like( "object", {budget:2000})
30
+ it_should_behave_like( "object operator", 'group',
31
+ {name:'test_operation_group', price:500},
32
+ {name:'updated_operation_test_group'} )
33
+ it_should_behave_like( "object parent", 'group')
34
+ end
35
+
36
+ describe ::PPC::Operation::Group do
37
+ # get test subject
38
+ subject{
39
+ ::PPC::Operation::Group.new( auth.merge({id:test_group_id}) )
40
+ }
41
+
42
+ it_should_behave_like( "object", {price:200})
43
+ it_should_behave_like( "object operator", 'keyword',
44
+ { keyword:'testKeyword', group_id:test_group_id, match_type:'exact'},
45
+ { match_type:'wide'})
46
+ it_should_behave_like( "object parent", 'keyword')
47
+
48
+ end
49
+
50
+
51
+
@@ -0,0 +1,17 @@
1
+ describe ::PPC::Operation::Account do
2
+ subject{
3
+ ::PPC::Operation::Account.new( $sogou_auth )
4
+ }
5
+ # opetation report test
6
+ it 'can get report' do
7
+ endDate = ( Time.now-2*3600*24).to_s[0..9].split('-').join
8
+ startDate =( Time.now-27*3600*24).to_s[0..9].split('-').join
9
+
10
+ p "startDate:#{startDate},endDate:#{endDate}"
11
+ param = {startDate:startDate, endDate:endDate}
12
+
13
+ subject.query_report( param )
14
+ subject.keyword_report( param )
15
+ subject.creative_report( param )
16
+ end
17
+ end
@@ -0,0 +1,51 @@
1
+ require './operation_spec_helper'
2
+
3
+ auth = $sogou_auth
4
+ preparation = ::PPC::API::Sogou::Group::ids( auth )
5
+ test_plan_id = preparation[:result][0][:plan_id]
6
+ test_group_id = preparation[:result][0][:group_ids][0]
7
+
8
+ ::PPC::API::Sogou.debug_on
9
+
10
+ describe ::PPC::Operation::Account do
11
+ subject{
12
+ ::PPC::Operation::Account.new( auth )
13
+ }
14
+
15
+ it_should_behave_like( "object", {budget:2990})
16
+ it_should_behave_like( "object parent", 'plan')
17
+
18
+ it_should_behave_like( "object operator", 'plan', {name:'operation_test_plan'},
19
+ {name:'updated_operation_test_plan'})
20
+
21
+ it_should_behave_like( "object operator", 'group',
22
+ {name:'test_operation_group',plan_id:test_plan_id, price:500},
23
+ {name:'updated_operation_test_group'} )
24
+
25
+ end
26
+
27
+ describe ::PPC::Operation::Plan do
28
+ # get test subject
29
+ subject{
30
+ ::PPC::Operation::Plan.new( auth.merge({id:test_plan_id}) )
31
+ }
32
+
33
+ it_should_behave_like( "object", {budget:2000})
34
+ it_should_behave_like( "object operator", 'group',
35
+ {name:'test_operation_group', price:500},
36
+ {name:'updated_operation_test_group'} )
37
+ it_should_behave_like( "object parent", 'group')
38
+ end
39
+
40
+ describe ::PPC::Operation::Group do
41
+ # get test subject
42
+ subject{
43
+ ::PPC::Operation::Group.new( auth.merge({id:test_group_id}) )
44
+ }
45
+
46
+ it_should_behave_like( "object", {price:200})
47
+ it_should_behave_like( "object parent", 'keyword')
48
+ end
49
+
50
+
51
+
@@ -0,0 +1,51 @@
1
+ shared_examples "object" 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 "object operator" 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
+ object_id = result[:result][0][:id]
24
+ end
25
+
26
+ it 'can update object' do
27
+ method_name = "update_"+object_name
28
+ result = subject.send( method_name.to_sym, update_info.merge( {id:object_id} ) )
29
+ is_success( result )
30
+ end
31
+
32
+ it 'can delete object' do
33
+ method_name = "delete_"+object_name
34
+ result = subject.send( method_name.to_sym, object_id )
35
+ is_success( result )
36
+ end
37
+ end
38
+
39
+ shared_examples "object parent" do
40
+ | object_name|
41
+ it 'can get all objects'do
42
+ result = subject.send( (object_name + 's').to_sym )
43
+ is_success( result )
44
+ end
45
+
46
+ it 'can get all object ids' do
47
+ result = subject.send( (object_name + '_ids').to_sym )
48
+ is_success( result )
49
+ end
50
+ end
51
+
@@ -0,0 +1,25 @@
1
+ describe ::PPC::API::Qihu::Account do
2
+ auth = $qihu_auth
3
+
4
+ it 'can get accnout info' do
5
+ response = ::PPC::API::Qihu::Account::info( auth )
6
+ is_success( response )
7
+ expect( response[:result].keys ).to eq [:id, :name, :email, :company, :industry1, :industry2, :balance, :budget, :open_domains]
8
+ end
9
+
10
+ it 'can update exclude iplist' do
11
+ response = ::PPC::API::Qihu::Account::update_exclude_ip( auth, ['127.0.0.1'] )
12
+ is_success( response )
13
+ end
14
+
15
+ it 'can get exclude ip list' do
16
+ response = ::PPC::API::Qihu::Account::get_exclude_ip( auth )
17
+ is_success( response )
18
+ end
19
+
20
+ it 'can update budget' do
21
+ response = ::PPC::API::Qihu::Account::update_budget( auth, 3500 )
22
+ is_success( response )
23
+ end
24
+
25
+ end
@@ -0,0 +1,48 @@
1
+ describe ::PPC::API::Qihu::Creative do
2
+ auth = $qihu_auth
3
+
4
+ test_plan_id = ::PPC::API::Qihu::Account::ids( auth )[:result][0].to_i
5
+ test_group_id = ::PPC::API::Qihu::Group::search_id_by_plan_id( auth, test_plan_id )[:result][0].to_i
6
+ test_Creative_id = 0
7
+
8
+ it 'can search creatives by group id' do
9
+ response = ::PPC::API::Qihu::Creative::search_id_by_group_id( auth, test_group_id )
10
+ is_success( response)
11
+ expect( response[:result].class ).to eq Array
12
+ end
13
+
14
+ it 'can add a creative' do
15
+ creative1 = {
16
+ group_id:test_group_id,
17
+ title:"testCreative1",
18
+ description1:'testhahaa',
19
+ pc_destination:'www.elong.com'
20
+ }
21
+ response = ::PPC::API::Qihu::Creative::add( auth, creative1)
22
+ is_success( response )
23
+ test_Creative_id = response[:result][0]
24
+ end
25
+
26
+ it 'can update a creative' do
27
+ creative = { id:test_Creative_id, description2:'testaaaaa' }
28
+ response = ::PPC::API::Qihu::Creative::update( auth, creative )
29
+ is_success( response )
30
+ end
31
+
32
+ it 'can get creatives' do
33
+ response = ::PPC::API::Qihu::Creative::get( auth, test_Creative_id )
34
+ is_success( response )
35
+ expect( response[:result][0].keys ).to include( :id, :title )
36
+ end
37
+
38
+ it 'can get status' do
39
+ response = ::PPC::API::Qihu::Creative::status( auth, test_Creative_id )
40
+ is_success( response )
41
+ end
42
+
43
+ it 'can delete a creative' do
44
+ response = ::PPC::API::Qihu::Creative::delete( auth, test_Creative_id )
45
+ is_success( response )
46
+ end
47
+
48
+ end