module Projector::ApiMethods
Ruby method wrappers for the Projector
API.
Public Instance Methods
Sends an event to one or more users at Projector
@param [Hash] event a hash of the event object @option event [String] :id (SecureRandom.uuid) the ID the event @option event [String] :event_key the event key for this type of event @option event [Number] :event_time ((Time.now.to_f * 1000).to_i) the event time in ms from epoch for this event @option event [Hash] :target the recipient or recipients of the event @option event [Hash] :event_context data for use in delivery rules and notification alert templates at Projector
@option event [Hash] :payload JSON data properties to be delivered on the event (deep links, metadata, etc) @example Sending a notification to one or more individual users
event = { id: 'like-event-7391', event_key: 'liked-your-dog', event_context: {dog_name: 'Barclay', liker_name: 'Jana', liker_id: '42'}, target: {end_users: [{id: '51'}]} } Projector.deliver_event(event)
@example Sending a notification to one or more tags
event = { id: 'new-dog-492', event_key: 'new-dog', event_context: {dog_name: 'Pixel', color: 'blond', size: 'small'}, target: {tags: ['likes_dogs']} } Projector.deliver_event(event)
@raise {Projector::Error::InvalidEvent} @raise {Projector::Error::Unauthorized} @raise {Projector::Error::BadRequest} @return [Hash]
# File lib/projector/api_methods.rb, line 74 def deliver_event(event) # Create an Event instance if the parameter is a Hash. if event.instance_of?(Hash) event = Projector::Event.new(event) end # Verify that we've got an Event object. raise Projector::InvalidEvent.new("Invalid event data") unless event.instance_of?(Projector::Event) post(host, '/events', Projector::Envelope.new(event).to_hash).body end
Registers or updates an end user at Projector
@param [Hash] end_user a hash of the end user object @option end_user [String] :id the ID of the user in your application @option end_user [Array] :tags an array of tags to apply to the user @return [Hash] a hash of data that should be returned as part of the registration API call @example Register an end user
end_user = { id: '42', tags: ['likes_dogs'] } Projector.register_end_user(end_user)
@raise {Projector::Error::Unauthorized} @raise {Projector::Error::BadRequest}
# File lib/projector/api_methods.rb, line 19 def register_end_user(end_user) # If a hash is passed, use it to populate a user object if end_user.instance_of?(Hash) user = Projector::EndUser.new(end_user) # If a User instance is passed, use it elsif end_user.instance_of?(Projector::EndUser) user = end_user end # return the data element of the resulting envelope post(host, '/end_users', Projector::Envelope.new(user).to_hash).body end