Sha256: 205d235a7fcd8868d49e07238a14b35f0292e9d84c9183cf4686660e2aeec4b4

Contents?: true

Size: 744 Bytes

Versions: 31

Compression:

Stored size: 744 Bytes

Contents

module LHC::Formats
  class JSON
    include LHC::BasicMethodsConcern

    def self.request(options)
      options[:headers] ||= {}
      options[:headers]['Content-Type'] = 'application/json'
      options[:headers]['Accept'] = 'application/json'
      options[:format] = new
      super(options)
    end

    def as_json(response)
      parse(response, Hash)
    end

    def as_open_struct(response)
      parse(response, OpenStruct)
    end

    def to_s
      'json'
    end

    def to_sym
      to_s.to_sym
    end

    private

    def parse(response, object_class)
      ::JSON.parse(response.body, object_class: object_class)
    rescue ::JSON::ParserError => e
      raise LHC::ParserError.new(e.message, response)
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
lhc-8.1.1 lib/lhc/formats/json.rb
lhc-8.1.0 lib/lhc/formats/json.rb
lhc-8.0.0 lib/lhc/formats/json.rb
lhc-7.3.3 lib/lhc/formats/json.rb
lhc-7.3.2 lib/lhc/formats/json.rb
lhc-7.3.1 lib/lhc/formats/json.rb
lhc-7.3.0 lib/lhc/formats/json.rb
lhc-7.2.0 lib/lhc/formats/json.rb
lhc-7.1.0 lib/lhc/formats/json.rb
lhc-7.0.1 lib/lhc/formats/json.rb
lhc-7.0.0 lib/lhc/formats/json.rb
lhc-7.0.0.beta1 lib/lhc/formats/json.rb
lhc-6.7.2 lib/lhc/formats/json.rb
lhc-6.7.1 lib/lhc/formats/json.rb
lhc-6.7.0 lib/lhc/formats/json.rb
lhc-6.6.0.zipkin.pre.03 lib/lhc/formats/json.rb
lhc-6.6.0.zipkin.pre.02 lib/lhc/formats/json.rb
lhc-6.6.0.zipkin.pre.01 lib/lhc/formats/json.rb
lhc-6.6.0.zipkin.pre lib/lhc/formats/json.rb
lhc-6.6.0 lib/lhc/formats/json.rb