Class: STAC::SimpleHTTPClient

Inherits:
Object
  • Object
show all
Defined in:
lib/stac/simple_http_client.rb

Overview

Simple HTTP Client using OpenURI.

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options = { 'User-Agent' => "stac-ruby v#{VERSION}" })
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



14
15
16
# File 'lib/stac/simple_http_client.rb', line 14

def options
  @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(options)
  JSON.parse(body)
rescue OpenURI::HTTPError => e
  raise HTTPError, e.message
end