Class: KnapsackPro::Client::Connection
- Inherits:
-
Object
- Object
- KnapsackPro::Client::Connection
- Defined in:
- lib/knapsack_pro/client/connection.rb
Defined Under Namespace
Classes: ServerError
Constant Summary collapse
- TIMEOUT =
15- REQUEST_RETRY_TIMEBOX =
8
Instance Method Summary collapse
- #api_code ⇒ Object
- #call ⇒ Object
- #errors? ⇒ Boolean
-
#initialize(action) ⇒ Connection
constructor
A new instance of Connection.
- #server_error? ⇒ Boolean
- #success? ⇒ Boolean
Constructor Details
#initialize(action) ⇒ Connection
Returns a new instance of Connection.
11 12 13 |
# File 'lib/knapsack_pro/client/connection.rb', line 11 def initialize(action) @action = action end |
Instance Method Details
#api_code ⇒ Object
30 31 32 33 |
# File 'lib/knapsack_pro/client/connection.rb', line 30 def api_code return unless response_body response_body['code'] end |
#call ⇒ Object
15 16 17 |
# File 'lib/knapsack_pro/client/connection.rb', line 15 def call send(action.http_method) end |
#errors? ⇒ Boolean
26 27 28 |
# File 'lib/knapsack_pro/client/connection.rb', line 26 def errors? !!(response_body && (response_body['errors'] || response_body['error'])) end |
#server_error? ⇒ Boolean
35 36 37 38 |
# File 'lib/knapsack_pro/client/connection.rb', line 35 def server_error? status = http_response.code.to_i status >= 500 && status < 600 end |
#success? ⇒ Boolean
19 20 21 22 23 24 |
# File 'lib/knapsack_pro/client/connection.rb', line 19 def success? return false if !response_body status = http_response.code.to_i status >= 200 && status < 500 end |