Sha256: 31a885f2fcce97357d7347ecbdfa5ecfdb12f65a684439cf382c6da1560c60b5

Contents?: true

Size: 580 Bytes

Versions: 1

Compression:

Stored size: 580 Bytes

Contents

# frozen_string_literal: true
require 'json'

module Excon
  # HyperMedia
  #
  module HyperMedia
    def method_missing(method_name, *params)
      return super unless (url = entrypoint.dig('_links', method_name.to_s, 'href'))

      Excon.new(url, params.first.to_h.merge(hypermedia: true))
    end

    def respond_to_missing?(method_name, include_private = false)
      entrypoint.dig('_links', method_name.to_s, 'href') ? true : super
    end

    private

    def entrypoint
      @entrypoint ||= JSON.parse(get.body)
    rescue JSON::ParserError
      {}
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
excon-hypermedia-0.1.0 lib/excon/hypermedia/hyper_media.rb