Sha256: dcdd96022ac3a4700a6202690196eda3ce342608155f2ecac444a1df1d302690

Contents?: true

Size: 683 Bytes

Versions: 7

Compression:

Stored size: 683 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.parse(body)
          }
        rescue JSON::ParserError
          {
            status: status,
            body: {}
          }
        end

        def to_json(*_args)
          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

7 entries across 7 versions & 1 rubygems

Version Path
fitting-3.0.2 lib/fitting/records/spherical/response.rb
fitting-3.0.1 lib/fitting/records/spherical/response.rb
fitting-3.0.0 lib/fitting/records/spherical/response.rb
fitting-2.18.3 lib/fitting/records/spherical/response.rb
fitting-2.18.2 lib/fitting/records/spherical/response.rb
fitting-2.18.1 lib/fitting/records/spherical/response.rb
fitting-2.18.0 lib/fitting/records/spherical/response.rb