Class: RHACK::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/rhack/clients/base.rb,
lib/rhack/clients/storage.rb

Direct Known Subclasses

OAuthClient

Instance Attribute Summary collapse

Class Method 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/clients/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/clients/base.rb', line 9

def f
  @f
end

#storageObject (readonly)

Returns the value of attribute storage.



7
8
9
# File 'lib/rhack/clients/storage.rb', line 7

def storage
  @storage
end

Class Method Details

.store(type, name, opts = {}) ⇒ Object



9
10
11
# File 'lib/rhack/clients/storage.rb', line 9

def self.store(type, name, opts={})
  storage[name] = RHACK::Storage(type, (opts[:prefix] || self.name.sub('RHACK::', '').underscore)+':'+name)
end

Instance Method Details

#go(*args, &block) ⇒ Object



29
30
31
32
33
34
# File 'lib/rhack/clients/base.rb', line 29

def go(*args, &block)
  __send__(@service, *args, &block) 
rescue
  L < $!
  Curl.reload
end

#inspectObject



43
44
45
# File 'lib/rhack/clients/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/clients/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/clients/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