Class: RHACK::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/rhack/services/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#fObject

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

#inspectObject



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

Yields:

  • (@f.get(URI :login))


19
20
21
22
23
24
25
26
27
# File 'lib/rhack/services/base.rb', line 19

def (*)
  Curl.run
  @f[0].cookies.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.copy_cookies!
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