Class: RHACK::Client
- Inherits:
-
Object
- Object
- RHACK::Client
- Defined in:
- lib/rhack/services/base.rb
Instance Attribute Summary collapse
-
#f ⇒ Object
Returns the value of attribute f.
Instance Method Summary collapse
- #go(*args, &block) ⇒ Object
-
#initialize(service, frame = nil, *args) ⇒ Client
constructor
A new instance of Client.
- #inspect ⇒ Object
-
#login {|@f.get(URI :login)| ... } ⇒ Object
Usable only for sync requests.
- #scrape!(page) ⇒ Object
Constructor Details
#initialize(service, frame = nil, *args) ⇒ Client
Returns a new instance of Client.
12 13 14 15 16 |
# File 'lib/rhack/services/base.rb', line 12 def initialize(service, frame=nil, *args) @service = service # first argument should be a string so that frame won't be static @f = frame || Frame(URI(service) || URI(:login), *args) end |
Instance Attribute Details
#f ⇒ Object
Returns the value of attribute f.
9 10 11 |
# File 'lib/rhack/services/base.rb', line 9 def f @f end |
Instance Method Details
#go(*args, &block) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/rhack/services/base.rb', line 29 def go(*args, &block) __send__(@service, *args, &block) rescue L < $! Curl.reload end |
#inspect ⇒ Object
43 44 45 |
# File 'lib/rhack/services/base.rb', line 43 def inspect "<##{self.class.self_name}:#{@service.to_s.camelize} service via #{@f.inspect}>" end |
#login {|@f.get(URI :login)| ... } ⇒ Object
Usable only for sync requests
19 20 21 22 23 24 25 26 27 |
# File 'lib/rhack/services/base.rb', line 19 def login(*) Curl.run @f[0]..clear json, wait, @f.opts[:json], @f.opts[:wait] = @f.opts[:json], @f.opts[:wait], false, true yield @f.get(URI :login) @f.get(URI :home) if URI :home @f.opts[:json], @f.opts[:wait] = json, wait @f. end |
#scrape!(page) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/rhack/services/base.rb', line 36 def scrape!(page) __send__(:"scrape_#{@service}", page) if url = next_url(page) @f.get(url) {|next_page| scrape!(next_page)} end end |