Sha256: c3ccd3cd783c6619d78392596aa8decffe42c28c61425b71cd4a2ff6e542be30

Contents?: true

Size: 695 Bytes

Versions: 23

Compression:

Stored size: 695 Bytes

Contents

require 'ostruct'
# Response data is data provided through the response body
# but made accssible in the ruby world
class LHC::Response::Data < OpenStruct

  def initialize(response)
    @response = response
    set_dynamic_accessor_methods
    super(as_json)
  end

  def as_json
    response.format.as_json(response)
  end

  def as_open_struct
    response.format.as_open_struct(response)
  end

  def [](key)
    @hash ||= as_json.with_indifferent_access
    @hash[key]
  end

  private

  attr_reader :response

  def set_dynamic_accessor_methods
    as_json.keys.each do |key|
      define_singleton_method key do |*args|
        as_open_struct.send key, *args
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
lhc-6.4.0 lib/lhc/response/data.rb
lhc-6.3.1 lib/lhc/response/data.rb
lhc-6.3.0 lib/lhc/response/data.rb
lhc-6.2.0 lib/lhc/response/data.rb
lhc-6.1.3 lib/lhc/response/data.rb
lhc-6.1.2 lib/lhc/response/data.rb
lhc-6.1.1 lib/lhc/response/data.rb
lhc-6.1.0 lib/lhc/response/data.rb
lhc-6.0.1 lib/lhc/response/data.rb
lhc-6.0.0 lib/lhc/response/data.rb
lhc-5.1.1 lib/lhc/response/data.rb
lhc-5.1.0 lib/lhc/response/data.rb
lhc-5.0.3 lib/lhc/response/data.rb
lhc-5.0.2 lib/lhc/response/data.rb
lhc-5.0.1 lib/lhc/response/data.rb
lhc-5.0.0 lib/lhc/response/data.rb
lhc-4.0.2 lib/lhc/response/data.rb
lhc-4.0.1 lib/lhc/response/data.rb
lhc-4.0.0 lib/lhc/response/data.rb
lhc-3.8.1 lib/lhc/response/data.rb