ppc 2.0.3 → 2.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 644d36e63a1131b4c40e51a9774a8fc3fcdce623
4
- data.tar.gz: ec46a7efe0d2740a765e9bc2a13f6417bff8a439
3
+ metadata.gz: 8c1ffce2f8c4545b7ae1489322d55a0ef2c03511
4
+ data.tar.gz: 58e7f48a6389464bf1c9a68d5f01c6d27f4546d6
5
5
  SHA512:
6
- metadata.gz: 9126d0b364445da25d82be3ae6fb14a4c1741d90f461d8d1826ff299d0d225f4f61c6f3291e3a0b91159c52ccbe6691ed913fa1294d352e5fcaf514be54134ee
7
- data.tar.gz: 4097196b9a88796223fe0f830053630fdbb284941f2c4f060999840daaad1959571c0ee7fd64979c2ad979843e938ac21de029d13977ecd835d367ee5d7a91a6
6
+ metadata.gz: 4e9518dd1d57f4dd9a053b8ba3fc1e18e5821eecc928421e360127d51b2e31203268d830fbd54741b00ab4141258c4baf36ccc084527453b08cdaeee2096f66d
7
+ data.tar.gz: e789f19103d66d2cac478bb27372b1c207b2a5b53eaeba1036d380b9d8afa47290d02b672fb7d5cd4d19d8b06559cf4a91f8f29b61c0c5eea5078859eaed9c83
data/README.md CHANGED
@@ -9,6 +9,12 @@ ppc
9
9
  ----------
10
10
  #How to use it ?
11
11
 
12
+ ### Add ppc and savon(version3) to Gemfile
13
+ ```ruby
14
+ gem "savon", git: "https://github.com/savonrb/savon", branch: "version3"
15
+ gem "ppc", "~>2.0.3"
16
+ ```
17
+
12
18
  ### Create an objects:
