Class: Darksky::HTTP
- Inherits:
-
Object
- Object
- Darksky::HTTP
- Defined in:
- lib/darksky-ruby/http.rb
Constant Summary collapse
- METHOD_HTTP_CLASS =
{ get: Net::HTTP::Get }
Instance Attribute Summary collapse
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#http ⇒ Object
readonly
Returns the value of attribute http.
-
#init_uri ⇒ Object
readonly
Returns the value of attribute init_uri.
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
- #get(path: nil, params: nil, query: nil) ⇒ Object
-
#initialize(url, hdrs = nil) ⇒ HTTP
constructor
A new instance of HTTP.
Constructor Details
#initialize(url, hdrs = nil) ⇒ HTTP
Returns a new instance of HTTP.
23 24 25 26 27 28 29 30 |
# File 'lib/darksky-ruby/http.rb', line 23 def initialize(url, hdrs = nil) @init_uri = URI(url) raise ArgumentError, 'Invalid URL' unless @init_uri.class <= URI::HTTP @http = Net::HTTP.new(init_uri.host, init_uri.port) http.use_ssl = init_uri.scheme == 'https' http.verify_mode = OpenSSL::SSL::VERIFY_PEER self.headers = hdrs end |
Instance Attribute Details
#headers ⇒ Object
Returns the value of attribute headers.
21 22 23 |
# File 'lib/darksky-ruby/http.rb', line 21 def headers @headers end |
#http ⇒ Object (readonly)
Returns the value of attribute http.
20 21 22 |
# File 'lib/darksky-ruby/http.rb', line 20 def http @http end |
#init_uri ⇒ Object (readonly)
Returns the value of attribute init_uri.
20 21 22 |
# File 'lib/darksky-ruby/http.rb', line 20 def init_uri @init_uri end |
Class Method Details
.get(url, params) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/darksky-ruby/http.rb', line 13 def self.get(url, params) h = HTTP.new(url) data = h.get(params: params) h.close return data end |
Instance Method Details
#close ⇒ Object
36 37 38 |
# File 'lib/darksky-ruby/http.rb', line 36 def close http.finish if http.started? end |
#get(path: nil, params: nil, query: nil) ⇒ Object
32 33 34 |
# File 'lib/darksky-ruby/http.rb', line 32 def get(path: nil, params: nil, query: nil) return operate(__method__, path: path, params: params, query: query) end |