Class: Boson::Commands::WebCore::Get
- Inherits:
-
Object
- Object
- Boson::Commands::WebCore::Get
- Defined in:
- lib/boson/commands/web_core.rb
Overview
Used by the get command to make get requests and optionally parse json and yaml. Ruby 1.8.x is dependent on json gem for parsing json. See Get.request for options a request can take.
Constant Summary collapse
- FORMAT_HEADERS =
{ :json=>%w{application/json text/json application/javascript text/javascript}, :yaml=>%w{application/x-yaml text/yaml} }
Instance Method Summary collapse
-
#initialize(url, options = {}) ⇒ Get
constructor
:nodoc:.
-
#request(options = {}) ⇒ Object
Returns the response body string or a parsed data structure.
Constructor Details
#initialize(url, options = {}) ⇒ Get
:nodoc:
94 95 96 |
# File 'lib/boson/commands/web_core.rb', line 94 def initialize(url, ={}) @url, @options = url, end |
Instance Method Details
#request(options = {}) ⇒ Object
Returns the response body string or a parsed data structure. Returns nil if request fails. By default expects response to be 200.
Options:
- :any_response
-
Returns body string for any response code. Default is false.
- :parse
-
Parse the body into either json or yaml. Expects a valid format or if true autodetects one. Default is false.
- :raise_error
-
Raises any original errors when parsing or fetching url instead of handling errors silently.
105 106 107 108 109 |
# File 'lib/boson/commands/web_core.rb', line 105 def request(={}) @options.merge! body = get_body body && @options[:parse] ? parse_body(body) : body end |