ppc 0.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.
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,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,19 @@
1
+ module PPC
2
+ module Operation
3
+ module Report
4
+
5
+ def query_report( param = nil, debug = false )
6
+ call('report').query_report( @auth, param, debug )
7
+ end
8
+
9
+ def creative_report( param = nil, debug = false )
10
+ call('report').creative_report( @auth, param, debug )
11
+ end
12
+
13
+ def keyword_report( param = nil, debug = false )
14
+ call('report').keyword_report( @auth, param, debug )
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ # require ppc for version
6
+ require 'ppc'
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = "ppc"
10
+ spec.version = PPC::VERSION
11
+ spec.authors = ["Chienli Ma, 刘梦晨, 刘明"]
12
+ spec.email = ["maqianlie@gmail.com, liuyu_tc@163.com, seoaqua@qq.com"]
13
+ spec.summary = %q{ppc api for baidu qihu sogou}
14
+ spec.description = %q{ppc api for baidu qihu sogou}
15
+ spec.homepage = "http://github.com/elong/ppc"
16
+ spec.license = "GNU"
17
+
18
+ spec.files = `git ls-files -z`.split("\x0")
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency 'httparty', '~> 0.13', '>= 0.13.0'
24
+ spec.add_dependency 'savon', '~> 3.0', '>= 3.0.0'
25
+
26
+ end
@@ -0,0 +1,15 @@
1
+ describe ::PPC::API::Baidu::Account do
2
+ auth = $baidu_auth
3
+
4
+ it 'can get account info' do
5
+ result = ::PPC::API::Baidu::Account::info( auth )
6
+ is_success( result )
7
+ end
8
+
9
+ it 'can update account' do
10
+ update = {budget:2990}
11
+ result = ::PPC::API::Baidu::Account::update( auth, update )
12
+ is_success( result )
13
+ end
14
+
15
+ end
@@ -0,0 +1,67 @@
1
+ # -*- coding:utf-8 -*-
2
+ describe ::PPC::API::Baidu::Creative do
3
+ auth = $baidu_auth
4
+
5
+ test_group_id = ::PPC::API::Baidu::Group::ids( auth )[:result][0][:group_ids][0]
6
+ test_plan_id = ::PPC::API::Baidu::Plan::all( auth )[:result][0][:plan_id]
7
+ test_creative_id = []
8
+
9
+ it 'can add creative' do
10
+ creative = { group_id: test_group_id,
11
+ title: 'TestCreative', preference:1,
12
+ description1:'this is rest',
13
+ description2:'also is a test',
14
+ pc_destination:$baidu_domain,
15
+ pc_display:$baidu_domain }
16
+ response = ::PPC::API::Baidu::Creative::add( auth, creative )
17
+ is_success( response )
18
+ test_creative_id << response[:result][0][:id]
19
+ end
20
+
21
+ it 'can update creative' do
22
+ update = { id:test_creative_id[0],
23
+ title:'ElongUpdateTest',
24
+ description1:'test for update',
25
+ mobile_destination:$baidu_domain,
26
+ pc_destination:$baidu_domain,
27
+ pause:true}
28
+ response = ::PPC::API::Baidu::Creative::update( auth, update )
29
+ is_success( response )
30
+ end
31
+
32
+ it 'can activate creative' do
33
+ response = ::PPC::API::Baidu::Creative::activate( auth, test_creative_id )
34
+ is_success( response )
35
+ end
36
+
37
+ # 连续测试的系统返回system_failured
38
+ # it 'can get status' do
39
+ # response1 = ::PPC::API::Baidu::Creative::status( auth, test_group_id, 'group' )
40
+ # response2 = ::PPC::API::Baidu::Creative::status( auth, test_creative_id, 'creative' )
41
+ # response3 = ::PPC::API::Baidu::Creative::status( auth, test_plan_id, 'plan' )
42
+ # is_success( response1 )
43
+ # is_success( response2 )
44
+ # is_success( response3 )
45
+ # end
46
+
47
+ it 'can search id by group id' do
48
+ response = ::PPC::API::Baidu::Creative::search_id_by_group_id( auth, test_group_id, 0 )
49
+ is_success( response )
50
+ end
51
+
52
+ it 'can search creative by group id' do
53
+ response = ::PPC::API::Baidu::Creative::search_by_group_id( auth, test_group_id, 0 )
54
+ is_success( response )
55
+ end
56
+
57
+ it 'can search creative by creative id' do
58
+ response = ::PPC::API::Baidu::Creative::get( auth, test_creative_id, 0 )
59
+ is_success( response )
60
+ end
61
+
62
+ it 'can delete creative' do
63
+ response = ::PPC::API::Baidu::Creative::delete( auth, test_creative_id )
64
+ is_success( response )
65
+ end
66
+
67
+ end
@@ -0,0 +1,45 @@
1
+ describe ::PPC::API::Baidu::Group do
2
+ auth = $baidu_auth
3
+
4
+ test_plan_id = ::PPC::API::Baidu::Plan.ids(auth)[:result][0]
5
+ test_group_id = []
6
+
7
+ it 'can get all group' do
8
+ response = ::PPC::API::Baidu::Group::ids( auth )
9
+ is_success( response )
10
+ end
11
+
12
+ it 'can add group' do
13
+ group = { name: 'test_group', plan_id:test_plan_id, price:500 }
14
+ response = ::PPC::API::Baidu::Group::add( auth, group )
15
+ is_success( response )
16
+ test_group_id << response[:result][0][:id]
17
+ end
18
+
19
+ it 'can update group' do
20
+ group = { id: test_group_id[0], price:600 }
21
+ response = ::PPC::API::Baidu::Group::update( auth, group )
22
+ is_success( response )
23
+ end
24
+
25
+ it 'can search group by group id' do
26
+ response = ::PPC::API::Baidu::Group::get( auth, test_group_id )
27
+ is_success( response )
28
+ end
29
+
30
+ it 'can search group id by plan id' do
31
+ response = ::PPC::API::Baidu::Group::search_id_by_plan_id( auth, test_plan_id )
32
+ is_success( response )
33
+ end
34
+
35
+ it 'search by plan id' do
36
+ response = ::PPC::API::Baidu::Group::search_by_plan_id( auth, test_plan_id )
37
+ is_success( response )
38
+ end
39
+
40
+ it 'can delete group' do
41
+ response = ::PPC::API::Baidu::Group::delete( auth, test_group_id )
42
+ is_success( response )
43
+ end
44
+
45
+ end
@@ -0,0 +1,61 @@
1
+ # -*- coding:utf-8 -*-
2
+ describe ::PPC::API::Baidu::Keyword do
3
+ auth = $baidu_auth
4
+
5
+ test_group_id = ::PPC::API::Baidu::Group::ids( auth )[:result][0][:group_ids][0]
6
+ test_plan_id = ::PPC::API::Baidu::Plan::all( auth )[:result][0][:plan_id]
7
+ test_keyword_id = []
8
+
9
+ it 'can search keyword by group id' do
10
+ response = ::PPC::API::Baidu::Keyword::search_by_group_id( auth, test_group_id )
11
+ is_success( response )
12
+ end
13
+
14
+ it 'can add keyword' do
15
+ keyword = { group_id: test_group_id, keyword: 'testkeywordid', match_type:'exact' }
16
+ response = ::PPC::API::Baidu::Keyword::add( auth, keyword )
17
+ is_success( response )
18
+ test_keyword_id << response[:result][0][:id]
19
+ end
20
+
21
+ it 'can update keyword' do
22
+ update = { id:test_keyword_id[0], pc_destination: $baidu_domain, pause:true}
23
+ response = ::PPC::API::Baidu::Keyword::update( auth, update )
24
+ is_success( response )
25
+ end
26
+
27
+ it 'can activate keyword' do
28
+ response = ::PPC::API::Baidu::Keyword::activate( auth, test_keyword_id )
29
+ is_success( response )
30
+ end
31
+
32
+ # 连续测试系统返回system failure
33
+ # it 'can get status' do
34
+ # response1 = ::PPC::API::Baidu::Keyword::status( auth, test_group_id, 'group' )
35
+ # response2 = ::PPC::API::Baidu::Keyword::status( auth, test_keyword_id, 'keyword' )
36
+ # response3 = ::PPC::API::Baidu::Keyword::status( auth, test_plan_id, 'plan' )
37
+ # is_success( response1 )
38
+ # is_success( response2 )
39
+ # is_success( response3 )
40
+ # end
41
+
42
+ # it 'can get quality' do
43
+ # response1 = ::PPC::API::Baidu::Keyword::quality( auth, test_group_id, 'group', true )
44
+ # response2 = ::PPC::API::Baidu::Keyword::quality( auth, test_keyword_id, 'keyword', true )
45
+ # response3 = ::PPC::API::Baidu::Keyword::quality( auth, test_plan_id, 'plan', true )
46
+ # is_successed( response1 )
47
+ # is_successed( response2 )
48
+ # is_successed( response3 )
49
+ # end
50
+
51
+ it 'can get 10-quality' do
52
+ response = ::PPC::API::Baidu::Keyword::quality( auth, test_keyword_id, 'keyword', 'pc' )
53
+ is_success( response )
54
+ end
55
+
56
+ it 'can delete keyword' do
57
+ response = ::PPC::API::Baidu::Keyword::delete( auth, test_keyword_id )
58
+ is_success( response )
59
+ end
60
+
61
+ end
@@ -0,0 +1,43 @@
1
+ describe ::PPC::API::Baidu::Plan do
2
+ auth = $baidu_auth
3
+
4
+ test_plan_id = []
5
+
6
+ ::PPC::API::Baidu.debug_on
7
+
8
+ it "can get all plans" do
9
+ response = ::PPC::API::Baidu::Plan::all( auth )
10
+ is_success( response )
11
+ end
12
+
13
+ it "can get all plan id" do
14
+ response = ::PPC::API::Baidu::Plan::ids( auth )
15
+ is_success( response )
16
+ end
17
+
18
+ it "can add plan" do
19
+ test_plan = { name: "test_elong_e", negative: ["test"] }
20
+ response = ::PPC::API::Baidu::Plan::add( auth, test_plan )
21
+ is_success( response )
22
+ test_plan_id << response[:result][0][:id]
23
+ end
24
+
25
+ it "can get plan by id" do
26
+ response = ::PPC::API::Baidu::Plan::get( auth, test_plan_id )
27
+ is_success( response )
28
+ end
29
+
30
+ it 'can update plan' do
31
+ update = { id: test_plan_id[0], name:"test_plan_update", is_dynamic:false }
32
+ response = ::PPC::API::Baidu::Plan::update( auth, update )
33
+ # param isDynamicCreative should not be default value
34
+ expect( response[:result][0][:is_dynamic] ).to eq false
35
+ is_success( response )
36
+ end
37
+
38
+ it "can delete plan" do
39
+ response = ::PPC::API::Baidu::Plan::delete( auth, test_plan_id )
40
+ is_success( response )
41
+ end
42
+
43
+ end