Class: Hyperb::FuncCallRequest
- Inherits:
-
Object
- Object
- Hyperb::FuncCallRequest
- Defined in:
- lib/hyperb/request.rb
Overview
func requests are very simple, they do not require signing
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#client ⇒ Object
Returns the value of attribute client.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#path ⇒ Object
Returns the value of attribute path.
-
#query ⇒ Object
Returns the value of attribute query.
-
#verb ⇒ Object
Returns the value of attribute verb.
Instance Method Summary collapse
- #fail_or_return(code, body) ⇒ Object
-
#initialize(client, path, query = {}, verb = 'GET', body = '') ⇒ FuncCallRequest
constructor
A new instance of FuncCallRequest.
- #perform ⇒ Object
- #set_base_url ⇒ Object
Constructor Details
#initialize(client, path, query = {}, verb = 'GET', body = '') ⇒ FuncCallRequest
Returns a new instance of FuncCallRequest.
140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/hyperb/request.rb', line 140 def initialize(client, path, query = {}, verb = 'GET', body = '') @client = client set_base_url @path = path @verb = verb @query = URI.encode_www_form(query) @body = body.empty? ? body : body.to_json @headers = { content_type: 'application/json' } end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
138 139 140 |
# File 'lib/hyperb/request.rb', line 138 def body @body end |
#client ⇒ Object
Returns the value of attribute client.
138 139 140 |
# File 'lib/hyperb/request.rb', line 138 def client @client end |
#headers ⇒ Object
Returns the value of attribute headers.
138 139 140 |
# File 'lib/hyperb/request.rb', line 138 def headers @headers end |
#path ⇒ Object
Returns the value of attribute path.
138 139 140 |
# File 'lib/hyperb/request.rb', line 138 def path @path end |
#query ⇒ Object
Returns the value of attribute query.
138 139 140 |
# File 'lib/hyperb/request.rb', line 138 def query @query end |
#verb ⇒ Object
Returns the value of attribute verb.
138 139 140 |
# File 'lib/hyperb/request.rb', line 138 def verb @verb end |
Instance Method Details
#fail_or_return(code, body) ⇒ Object
165 166 167 168 169 |
# File 'lib/hyperb/request.rb', line 165 def fail_or_return(code, body) error = Hyperb::Error::ERRORS[code] raise(error.new(body, code)) if error body end |
#perform ⇒ Object
157 158 159 160 161 162 163 |
# File 'lib/hyperb/request.rb', line 157 def perform final_url = @base_url + @path + '?' + @query = {} [:body] = @body unless @body.empty? response = HTTP.headers(@headers).public_send(@verb.downcase.to_sym, final_url, ) fail_or_return(response.code, response.body) end |
#set_base_url ⇒ Object
152 153 154 155 |
# File 'lib/hyperb/request.rb', line 152 def set_base_url @host = "#{client.region}.hyperfunc.io".freeze @base_url = "https://#{@host}/".freeze end |