baidu-tuiguang 0.1.0 → 0.1.1

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: 758f53d595078896de5479bb92a1a17cb4537a0a
4
- data.tar.gz: 79c5828c64b38d00f3bdfc159b0c74dd21a05e91
3
+ metadata.gz: af00a2da8c08836a6f99a6153de28f0ad0a0dbd7
4
+ data.tar.gz: 9467ab33800680b41ad7b47c1f5ef00a4776ca12
5
5
  SHA512:
6
- metadata.gz: 3b8effd90cc0e48f67453f08e63572479398252940a98f373412d8b9b546e6a3552ba367f655ab68bf9578371ba1766a493c1f0b94ec0f62ee7754b51fe2893c
7
- data.tar.gz: 43fe7262f4fe9d5ada7fbad9b2d0474fe8cf621107091fa6585ffb13a64a1925ec9bc3ec78f195bc0601c7e14b38df0ebeba1f692c4fbb865d7b17aa84af3eb6
6
+ metadata.gz: aa164a9752e962c21651827333b4eff42b65c803aa04a017f87bb6f376aac14fb722dbaba7a38f5dea6c90627dd0d27691f20ec29e2734a769b9d2a8a2c091a5
7
+ data.tar.gz: f039446cef6f9738616a18b0cf66638be954bb62d1c4217837a9f81b039e24899c246bab2578234548cb05cbae4774664e3f220623df7111d3c270608e6dc727
@@ -10,7 +10,7 @@ module Baidu
10
10
  module Tuiguang
11
11
  class Action
12
12
  attr_reader :req_url
13
- attr_reader :req_data
13
+ attr_reader :req_params
14
14
  attr_reader :resp
15
15
 
16
16
  def initialize(cookies)
@@ -26,6 +26,7 @@ module Baidu
26
26
  'id' => item['planid'],
27
27
  'name' => item['planname'],
28
28
  'pause' => item['pausestat'] == 1,
29
+ 'status' => '',
29
30
  'mobile_price_ratio' => item['mPriceFactor'],
30
31
  }
31
32
  end
@@ -33,35 +34,24 @@ module Baidu
33
34
  end
34
35
 
35
36
 
36
- def groups(plan_id = nil, page = 1, page_size = 20)
37
+ def groups(plan_id, page = 1, page_size = 20)
37
38
  today = Time.now.to_date
38
- level_cond = {}
39
- if !plan_id.nil?
40
- level_cond = {"levelCond": {"planid": plan_id}}
41
- end
42
- data = request("path": 'vega/GET/mtllist/unit', "params": {"fields": ["unitid", "planid", "pausestat", "unitname", "planname", "unitbid", "unitMPriceFactor", "shows", "clks", "paysum", "trans", "avgprice", "unitstat", "matchPriceFactor", "matchPriceStatus", "phonetrans", "clkrate", "extbind", "allnegativecnt", "showpay", "deviceprefer", "mPriceFactor", "adtype", "finebidstatus", "atstatus", "atbid", "planatbid", "bidprefer", "pcpricefactor", "planPcpricefactor"], "pageNo": page, "pageSize": page_size, "startTime": today, "endTime": today}.merge(level_cond))
39
+ data = request("path": 'vega/GET/mtllist/unit', "params": {"fields": ["unitid", "planid", "pausestat", "unitname", "planname", "unitbid", "unitMPriceFactor", "shows", "clks", "paysum", "trans", "avgprice", "unitstat", "matchPriceFactor", "matchPriceStatus", "phonetrans", "clkrate", "extbind", "allnegativecnt", "showpay", "deviceprefer", "mPriceFactor", "adtype", "finebidstatus", "atstatus", "atbid", "planatbid", "bidprefer", "pcpricefactor", "planPcpricefactor"], "pageNo": page, "pageSize": page_size, "startTime": today, "endTime": today, "levelCond": {"planid": plan_id}})
43
40
  result = {'data' => [], 'count' => data['totalCount']}
44
41
  data['listData'].each do |item|
45
42
  result['data'] << {
46
43
  'id' => item['unitid'],
47
44
  'name' => item['unitname'],
48
45
  'pause' => item['pausestat'] == 1,
49
- 'plan_id' => item['planid'],
50
- 'plan_name' => item['planname']
46
+ 'status' => ''
51
47
  }
52
48
  end
53
49
  result
54
50
  end
55
51
 
56
- def keywords(plan_id = nil, group_id = nil, page = 1, page_size = 20)
52
+ def keywords(plan_id, group_id, page = 1, page_size = 20)
57
53
  today = Time.now.to_date
