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.
9 10 11 |
# File 'lib/knapsack_pro/client/connection.rb', line 9 def initialize(action) @action = action end |
Instance Method Details
#api_code ⇒ Object
28 29 30 31 |
# File 'lib/knapsack_pro/client/connection.rb', line 28 def api_code return unless response_body response_body['code'] end |
#call ⇒ Object
13 14 15 |
# File 'lib/knapsack_pro/client/connection.rb', line 13 def call send(action.http_method) end |
#errors? ⇒ Boolean
24 25 26 |
# File 'lib/knapsack_pro/client/connection.rb', line 24 def errors? !!(response_body && (response_body['errors'] || response_body['error'])) end |
#server_error? ⇒ Boolean
33 34 35 36 |
# File 'lib/knapsack_pro/client/connection.rb', line 33 def server_error? status = http_response.code.to_i status >= 500 && status < 600 end |
#success? ⇒ Boolean
17 18 19 20 21 22 |
# File 'lib/knapsack_pro/client/connection.rb', line 17 def success? return false if !response_body status = http_response.code.to_i status >= 200 && status < 500 end |