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
Constant Summary collapse
- REGION =
'us-west-1'.freeze
- URL =
"https://#{REGION}.hyperfunc.io/".freeze
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#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
Constructor Details
#initialize(client, path, query = {}, verb = 'GET', body = '') ⇒ FuncCallRequest
Returns a new instance of FuncCallRequest.
137 138 139 140 141 142 143 144 |
# File 'lib/hyperb/request.rb', line 137 def initialize(client, path, query = {}, verb = 'GET', body = '') @client = client @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.
135 136 137 |
# File 'lib/hyperb/request.rb', line 135 def body @body end |
#headers ⇒ Object
Returns the value of attribute headers.
135 136 137 |
# File 'lib/hyperb/request.rb', line 135 def headers @headers end |
#path ⇒ Object
Returns the value of attribute path.
135 136 137 |
# File 'lib/hyperb/request.rb', line 135 def path @path end |
#query ⇒ Object
Returns the value of attribute query.
135 136 137 |
# File 'lib/hyperb/request.rb', line 135 def query @query end |
#verb ⇒ Object
Returns the value of attribute verb.
135 136 137 |
# File 'lib/hyperb/request.rb', line 135 def verb @verb end |
Instance Method Details
#fail_or_return(code, body) ⇒ Object
154 155 156 157 158 |
# File 'lib/hyperb/request.rb', line 154 def fail_or_return(code, body) error = Hyperb::Error::ERRORS[code] raise(error.new(body, code)) if error body end |
#perform ⇒ Object
146 147 148 149 150 151 152 |
# File 'lib/hyperb/request.rb', line 146 def perform final_url = 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 |