diff --git a/lib/scalingo/api/client.rb b/lib/scalingo/api/client.rb index 0d4d929..6b20d84 100644 --- a/lib/scalingo/api/client.rb +++ b/lib/scalingo/api/client.rb @@ -1,4 +1,6 @@ require "scalingo/token_holder" +require "scalingo/faraday/response" +require "active_support/core_ext/hash" module Scalingo module API diff --git a/lib/scalingo/faraday/response.rb b/lib/scalingo/faraday/response.rb new file mode 100644 index 0000000..a958e60 --- /dev/null +++ b/lib/scalingo/faraday/response.rb @@ -0,0 +1,29 @@ +require "faraday" +require "faraday/response" + +# Some additional methods for Faraday::Response in order to enhance expressiveness +module Faraday + class Response + # @deprecated Use {#success?} instead + def successful? + success? + end + + # @deprecated Use {#body} instead + def data + body + end + + def client_error? + RaiseError::ClientErrorStatuses.include?(status) + end + + def server_error? + RaiseError::ServerErrorStatuses.include?(status) + end + + def error? + !success? + end + end +end