Class: Chuckle::Client
- Inherits:
-
Object
- Object
- Chuckle::Client
- Includes:
- Options
- Defined in:
- lib/chuckle/client.rb
Constant Summary
Constants included from Options
Instance Attribute Summary collapse
-
#cache ⇒ Object
Returns the value of attribute cache.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
-
#create_request(uri, body = nil) ⇒ Object
main entry points.
- #get(uri) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
-
#inspect ⇒ Object
:nodoc:.
- #post(uri, body) ⇒ Object
- #run(request) ⇒ Object
Methods included from Options
#cache_dir, #cache_errors?, #cookies?, #expires_in, #nretries, #rate_limit, #timeout, #user_agent, #verbose?
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
9 10 11 12 13 14 |
# File 'lib/chuckle/client.rb', line 9 def initialize( = {}) self. = DEFAULT_OPTIONS.dup .each { |k, v| self.[k] = v if v } self.cache = Cache.new(self) sanity! end |
Instance Attribute Details
#cache ⇒ Object
Returns the value of attribute cache.
7 8 9 |
# File 'lib/chuckle/client.rb', line 7 def cache @cache end |
#options ⇒ Object
Returns the value of attribute options.
7 8 9 |
# File 'lib/chuckle/client.rb', line 7 def end |
Instance Method Details
#create_request(uri, body = nil) ⇒ Object
main entry points
20 21 22 23 |
# File 'lib/chuckle/client.rb', line 20 def create_request(uri, body = nil) uri = URI.parse(uri.to_s) if !uri.is_a?(URI) Request.new(self, uri, body) end |
#get(uri) ⇒ Object
25 26 27 |
# File 'lib/chuckle/client.rb', line 25 def get(uri) run(create_request(uri)) end |
#inspect ⇒ Object
:nodoc:
45 46 47 |
# File 'lib/chuckle/client.rb', line 45 def inspect #:nodoc: self.class.name end |
#post(uri, body) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/chuckle/client.rb', line 29 def post(uri, body) body = case body when Hash Util.hash_to_query(body) else body.to_s end run(create_request(uri, body)) end |
#run(request) ⇒ Object
39 40 41 42 43 |
# File 'lib/chuckle/client.rb', line 39 def run(request) response = cache.get(request) || curl(request) raise_errors(response) response end |