Class: STAC::SimpleHTTPClient
- Inherits:
-
Object
- Object
- STAC::SimpleHTTPClient
- Defined in:
- lib/stac/simple_http_client.rb
Overview
Simple HTTP Client using OpenURI.
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#get(url) ⇒ Object
Makes a HTTP request and returns the responded JSON as Hash.
-
#initialize(options = { 'User-Agent' => "stac-ruby v#{VERSION}" }) ⇒ SimpleHTTPClient
constructor
A new instance of SimpleHTTPClient.
Constructor Details
#initialize(options = { 'User-Agent' => "stac-ruby v#{VERSION}" }) ⇒ SimpleHTTPClient
Returns a new instance of SimpleHTTPClient.
16 17 18 |
# File 'lib/stac/simple_http_client.rb', line 16 def initialize( = { 'User-Agent' => "stac-ruby v#{VERSION}" }) @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
14 15 16 |
# File 'lib/stac/simple_http_client.rb', line 14 def @options end |
Instance Method Details
#get(url) ⇒ Object
Makes a HTTP request and returns the responded JSON as Hash.
Raises STAC::HTTPError when the response status is not 2XX.
23 24 25 26 27 28 |
# File 'lib/stac/simple_http_client.rb', line 23 def get(url) body = URI(url).read() JSON.parse(body) rescue OpenURI::HTTPError => e raise HTTPError, e. end |