rhack 1.3.0 → 1.3.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: ccd52c86276421476a67a4b379fcb6275bd6f85e
4
- data.tar.gz: 46efe342223575cb26eceddca4970173b7f32cdf
3
+ metadata.gz: 8f5a539c0ca1c92416d50ffd4609d08a69d900fe
4
+ data.tar.gz: fee2e42ae02b21af929a1b0b417360adc043562d
5
5
  SHA512:
6
- metadata.gz: af9bbd50acdc9ee228bc3ccede8fc31da56dd762d39a96f85c847e3c223167f2aff0fff6f4ef30ee68e7d7b3fa91e51d74cf670c7b7968bd9d4ec70861ca3ae9
7
- data.tar.gz: 7d0f7418a4af8d3ff2bcbfab5ec26fbca85ad0664570242255fee2822ffbf3c528ab8e4ba9979d2a545b6599a77bd80f15ab6aa2f24297bb947fdc134a7457b0
6
+ metadata.gz: bfda297b6b465393b6749bac236e32bd967216dbad68c4383fc3bdd1e9cbc5602efcb57513ce9c01b9b6c6416ad312b10e150a802b717932e471594744e8765b
7
+ data.tar.gz: e4e762cd0e9e858cd20e9bef50c0a9fb4d97b506361879b5efc49cad3d939ebb35b2e3245144fd2e9f01a7ddc033200b656d71a5e4ffa53172e84d468376d3c4
@@ -8,13 +8,13 @@ module RHACK
8
8
  class Client
9
9
  attr_reader :service
10
10
  attr_accessor :f
11
- class_attribute :frame_defaults
12
- class_attribute :accounts
13
- class_attribute :routes
11
+ class_attribute :frame_defaults, :instance_writer => false
12
+ class_attribute :accounts, :instance_writer => false
13
+ class_attribute :routes, :instance_writer => false
14
14
 
15
- @@frame_defaults = {}
16
- @@accounts = {}
17
- @@routes = {}
15
+ self.frame_defaults = {}
16
+ self.accounts = {}
17
+ self.routes = {}
18
18
 
19
19
  class << self
20
20
 
@@ -33,28 +33,35 @@ module RHACK
33
33
  if defined? URI and URI.is Hash
34
34
  URI.merge! dict.map_hash {|k, v| [k.to_sym, v.freeze]}
35
35
  end
36
- @@routes.merge! dict.map_hash {|k, v| [k.to_sym, v.freeze]}
36
+ routes.merge! dict.map_hash {|k, v| [k.to_sym, v.freeze]}
37
37
  end
38
38
 
39
39
  # Set default Frame options
40
40
  def frame(dict)
41
- @@frame_defaults.merge! dict
41
+ frame_defaults.merge! dict
42
42
  end
43
43
 
44
44
  # Set usable accounts
45
45
  # @ dict : {symbol => {symbol => string, ...}}
46
46
  def accounts(dict)
47
- @@accounts.merge! dict
47
+ accounts.merge! dict
48
48
  end
49
49
 
50
50
  end
51
51
 
52
- def initialize(service=:api, opts={})
52
+ def initialize(*args)
53
+ service, opts = args.get_opts [:api]
53
54
  @service = service
54
55
  # first argument should be a string so that frame won't be static
55
- @f = opts.is_a?(Frame) ?
56
- opts :
57
- Frame(route(service) || route(:login), @@frame_defaults.merge(opts))
56
+ if opts.is_a?(Frame)
57
+ @f = opts
58
+ else
59
+ opts = frame_defaults.merge(opts)
60
+ if self.class.const_defined? :Result
61
+ opts[:result] = self.class::Result
62
+ end
63
+ @f = Frame(route(service) || route(:login), opts)
64
+ end
58
65
  end
59
66
 
60
67
 
@@ -79,7 +86,7 @@ module RHACK
79
86
 
80
87
 
81
88
  def scrape!(page)
82
- __send__(:"scrape_#{@service}", page)
89
+ __send__(:"scrape_#@service", page)
83
90
  if url = next_url(page)
84
91
  @f.get(url) {|next_page| scrape!(next_page)}
85
92
  end
@@ -92,14 +99,14 @@ module RHACK
92
99
  # shortcuts to class variables #
93
100
 
94
101
  def route(name)
95
- @@routes[name]
102
+ routes[name]
96
103
  end
97
104
  alias :url :route
98
105
  # URI is deprecated # backward compatibility
99
106
  alias :URI :route
100
107
 
101
108
  def account(name)
102
- @@accounts[name]
109
+ accounts[name]
103
110
  end
104
111
 
105
112
  end
data/lib/rhack/frame.rb CHANGED
@@ -331,12 +331,14 @@ module RHACK
331
331
  # if no spare scouts can be found, squad simply waits for first callbacks to complete
332
332
  s = @ss.next
333
333
  s.http.on_failure {|curl, error|
334
- s.process_failure(*error)
335
- if opts[:raw]
336
- page.res = s.error
337
- elsif page.process(curl, opts)
338
- run_callbacks! page, opts, &callback
339
- # nothing to do here if process returns nil or false
334
+ if s.process_failure(*error)
335
+ # curl itself has decided not to retry a request
336
+ if opts[:raw]
337
+ page.res = s.error
338
+ elsif page.process(curl, opts)
339
+ run_callbacks! page, opts, &callback
340
+ # nothing to do here if process returns nil or false
341
+ end
340
342
  end
341
343
  }
342
344
  s.send(*(order << opts)) {|curl|
data/lib/rhack/scout.rb CHANGED
@@ -208,11 +208,11 @@ module RHACK
208
208
  cks.map2 {|k, v| Cookie(k, v)}
209
209
  end
210
210
 
211
- def retry?(eclass)
211
+ def retry?(curl_err)
212
212
  # sites = ['0chan.ru', '2-ch.ru', 'www.nomer.org', 'nomer.org'].select_in('http://www.nomer.org') = ['www.nomer.org', 'nomer.org']
213
213
  sites = (@@retry.keys + @retry.keys).select_in @root
214
214
  return false if sites.empty?
215
- errname = eclass.self_name
215
+ errname = curl_err.self_name
216
216
  # retry = ['www.nomer.org', 'nomer.org'].any? {|www| {'nomer.org' => ['TimeoutError']}[www].include? 'TimeoutError'}
217
217
  sites.any? {|site|
218
218
  (@@retry[site] || []).include? errname or
@@ -235,6 +235,8 @@ module RHACK
235
235
  !loaded?
236
236
  end
237
237
 
238
+ # - if curl should retry request based on Curl::Err class only
239
+ # => false
238
240
  def process_failure(curl_err, message)
239
241
  @error = curl_err.new message
240
242
  #@error = [curl_err, message] # old
@@ -245,10 +247,12 @@ module RHACK
245
247
  if retry? curl_err
246
248
  L.debug "#{curl_err} -> reloading scout"
247
249
  retry!
250
+ false
248
251
  else
249
252
  L.debug "#{curl_err} -> not reloading scout"
250
253
  raise @error if @raise_err
251
254
  #raise *@error if @raise_err # old
255
+ true
252
256
  end
253
257
  end
254
258
 
data/lib/rhack/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RHACK
2
- VERSION = '1.3.0'
2
+ VERSION = '1.3.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rhack
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Baev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-15 00:00:00.000000000 Z
11
+ date: 2014-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rmtools