Class: Neko::HTTP
- Inherits:
-
Object
- Object
- Neko::HTTP
- Defined in:
- lib/darksky-ruby/http.rb
Constant Summary collapse
- METHOD_HTTP_CLASS =
{ get: Net::HTTP::Get, put: Net::HTTP::Put, patch: Net::HTTP::Patch, post: Net::HTTP::Post, delete: Net::HTTP::Delete }
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.
-
#logger ⇒ Object
Returns the value of attribute logger.
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
- #delete(path: nil, params: nil, query: nil) ⇒ Object
- #get(path: nil, params: nil, query: nil) ⇒ Object
-
#initialize(url, hdrs = nil) ⇒ HTTP
constructor
A new instance of HTTP.
- #patch(path: nil, params: nil, body: nil, query: nil) ⇒ Object
- #post(path: nil, params: nil, body: nil, query: nil) ⇒ Object
- #put(path: nil, params: nil, body: nil, query: nil) ⇒ Object
Constructor Details
#initialize(url, hdrs = nil) ⇒ HTTP
Returns a new instance of HTTP.
44 45 46 47 48 49 50 51 52 |
# File 'lib/darksky-ruby/http.rb', line 44 def initialize(url, hdrs = nil) @logger = Neko.logger @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.
42 43 44 |
# File 'lib/darksky-ruby/http.rb', line 42 def headers @headers end |
#http ⇒ Object (readonly)
Returns the value of attribute http.
41 42 43 |
# File 'lib/darksky-ruby/http.rb', line 41 def http @http end |
#init_uri ⇒ Object (readonly)
Returns the value of attribute init_uri.
41 42 43 |
# File 'lib/darksky-ruby/http.rb', line 41 def init_uri @init_uri end |
#logger ⇒ Object
Returns the value of attribute logger.
42 43 44 |
# File 'lib/darksky-ruby/http.rb', line 42 def logger @logger end |
Class Method Details
Instance Method Details
#close ⇒ Object
74 75 76 |
# File 'lib/darksky-ruby/http.rb', line 74 def close http.finish if http.started? end |
#delete(path: nil, params: nil, query: nil) ⇒ Object
70 71 72 |
# File 'lib/darksky-ruby/http.rb', line 70 def delete(path: nil, params: nil, query: nil) return operate(__method__, path: path, params: params, query: query) end |
#get(path: nil, params: nil, query: nil) ⇒ Object
54 55 56 |
# File 'lib/darksky-ruby/http.rb', line 54 def get(path: nil, params: nil, query: nil) return operate(__method__, path: path, params: params, query: query) end |
#patch(path: nil, params: nil, body: nil, query: nil) ⇒ Object
66 67 68 |
# File 'lib/darksky-ruby/http.rb', line 66 def patch(path: nil, params: nil, body: nil, query: nil) return operate(__method__, path: path, params: params, body: body, query: query) end |
#post(path: nil, params: nil, body: nil, query: nil) ⇒ Object
58 59 60 |
# File 'lib/darksky-ruby/http.rb', line 58 def post(path: nil, params: nil, body: nil, query: nil) return operate(__method__, path: path, params: params, body: body, query: query) end |
#put(path: nil, params: nil, body: nil, query: nil) ⇒ Object
62 63 64 |
# File 'lib/darksky-ruby/http.rb', line 62 def put(path: nil, params: nil, body: nil, query: nil) return operate(__method__, path: path, params: params, body: body, query: query) end |