openc/turbot-api

View on GitHub
lib/turbot/api/response.rb

Summary

Maintainability
A
0 mins
Test Coverage
module Turbot
  class API
    class Response < SimpleDelegator
      attr_reader :message

      def initialize(response)
        super
        @parsed_body = JSON.parse(response.body, :symbolize_names => true)
        @message = @parsed_body[:message]
      end
    end

    class SuccessResponse < Response
      attr_reader :data

      def initialize(response)
        super
        @data = @parsed_body[:data]
      end
    end

    class FailureResponse < Response
      attr_reader :error_code

      def initialize(response)
        super
        @error_code = @parsed_body[:error_code]
      end
    end
  end
end