Sha256: d2fb7956a9389d6c1ee0f3aeabe681a0a332ce046b5eb5ecafcea2f4a0b95745

Contents?: true

Size: 980 Bytes

Versions: 1

Compression:

Stored size: 980 Bytes

Contents

# frozen_string_literal: true
module Foederati
  ##
  # A Foederati provider is one JSON API provider capable of being searched by
  # the Foederati.
  #
  # TODO allow specification of a wildcard to search all the provider's records
  class Provider
    autoload :Request, 'foederati/provider/request'
    autoload :Response, 'foederati/provider/response'

    # TODO validate the type of values added to these
    Urls = Struct.new(:api, :site)
    Results = Struct.new(:items, :total)
    Fields = Struct.new(:title, :thumbnail, :url)

    attr_reader :id, :urls, :results, :fields

    def initialize(id, &block)
      @id = id
      @urls = Urls.new
      @results = Results.new
      @fields = Fields.new

      instance_eval(&block) if block_given?

      self
    end

    # TODO sanity check things like presence of API URL
    def search(**params)
      request.execute(params).normalise
    end

    protected

    def request
      Request.new(self)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
foederati-0.1.0 lib/foederati/provider.rb