Class: ZQuickblox::Request
- Inherits:
-
Object
- Object
- ZQuickblox::Request
- Defined in:
- lib/zquickblox/request.rb
Direct Known Subclasses
Dialog::CreateDialogRequest, Dialog::GetDialogsRequest, Dialog::UpdateDialogRequest, Session, User::CreateUserRequest, User::DeleteUserRequest, User::FindUserRequest, User::LoginUserRequest
Constant Summary collapse
- API_ENDPOINT =
"https://api.quickblox.com"
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#method ⇒ Object
Returns the value of attribute method.
-
#params ⇒ Object
Returns the value of attribute params.
-
#response ⇒ Object
Returns the value of attribute response.
-
#response_body ⇒ Object
Returns the value of attribute response_body.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
- #after_request ⇒ Object
- #before_request ⇒ Object
- #execute ⇒ Object
- #header(key, value) ⇒ Object
-
#initialize ⇒ Request
constructor
A new instance of Request.
Constructor Details
#initialize ⇒ Request
Returns a new instance of Request.
9 10 11 12 13 14 15 16 17 |
# File 'lib/zquickblox/request.rb', line 9 def initialize @connection = Faraday.new(url: Request::API_ENDPOINT) do |faraday| faraday.request :url_encoded faraday.response :logger faraday.adapter Faraday.default_adapter end @headers = {} end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
6 7 8 |
# File 'lib/zquickblox/request.rb', line 6 def connection @connection end |
#errors ⇒ Object
Returns the value of attribute errors.
5 6 7 |
# File 'lib/zquickblox/request.rb', line 5 def errors @errors end |
#headers ⇒ Object
Returns the value of attribute headers.
5 6 7 |
# File 'lib/zquickblox/request.rb', line 5 def headers @headers end |
#method ⇒ Object
Returns the value of attribute method.
5 6 7 |
# File 'lib/zquickblox/request.rb', line 5 def method @method end |
#params ⇒ Object
Returns the value of attribute params.
5 6 7 |
# File 'lib/zquickblox/request.rb', line 5 def params @params end |
#response ⇒ Object
Returns the value of attribute response.
5 6 7 |
# File 'lib/zquickblox/request.rb', line 5 def response @response end |
#response_body ⇒ Object
Returns the value of attribute response_body.
5 6 7 |
# File 'lib/zquickblox/request.rb', line 5 def response_body @response_body end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
7 8 9 |
# File 'lib/zquickblox/request.rb', line 7 def uri @uri end |
Instance Method Details
#after_request ⇒ Object
26 27 |
# File 'lib/zquickblox/request.rb', line 26 def after_request end |
#before_request ⇒ Object
23 24 |
# File 'lib/zquickblox/request.rb', line 23 def before_request end |
#execute ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/zquickblox/request.rb', line 29 def execute before_request get if @method == :get post if @method == :post put if @method == :put delete if @method == :delete if @response.status != 404 && @response.body.length > 1 @response_body = JSON.parse(@response.body) else @response_body = {} end @errors = @response_body["errors"] if @response.status != 404 if @errors if @errors.kind_of?(Hash) raise ZQuickblox::Error.new(messages: @errors["base"]) if !@errors["base"].nil? = "" @errors.each do |key, value| += "; " + key += " " + value.join(", ") end raise ZQuickblox::Error.new(messages: ) end end after_request end |
#header(key, value) ⇒ Object
19 20 21 |
# File 'lib/zquickblox/request.rb', line 19 def header(key, value) headers[key] = value end |