Class: Postgrest::HTTP
- Inherits:
-
Object
- Object
- Postgrest::HTTP
- Defined in:
- lib/postgrest/http.rb
Constant Summary collapse
- METHODS =
{ get: Net::HTTP::Get, post: Net::HTTP::Post, patch: Net::HTTP::Patch, put: Net::HTTP::Patch, delete: Net::HTTP::Delete }.freeze
- RESPONSES =
{ get: Responses::GetResponse, post: Responses::PostResponse, put: Responses::PatchResponse, patch: Responses::PatchResponse, delete: Responses::DeleteResponse, options: Responses::GetResponse # ? }.freeze
- USER_AGENT =
'PostgREST Ruby Client'
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#http_method ⇒ Object
readonly
Returns the value of attribute http_method.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
- #call ⇒ Object (also: #execute)
-
#initialize(uri:, query: {}, body: {}, headers: {}, http_method: :get) ⇒ HTTP
constructor
A new instance of HTTP.
- #update_query_params(new_value = {}) ⇒ Object
Constructor Details
#initialize(uri:, query: {}, body: {}, headers: {}, http_method: :get) ⇒ HTTP
Returns a new instance of HTTP.
26 27 28 29 30 31 32 33 34 |
# File 'lib/postgrest/http.rb', line 26 def initialize(uri:, query: {}, body: {}, headers: {}, http_method: :get) @uri = uri @body = body @headers = headers @http_method = http_method.to_sym @response = nil @request = nil uri.query = decode_query_params(query) end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
24 25 26 |
# File 'lib/postgrest/http.rb', line 24 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
24 25 26 |
# File 'lib/postgrest/http.rb', line 24 def headers @headers end |
#http_method ⇒ Object (readonly)
Returns the value of attribute http_method.
24 25 26 |
# File 'lib/postgrest/http.rb', line 24 def http_method @http_method end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
24 25 26 |
# File 'lib/postgrest/http.rb', line 24 def query @query end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
24 25 26 |
# File 'lib/postgrest/http.rb', line 24 def request @request end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
24 25 26 |
# File 'lib/postgrest/http.rb', line 24 def response @response end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
24 25 26 |
# File 'lib/postgrest/http.rb', line 24 def uri @uri end |
Instance Method Details
#call ⇒ Object Also known as: execute
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/postgrest/http.rb', line 42 def call raise InvalidHTTPMethod unless valid_http_method? @response = Net::HTTP.start(uri.host, uri.port, use_ssl: use_ssl?) do |http| @request = create_request http.request(request) end RESPONSES[http_method].new(request, response) end |
#update_query_params(new_value = {}) ⇒ Object
36 37 38 39 40 |
# File 'lib/postgrest/http.rb', line 36 def update_query_params(new_value = {}) @uri.query = decode_query_params(new_value) rescue NoMethodError @uri.query end |