Module: Keen::Client::PublishingMethods
- Included in:
- Keen::Client
- Defined in:
- lib/keen/client/publishing_methods.rb
Instance Method Summary collapse
- #add_event(event_collection, properties, options = {}) ⇒ Object deprecated Deprecated.
-
#beacon_url(event_collection, properties) ⇒ Object
Returns an encoded URL that will record an event.
-
#publish(event_collection, properties) ⇒ Object
Publishes a synchronous event See detailed documentation here keen.io/docs/api/reference/#event-collection-resource.
-
#publish_async(event_collection, properties) ⇒ Object
Publishes an asynchronous event See detailed documentation here keen.io/docs/api/reference/#event-collection-resource.
-
#publish_batch(events) ⇒ Object
Publishes a batch of events See detailed documentation here keen.io/docs/api/reference/#post-request-body-example-of-batch-event-posting.
- #publish_batch_async(events) ⇒ Object
-
#redirect_url(event_collection, properties, redirect_url) ⇒ Object
Returns an encoded URL that will record an event and then redirect.
Instance Method Details
#add_event(event_collection, properties, options = {}) ⇒ Object
Publishes a synchronous event
12 13 14 |
# File 'lib/keen/client/publishing_methods.rb', line 12 def add_event(event_collection, properties, ={}) self.publish(event_collection, properties, ) end |
#beacon_url(event_collection, properties) ⇒ Object
Returns an encoded URL that will record an event. Useful in email situations. See detailed documentation here keen.io/docs/api/reference/#event-collection-resource
108 109 110 111 112 |
# File 'lib/keen/client/publishing_methods.rb', line 108 def beacon_url(event_collection, properties) json = MultiJson.encode(properties) data = [json].pack("m0").tr("+/", "-_").gsub("\n", "") "#{self.api_url}#{api_event_collection_resource_path(event_collection)}?api_key=#{self.write_key}&data=#{data}" end |
#publish(event_collection, properties) ⇒ Object
Publishes a synchronous event See detailed documentation here keen.io/docs/api/reference/#event-collection-resource
24 25 26 27 28 29 30 31 32 |
# File 'lib/keen/client/publishing_methods.rb', line 24 def publish(event_collection, properties) ensure_project_id! ensure_write_key! check_event_data!(event_collection, properties) publish_body( api_event_collection_resource_path(event_collection), MultiJson.encode(properties), "publish") end |
#publish_async(event_collection, properties) ⇒ Object
Publishes an asynchronous event See detailed documentation here keen.io/docs/api/reference/#event-collection-resource
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/keen/client/publishing_methods.rb', line 59 def publish_async(event_collection, properties) ensure_project_id! ensure_write_key! check_event_data!(event_collection, properties) http_client = Keen::HTTP::Async.new( self.api_url, {:proxy_url => self.proxy_url, :proxy_type => self.proxy_type}) http = http_client.post( :path => api_event_collection_resource_path(event_collection), :headers => api_headers(self.write_key, "async"), :body => MultiJson.encode(properties) ) if defined?(EM::Synchrony) process_with_synchrony(http) else process_with_callbacks(http) end end |
#publish_batch(events) ⇒ Object
Publishes a batch of events See detailed documentation here keen.io/docs/api/reference/#post-request-body-example-of-batch-event-posting
and the values are arrays of hashes (event properties)
42 43 44 45 46 47 48 49 |
# File 'lib/keen/client/publishing_methods.rb', line 42 def publish_batch(events) ensure_project_id! ensure_write_key! publish_body( api_events_resource_path, MultiJson.encode(events), "publish") end |
#publish_batch_async(events) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/keen/client/publishing_methods.rb', line 80 def publish_batch_async(events) ensure_project_id! ensure_write_key! http_client = Keen::HTTP::Async.new( self.api_url, {:proxy_url => self.proxy_url, :proxy_type => self.proxy_type}) http = http_client.post( :path => api_events_resource_path, :headers => api_headers(self.write_key, "async"), :body => MultiJson.encode(events) ) if defined?(EM::Synchrony) process_with_synchrony(http) else process_with_callbacks(http) end end |
#redirect_url(event_collection, properties, redirect_url) ⇒ Object
Returns an encoded URL that will record an event and then redirect. Useful in email situations. See detailed documentation here keen.io/docs/api/reference/#event-collection-resource
122 123 124 125 126 127 128 |
# File 'lib/keen/client/publishing_methods.rb', line 122 def redirect_url(event_collection, properties, redirect_url) require 'open-uri' encoded_url = URI::encode(redirect_url) json = MultiJson.encode(properties) data = [json].pack("m0").tr("+/", "-_").gsub("\n", "") "#{self.api_url}#{api_event_collection_resource_path(event_collection)}?api_key=#{self.write_key}&data=#{data}&redirect=#{encoded_url}" end |