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