58
- level_cond = {}
59
- if !group_id.nil?
60
- level_cond = {"levelCond": {"unitid": group_id}}
61
- elsif !plan_id.nil?
62
- level_cond = {"levelCond": {"planid": plan_id}}
63
- end
64
- data = request("path": 'vega/GET/mtllist/word', "params": {"fields": ["winfoid", "unitid", "planid", "wordid", "pausestat", "showword", "unitname", "planname", "wordstat", "bid", "unitbid", "pcqscore", "mqscore", "trans", "paysum", "shows", "clks", "avgprice", "wmatch", "shadow_wurl", "shadow_mwurl", "activestat", "wctrl", "wurl", "pageexp", "mwurl", "showqscore", "blockreason", "confidence", "pcblockreason", "pcconfidence", "matchPriceEnableStatus", "clkrate", "showpay", "adtype", "bidprefer", "mPriceGuide", "leftPriceGuide", "left3PriceGuide", "marker", "mconfidence", "mblockreason", "pcqscorecon", "mqscorecon", "pcrelativity", "mrelativity", "pclandpage", "mlandpage", "pclandpagereason", "mlandpagereason", "addfrom", "modfrom"], "pageNo": page, "pageSize": page_size, "startTime": today, "endTime": today}.merge(level_cond))
54
+ data = request("path": 'vega/GET/mtllist/word', "params": {"fields": ["winfoid", "unitid", "planid", "wordid", "pausestat", "showword", "unitname", "planname", "wordstat", "bid", "unitbid", "pcqscore", "mqscore", "trans", "paysum", "shows", "clks", "avgprice", "wmatch", "shadow_wurl", "shadow_mwurl", "activestat", "wctrl", "wurl", "pageexp", "mwurl", "showqscore", "blockreason", "confidence", "pcblockreason", "pcconfidence", "matchPriceEnableStatus", "clkrate", "showpay", "adtype", "bidprefer", "mPriceGuide", "leftPriceGuide", "left3PriceGuide", "marker", "mconfidence", "mblockreason", "pcqscorecon", "mqscorecon", "pcrelativity", "mrelativity", "pclandpage", "mlandpage", "pclandpagereason", "mlandpagereason", "addfrom", "modfrom"], "pageNo": page, "pageSize": page_size, "startTime": today, "endTime": today, "levelCond": {"unitid": group_id}})
65
55
  result = {'data' => [], 'count' => data['totalCount']}
66
56
  data['listData'].each do |item|
67
57
  match = ''
@@ -87,31 +77,29 @@ module Baidu
87
77
  'id' => item['winfoid'],
88
78
  'keyword' => item['showword'],
89
79
  'status' => status,
80
+ 'mobile_status' => '',
90
81
  'pause' => item['pausestat'] == 1,
91
82
  'price' => item['bid'],
92
83
  'match' => match,
93
84
  'quality' => item['pcqscore'],
94
85
  'mobile_quality' => item['mqscore'],
95
86
  'url' => item['wurl'],
96
- 'mobile_url' => item['mwurl'],
97
- 'group_id' => item['wordid'],
98
- 'group_name' => item['unitname'],
99
- 'plan_id' => item['planid'],
100
- 'plan_name' => item['planname']
87
+ 'mobile_url' => item['mwurl']
101
88
  }
102
89
  end
103
90
  result
104
91
  end
105
92
 
106
- def keyword_pause(winfoid)
107
- request("path": 'vega/MOD/keyword', "params": {"winfoid": [winfoid.to_i], "items": {"pausestat": 1}})
93
+ def keyword_pause(keyword_id)
94
+ request("path": 'vega/MOD/keyword', "params": {"winfoid": [keyword_id.to_i], "items": {"pausestat": 1}})
108
95
  end
109
96
 
110
- def keyword_enable(winfoid)
111
- request("path": 'vega/MOD/keyword', "params": {"winfoid": [winfoid.to_i], "items": {"pausestat": 0}})
97
+ def keyword_enable(keyword_id)
98
+ request("path": 'vega/MOD/keyword', "params": {"winfoid": [keyword_id.to_i], "items": {"pausestat": 0}})
112
99
  end
113
100
 
114
101
  def request(params = {})
102
+ @req_params = params
115
103
  params.merge!(
116
104
  "userid": cookies_params['__cas__id__3'],
117
105
  "token": cookies_params['__cas__st__3'],
@@ -134,14 +122,13 @@ module Baidu
134
122
  request["pragma"] = 'no-cache'
135
123
  request["referer"] = "http://fengchao.baidu.com/nirvana/main.html?userid=#{cookies_params['__cas__id__3']}"
136
124
  request["user-agent"] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36'
137
- request.body = @req_data = URI.encode_www_form(params)
125
+ request.body = URI.encode_www_form(params)
138
126
  response = http.request(request)
139
127
  raise RequestError, "HTTP Response: #{response.code} #{response.message}" unless response.is_a?(Net::HTTPSuccess)
140
128
  @resp = response.read_body
141
129
  if response['Content-Encoding'] && response['Content-Encoding'].include?('gzip')
142
130
  @resp = Zlib::GzipReader.new(StringIO.new(@resp)).read
143
131
  end
144
- # puts @resp
145
132
  result = JSON.parse(@resp)
146
133
  raise LoginExpired if result['redirect'] && result['redirecturl'] && result['redirecturl'].include?('http://cas.baidu.com')
147
134
  raise Error.new result['error'], result['status'] unless result['status'].to_i == 200
@@ -1,5 +1,5 @@
1
1
  module Baidu
2
2
  module Tuiguang
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: baidu-tuiguang
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Xiao Jie