Sha256: 979d1856a75ec66468d8c0842d89025bcfadce57e57be2b39a9e52d52c5eeb0d

Contents?: true

Size: 674 Bytes

Versions: 3

Compression:

Stored size: 674 Bytes

Contents

require 'json'

module Fitting
  class Records
    class Spherical
      class Response
        attr_reader :status, :body

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

        def to_hash
          {
            status: status,
            body: JSON.load(body)
          }
        rescue JSON::ParserError
          {
            status: status,
            body: {}
          }
        end

        def to_json
          JSON.dump(to_hash)
        end

        class << self
          def load(hash)
            new(status: hash["status"], body: hash["body"])
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fitting-2.7.1 lib/fitting/records/spherical/response.rb
fitting-2.7.0 lib/fitting/records/spherical/response.rb
fitting-2.6.0 lib/fitting/records/spherical/response.rb