lib/wcc/media/client.rb in wcc-media-client-0.4.15 vs lib/wcc/media/client.rb in wcc-media-client-0.5.0

- old
+ new

@@ -1,5 +1,7 @@ +# frozen_string_literal: true + require 'wcc/api/rest_client' require_relative 'message' require_relative 'series' require_relative 'speaker' require_relative 'tag' @@ -10,10 +12,11 @@ module WCC module Media class Client < ::WCC::API::RestClient class << self attr_writer :default + # The default client. Set this in an initializer to change the client used # by all the WCC::Media models def default @default ||= new end @@ -37,14 +40,12 @@ 'speakers' => WCC::Media::Speaker, 'tags' => WCC::Media::Tag, 'playlists' => WCC::Media::Playlist, 'streams' => WCC::Media::LiveStream }.freeze - attr_reader(*RESOURCES.keys) + attr_reader(*RESOURCES.keys, :options) - attr_reader :options - def initialize(**options) options = { api_url: 'https://media.watermark.org/api/v1/', response_class: Response, adapter: :typhoeus @@ -56,23 +57,23 @@ end end Resource = Struct.new(:client, :model, :options) do - def find(id, **params) + def find(id, **params) # rubocop:disable Metrics/AbcSize raise ArgumentError, "id param must be present, got: #{id}" unless id && /\S/.match(id.to_s) resp = client.get( "#{model.endpoint}/#{id}", - default_params('target').merge(params), + default_params('target').merge(params) ) resp.assert_ok! model.new(resp.body[model.key], resp.headers.freeze) end def list(**filters) query = extract_params(filters) - query = query.merge!(apply_filters(filters, model.filters)) + query.merge!(apply_filters(filters, model.filters)) resp = client.get(model.endpoint, query) resp.assert_ok! resp.items.map { |s| model.new(s) } end