13
19
  ```ruby
14
20
  param = {
data/lib/ppc.rb CHANGED
@@ -3,7 +3,7 @@ require 'ppc/operation'
3
3
  require 'ppc/ext'
4
4
  module PPC
5
5
 
6
- VERSION = "2.0.3"
6
+ VERSION = "2.0.4"
7
7
 
8
8
  protected
9
9
  def print_debug(var,varname=nil)
@@ -14,17 +14,8 @@ module PPC
14
14
  module API
15
15
 
16
16
  @map = nil
17
- @debug = false
18
17
  @match_types = nil
19
18
 
20
- def debug_on
21
- @debug = true
22
- end
23
-
24
- def debug_off
25
- @debug = false
26
- end
27
-
28
19
  def request_uri(param = {})
29
20
  raise 'you need build the uri'
30
21
  end
@@ -62,7 +53,7 @@ module PPC
62
53
  end
63
54
 
64
55
  # 是否显示http通信输出
65
- http.set_debug_output( $stdout ) if @debug
56
+ http.set_debug_output( $stdout ) if ENV["DEBUG"]
66
57
  http.use_ssl = true
67
58
  if http_method == 'delete'
68
59
  req = Net::HTTP::Delete.new(uri.path, http_header)
@@ -52,17 +52,17 @@ module PPC
52
52
  raise file_id[:failure][0]['message']
53
53
  end
54
54
 
55
- puts "file_id: #{file_id}" if @debug
55
+ puts "file_id: #{file_id}" if ENV["DEBUG"]
56
56
 
57
57
  loop do
58
58
  state = state( auth, file_id )[:result].to_s
59
59
  raise "invalid file state: #{state}" unless %w(1 2 3 null).include? state
60
60
  break if state == '3'
61
- puts "waiting for #{file_id} to be ready. current state:#{state}" if @debug
61
+ puts "waiting for #{file_id} to be ready. current state:#{state}" if ENV["DEBUG"]
62
62
  sleep 3
63
63
  end
64
64
 
65
- puts "#{file_id} is ready" if @debug
65
+ puts "#{file_id} is ready" if ENV["DEBUG"]
66
66
  return path( auth, file_id )
67
67
 
68
68
  rescue => e
@@ -72,67 +72,67 @@ module PPC
72
72
  #################################
73
73
  # useful function for operation #
74
74
  #################################
75
- def self.query_report( auth, param = {}, debug = false )
75
+ def self.query_report( auth, param = {} )
76
76
  param[:type] ||= 'query'
77
77
  param[:fields] ||= %w(click impression)
78
78
  param[:level] ||= 'pair'
79
79
  param[:range] ||= 'account'
80
80
  param[:unit] ||= 'day'
81
- download_report( auth, param, debug )
81
+ download_report( auth, param )
82
82
  end
83
83
 
84
- def self.creative_report( auth, param = {}, debug = false )
84
+ def self.creative_report( auth, param = {} )
85
85
  param[:type] ||= 'creative'
86
86
  param[:fields] ||= %w(impression click cpc cost ctr cpm position conversion)
87
87
  param[:level] ||= 'creative'
88
88
  param[:range] ||= 'creative'
89
89
  param[:unit] ||= 'day'
90
- download_report( auth, param, debug )
90
+ download_report( auth, param )
91
91
  end
92
92
 
93
- def self.keyword_report( auth, param = {}, debug = false )
93
+ def self.keyword_report( auth, param = {} )
94
94
  param[:type] ||= 'keyword'
95
95
  param[:fields] ||= %w(impression click cpc cost ctr cpm position conversion)
96
96
  param[:level] ||= 'keywordid'
97
97
  param[:range] ||= 'keywordid'
98
98
  param[:unit] ||= 'day'
99
- download_report( auth, param, debug )
99
+ download_report( auth, param )
100
100
  end
101
101
 
102
- def self.account_report( auth, param = {}, debug = false )
102
+ def self.account_report( auth, param = {} )
103
103
  param[:type] ||= 'account'
104
104
  param[:fields] ||= %w(impression click cpc cost ctr cpm conversion)
105
105
  param[:level] ||= 'account'
106
106
  param[:unit] ||= 'day'
107
- download_report( auth, param, debug )
107
+ download_report( auth, param )
108
108
  end
109
109
 
110
- def self.plan_report( auth, param = {}, debug = false )
110
+ def self.plan_report( auth, param = {} )
111
111
  param[:type] ||= 'plan'
112
112
  param[:fields] ||= %w(impression click cpc cost ctr cpm conversion)
113
113
  param[:level] ||= 'plan'
114
114
  param[:unit] ||= 'day'
115
- download_report( auth, param, debug )
115
+ download_report( auth, param )
116
116
  end
117
117
 
118
- def self.group_report( auth, param = {}, debug = false )
118
+ def self.group_report( auth, param = {} )
119
119
  param[:type] ||= 'group'
120
120
  param[:fields] ||= %w(impression click cpc cost ctr cpm conversion)
121
121
  param[:level] ||= 'group'
122
122
  param[:unit] ||= 'day'
123
- download_report( auth, param, debug )
123
+ download_report( auth, param )
124
124
  end
125
125
 
126
- def self.download_report( auth, param, debug = false )
126
+ def self.download_report( auth, param )
127
127
  p param
128
128
  response = get_id( auth, param )
129
129
  if response[:succ]
130
130
  id = response[:result]
131
- p "Got report id:" + id.to_s if debug
131
+ p "Got report id:" + id.to_s if ENV["DEBUG"]
132
132
  loop do
133
133
  sleep 2
134
134
  break if get_state( auth, id )[:result].to_s[/(Finished|3)/]
135
- p "Report is not generated, waiting..." if debug
135
+ p "Report is not generated, waiting..." if ENV["DEBUG"]
136
136
  end
137
137
 
138
138
  url = get_url( auth, id )[:result]
@@ -57,15 +57,15 @@ module PPC
57
57
  ############################
58
58
  # Interfaces for operation #
59
59
  ############################
60
- def self.keyword_report( auth, param, debug = false )
61
- download_report(auth, 'keyword', param, debug )
60
+ def self.keyword_report( auth, param )
61
+ download_report(auth, 'keyword', param )
62
62
  end
63
63
 
64
- def self.creative_report( auth, param, debug = false )
65
- download_report(auth, 'creative', param, debug)
64
+ def self.creative_report( auth, param )
65
+ download_report(auth, 'creative', param )
66
66
  end
67
67
 
68
- def self.download_report(auth, type, param, debug = false)
68
+ def self.download_report(auth, type, param )
69
69
  # deal_with time
70
70
  is_now = Date.today == Date.parse(param[:startDate])
71
71
 
@@ -28,7 +28,7 @@ module PPC
28
28
  result is the processed response body.
29
29
  '''
30
30
  result = {}
31
- result[:succ] = response['header']['desc'] =='success'
31
+ result[:succ] = response['header']['desc'][/(success|执行成功)/] ? true : false
32
32
  result[:failure] = response['header']['failures']
33
33
  result[:result] = func[ response['body'][key] ] rescue nil
34
34
  result[:no_quota] = (response['header']['failures']['code'] == '8501') rescue false
@@ -45,7 +45,7 @@ module PPC
45
45
  raise "获取task id 失败"
46
46
  end
47
47
 
48
- puts "task_id: #{task_id}" if @debug
48
+ puts "task_id: #{task_id}" if ENV["DEBUG"]
49
49
 
50
50
  loop do
51
51
  file_id = get_file_id( auth, task_id )[:result]
@@ -70,63 +70,63 @@ module PPC
70
70
  #################################
71
71
  # useful function for operation #
72
72
  #################################
73
- def self.query_report( auth, param = {}, debug = false )
73
+ def self.query_report( auth, param = {} )
74
74
  param[:type] ||= 'query'
75
75
  param[:fields] ||= %w(click impression)
76
76
  param[:range] ||= 'account'
77
77
  param[:unit] ||= 'day'
78
- download_report( auth, param, debug )
78
+ download_report( auth, param )
79
79
  end
80
80
 
81
- def self.creative_report( auth, param = {}, debug = false )
81
+ def self.creative_report( auth, param = {} )
82
82
  param[:type] ||= 'creative'
83
83
  param[:fields] ||= %w(click impression)
84
84
  param[:range] ||= 'account'
85
85
  param[:unit] ||= 'day'
86
- download_report( auth, param, debug )
86
+ download_report( auth, param )
87
87
  end
88
88
 
89
- def self.keyword_report( auth, param = {}, debug = false )
89
+ def self.keyword_report( auth, param = {} )
90
90
  param[:type] ||= 'keyword'
91
91
  param[:fields] ||= %w(click impression cost cpc ctr)
92
92
  param[:range] ||= 'account'
93
93
  param[:unit] ||= 'day'
94
- download_report( auth, param, debug )
94
+ download_report( auth, param )
95
95
  end
96
96
 
97
- def self.account_report( auth, param = {}, debug = false )
97
+ def self.account_report( auth, param = {} )
98
98
  param[:type] ||= 'account'
99
99
  param[:fields] ||= %w(click impression cost cpc ctr)
100
100
  param[:range] ||= 'account'
101
101
  param[:unit] ||= 'day'
102
- download_report( auth, param, debug )
102
+ download_report( auth, param )
103
103
  end
104
104
 
105
- def self.plan_report( auth, param = {}, debug = false )
105
+ def self.plan_report( auth, param = {} )
106
106
  param[:type] ||= 'plan'
107
107
  param[:fields] ||= %w(click impression cost cpc ctr)
108
108
  param[:range] ||= 'plan'
109
109
  param[:unit] ||= 'day'
110
- download_report( auth, param, debug )
110
+ download_report( auth, param )
111
111
  end
112
112
 
113
- def self.group_report( auth, param = {}, debug = false )
113
+ def self.group_report( auth, param = {} )
114
114
  param[:type] ||= 'group'
115
115
  param[:fields] ||= %w(click impression cost cpc ctr)
116
116
  param[:range] ||= 'group'
117
117
  param[:unit] ||= 'day'
118
- download_report( auth, param, debug )
118
+ download_report( auth, param )
119
119
  end
120
120
 
121
- def self.download_report( auth, param, debug = false )
121
+ def self.download_report( auth, param )
122
122
  response = get_id( auth, param )
123
123
  if response[:succ]
124
124
  id = response[:result]
125
- p "Got report id:" + id.to_s if debug
125
+ p "Got report id:" + id.to_s if ENV["DEBUG"]
126
126
  loop do
127
127
  sleep 2
128
128
  break if get_state( auth, id )[:result] == 'FINISHED'
129
- p "Report is not generated, waiting..." if debug
129
+ p "Report is not generated, waiting..." if ENV["DEBUG"]
130
130
  end
131
131
  fileId = get_fileId(auth, id)[:result]
132
132
  return get_file(auth, fileId).force_encoding("utf-8")
@@ -31,14 +31,14 @@ module PPC
31
31
  }
32
32
  operation.body = { (method+'Request').to_sym => params }
33
33
  # debug print
34
- debug_print( operation ) if @debug
34
+ debug_print( operation ) if ENV["DEBUG"]
35
35
  result = operation.call.hash[:envelope]
36
36
  #extract header and body
37
37
  response = { }
38
38
  response[:header] = result[:header][:res_header]
39
39
  response[:body] = result[:body][ (method + "Response").snake_case.to_sym ]
40
40
  # debug print
41
- puts response if @debug
41
+ puts response if ENV["DEBUG"]
42
42
  return response
43
43
  end
44
44
 
@@ -67,7 +67,7 @@ module PPC
67
67
  end
68
68
  end
69
69
 
70
- def self.rank_report(auth, device = 0, debug)
70
+ def self.rank_report(auth, device = 0 )
71
71
  url = download_cpc_rank(auth, device)[:result]
72
72
  file = "sogou_rank_#{Time.now.to_i}.zip"
73
73
  File.open(file, "w"){|f| f.puts open(url).read}
@@ -64,16 +64,16 @@ module PPC
64
64
  ###########################
65
65
  # intreface for Operation #
66
66
  ###########################
67
- def self.download_report( auth, param, debug = false )
67
+ def self.download_report( auth, param )
68
68
  response = get_id( auth, param )
69
69
  if response[:succ]
70
70
  id = response[:result]
71
- p "Got report id:" + id.to_s if debug
71
+ p "Got report id:" + id.to_s if ENV["DEBUG"]
72
72
  times = 0
73
73
  loop do
74
74
  raise "The speed of get_status is too slow." if (times += 1) > 10
75
75
  break if get_state( auth, id )[:result] == 'Finished'
76
- p "Report is not generated, waiting..." if debug
76
+ p "Report is not generated, waiting..." if ENV["DEBUG"]
77
77
  sleep 5
78
78
  end
79
79
 
@@ -84,47 +84,47 @@ module PPC
84
84
  end
85
85
  end
86
86
 
87
- def self.query_report( auth, param = {}, debug = false )
87
+ def self.query_report( auth, param = {} )
88
88
  param[:type] ||= 'query'
89
89
  param[:fields] ||= %w(click)
90
90
  param[:range] ||= 'account'
91
91
  param[:unit] ||= 'day'
92
- download_report( auth, param, debug )
92
+ download_report( auth, param )
93
93
  end
94
94
 
95
- def self.creative_report( auth, param = {}, debug = false )
95
+ def self.creative_report( auth, param = {} )
96
96
  param[:type] ||= 'creative'
97
97
  param[:fields] ||= %w( cost cpc click impression ctr )
98
98
  param[:range] ||= 'account'
99
- download_report( auth, param, debug )
99
+ download_report( auth, param )
100
100
  end
101
101
 
102
- def self.keyword_report( auth, param = {}, debug = false )
102
+ def self.keyword_report( auth, param = {} )
103
103
  param[:type] ||= 'keyword'
104
104
  param[:fields] ||= %w( cost cpc click impression ctr )
105
105
  param[:range] ||= 'account'
106
- download_report( auth, param, debug )
106
+ download_report( auth, param )
107
107
  end
108
108
 
109
- def self.account_report( auth, param = {}, debug = false )
109
+ def self.account_report( auth, param = {} )
110
110
  param[:type] ||= 'account'
111
111
  param[:fields] ||= %w( cost cpc click impression ctr )
112
112
  param[:range] ||= 'account'
113
- download_report( auth, param, debug )
113
+ download_report( auth, param )
114
114
  end
115
115
 
116
- def self.plan_report( auth, param = {}, debug = false )
116
+ def self.plan_report( auth, param = {} )
117
117
  param[:type] ||= 'plan'
118
118
  param[:fields] ||= %w( cost cpc click impression ctr )
119
119
  param[:range] ||= 'plan'
120
- download_report( auth, param, debug )
120
+ download_report( auth, param )
121
121
  end
122
122
 
123
- def self.group_report( auth, param = {}, debug = false )
123
+ def self.group_report( auth, param = {} )
124
124
  param[:type] ||= 'group'
125
125
  param[:fields] ||= %w( cost cpc click impression ctr)
126
126
  param[:range] ||= 'group'
127
- download_report( auth, param, debug )
127
+ download_report( auth, param )
128
128
  end
129
129
 
130
130
  end # Repost
@@ -2,36 +2,36 @@ module PPC
2
2
  module Operation
3
3
  module Report
4
4
 
5
- def download_report( param = {}, debug = false )
6
- call( "report" ).download_report( @auth, param, debug )
5
+ def download_report( param = {} )
6
+ call( "report" ).download_report( @auth, param )
7
7
  end
8
8
 
9
- def query_report( param = {}, debug = false )
10
- call( "report" ).query_report( @auth, param, debug )
9
+ def query_report( param = {} )
10
+ call( "report" ).query_report( @auth, param )
11
11
  end
12
12
 
13
- def creative_report( param = {}, debug = false )
14
- call( "report" ).creative_report( @auth, param, debug )
13
+ def creative_report( param = {} )
14
+ call( "report" ).creative_report( @auth, param )
15
15
  end
16
16
 
17
- def keyword_report( param = {}, debug = false )
18
- call( "report" ).keyword_report( @auth, param, debug )
17
+ def keyword_report( param = {} )
18
+ call( "report" ).keyword_report( @auth, param )
19
19
  end
20
20
 
21
- def account_report( param = {}, debug = false )
22
- call( "report" ).account_report( @auth, param, debug )
21
+ def account_report( param = {} )
22
+ call( "report" ).account_report( @auth, param )
23
23
  end
24
24
 
25
- def plan_report( param = {}, debug = false )
26
- call( "report" ).plan_report( @auth, param, debug )
25
+ def plan_report( param = {} )
26
+ call( "report" ).plan_report( @auth, param )
27
27
  end
28
28
 
29
- def group_report( param = {}, debug = false )
30
- call( "report" ).group_report( @auth, param, debug )
29
+ def group_report( param = {} )
30
+ call( "report" ).group_report( @auth, param )
31
31
  end
32
32
 
33
- def rank_report( device = 0, debug = false )
34
- call( "bulk" ).rank_report( @auth, device, debug)
33
+ def rank_report( device = 0 )
34
+ call( "bulk" ).rank_report( @auth, device )
35
35
  end
36
36
 
37
37
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ppc
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 2.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chienli Ma
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2016-10-20 00:00:00.000000000 Z
14
+ date: 2016-11-28 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: httparty