Sha256: 903a4faeb2e0bff6d786a554dd51252a87851565cd6058655a1f791e62695afc

Contents?: true

Size: 784 Bytes

Versions: 2

Compression:

Stored size: 784 Bytes

Contents

module ComicVine
  class Api
    class Response
      attr_reader :raw_response, :status, :headers, :body, :error, :limit,
                  :offset, :number_of_page_results, :number_of_total_results,
                  :status_code, :results, :version

      def initialize(status:, headers:, body:)
        @status = status
        @headers = headers
        @body = body

        parse_body
      end

      private

      def parse_body
        data = JSON.parse(body)
        methods = %w(error limit offset number_of_page_results
                     number_of_total_results status_code results version)

        methods.each do |method_name|
          instance_variable_set(:"@#{method_name}", data[method_name])
        end
      rescue
        nil
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
comic_vine-api-0.1.1 lib/comic_vine/api/response.rb
comic_vine-api-0.1.0 lib/comic_vine/api/response.rb