class MovidaEvents::Client
The interface to the Movida event stream API
Manages authentication and API configuration
Public Class Methods
Create a new `MovidaEvents::Client`
@param [Hash] options API setup options @option options [String] :username The username to authenticate with
Required.
@option options [String] :password The password to authenticate with.
Required.
@option options [String] :domain The API domain to use. Default:
'movida.bebanjo.net'.
# File lib/movida_events/client.rb, line 17 def initialize(options = {}) @options = default_options.merge(options) @auth = Almodovar::DigestAuth.new( @options[:realm], @options[:username], @options[:password] ) end
Public Instance Methods
Request a list of events
@param [Hash] params Request parameters @option params [String] newer_than An event ID indicating the position in
the event stream where the request starts.
@option params [String] event_type A comma separated list of event types. @yield Each returned event @yieldparam event [Almodovar::Resource] The event object @return [Enumerator<Almodovar::Resource>] An enumerator over the returned
events
# File lib/movida_events/client.rb, line 36 def events(params = {}, &block) Enumerator.new do |yielder| events = events_collection(params) events.each { |e| yielder << e } end.each(&block) end
Private Instance Methods
Get the events API URL
# File lib/movida_events/client.rb, line 58 def api_url "https://#{@options[:domain]}/api/events" end
Get the default options for {#initialize}
# File lib/movida_events/client.rb, line 63 def default_options { realm: 'realm', username: nil, password: nil, domain: 'movida.bebanjo.net' } end
Get a `Almodovar::ResourceCollection` of events
@param [Hash] params Request parameters, see {#events}.
# File lib/movida_events/client.rb, line 48 def events_collection(params) Almodovar::ResourceCollection.new( api_url, @auth, nil, params ) end