Class: RHACK::Client
- Defined in:
- lib/rhack/clients/base.rb,
lib/rhack/clients/storage.rb
Direct Known Subclasses
Constant Summary collapse
- @@frame_defaults =
{}
- @@accounts =
{}
- @@routes =
{}
Instance Attribute Summary collapse
-
#f ⇒ Object
Returns the value of attribute f.
-
#service ⇒ Object
readonly
Returns the value of attribute service.
-
#storage ⇒ Object
readonly
Returns the value of attribute storage.
Class Method Summary collapse
Instance Method Summary collapse
- #account(name) ⇒ Object
- #go(*args, &block) ⇒ Object
-
#initialize(service = :api, opts = {}) ⇒ Client
constructor
A new instance of Client.
- #inspect ⇒ Object
-
#login {|@f.get(route :login)| ... } ⇒ Object
Usable only for sync requests.
-
#route(name) ⇒ Object
(also: #url, #URI)
shortcuts to class variables #.
- #scrape!(page) ⇒ Object
Constructor Details
#initialize(service = :api, opts = {}) ⇒ Client
Returns a new instance of Client.
52 53 54 55 56 57 58 |
# File 'lib/rhack/clients/base.rb', line 52 def initialize(service=:api, opts={}) @service = service # first argument should be a string so that frame won't be static @f = opts.is_a?(Frame) ? opts : Frame(route(service) || route(:login), @@frame_defaults.merge(opts)) end |
Instance Attribute Details
#f ⇒ Object
Returns the value of attribute f.
10 11 12 |
# File 'lib/rhack/clients/base.rb', line 10 def f @f end |
#service ⇒ Object (readonly)
Returns the value of attribute service.
9 10 11 |
# File 'lib/rhack/clients/base.rb', line 9 def service @service end |
#storage ⇒ Object (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
.inherited(child) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/rhack/clients/base.rb', line 21 def inherited(child) child.class_eval { include RHACK __init__ } end |
.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
#account(name) ⇒ Object
101 102 103 |
# File 'lib/rhack/clients/base.rb', line 101 def account(name) @@accounts[name] end |
#go(*args, &block) ⇒ Object
72 73 74 75 76 77 |
# File 'lib/rhack/clients/base.rb', line 72 def go(*args, &block) __send__(@service, *args, &block) rescue L < $! Curl.reload end |
#inspect ⇒ Object
88 89 90 |
# File 'lib/rhack/clients/base.rb', line 88 def inspect "<##{self.class.self_name}:#{@service.to_s.camelize} service via #{@f.inspect}>" end |
#login {|@f.get(route :login)| ... } ⇒ Object
Usable only for sync requests
62 63 64 65 66 67 68 69 70 |
# File 'lib/rhack/clients/base.rb', line 62 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(route :login) @f.get(route :home) if route :home @f.opts[:json], @f.opts[:wait] = json, wait @f. end |
#route(name) ⇒ Object Also known as: url, URI
shortcuts to class variables #
94 95 96 |
# File 'lib/rhack/clients/base.rb', line 94 def route(name) @@routes[name] end |
#scrape!(page) ⇒ Object
81 82 83 84 85 86 |
# File 'lib/rhack/clients/base.rb', line 81 def scrape!(page) __send__(:"scrape_#{@service}", page) if url = next_url(page) @f.get(url) {|next_page| scrape!(next_page)} end end |