Class: Notifo
Overview
Simple client class for the Notifo API.
Instance Method Summary collapse
-
#initialize(username, api_secret) ⇒ Notifo
constructor
Create a new client instance.
-
#post(username, message, title = nil, uri = nil, label = nil) ⇒ Object
:ndoc:.
-
#send_message(username, message) ⇒ Object
Send a message to a specific Notifo user.
-
#send_notification(username, message, title = nil, uri = nil, label = nil) ⇒ Object
Send a notification to the specified user.
-
#subscribe_user(username) ⇒ Object
Subscribe a user to your service.
-
#verify_webhook_signature(params) ⇒ Object
Required Parameters: params - the hash of params the webhook passed to you.
Constructor Details
#initialize(username, api_secret) ⇒ Notifo
Create a new client instance. Must be supplied with the username and api_secret for your service.
Required Parameters: username - notifo service username api_secret - notifo service api secret
16 17 18 |
# File 'lib/notifo.rb', line 16 def initialize(username, api_secret) @auth = { :username => username, :password => api_secret } end |
Instance Method Details
#post(username, message, title = nil, uri = nil, label = nil) ⇒ Object
:ndoc:
46 47 48 49 |
# File 'lib/notifo.rb', line 46 def post(username, , title = nil, uri = nil, label = nil) # :ndoc: warn "DEPRECATION WARNING: the 'post' method is deprecated. Use 'send_notification' instead" send_notification(username, , title, uri, label) end |
#send_message(username, message) ⇒ Object
Send a message to a specific Notifo user. Messages are slightly different from notifications in that they are permitted to be sent to users who haven’t subscribed.
Required Parameters: username - notifo username of recipient message - message being sent; must be url encoded
71 72 73 74 |
# File 'lib/notifo.rb', line 71 def (username, ) = { :body => { :to => username, :msg => }, :basic_auth => @auth } self.class.post('/send_message', ) end |
#send_notification(username, message, title = nil, uri = nil, label = nil) ⇒ Object
Send a notification to the specified user. You will only be allowed to send notifications to users who have previously subscribed to your service.
Required Parameters: username - notifo username of recipient message - message being sent; must be url encoded
Optional Parameters: title - name of “notification event” uri - the uri that will be loaded when the notification is opened; if specified, must be urlencoded; if a web address, must start with http:// or https:// label - label describing the “application” (used only if being sent from a User account; the Service label is automatically applied if being sent from a Service account)
41 42 43 44 |
# File 'lib/notifo.rb', line 41 def send_notification(username, , title = nil, uri = nil, label = nil) = { :body => {:to => username, :msg => , :label => title, :title => title, :uri => uri}, :basic_auth => @auth } self.class.post('/send_notification', ) end |
#subscribe_user(username) ⇒ Object
Subscribe a user to your service. This sends them a message confirming they want to use the service.
Required Parameters: username - notifo username to subscribe to your service
25 26 27 28 |
# File 'lib/notifo.rb', line 25 def subscribe_user(username) = { :body => { :username => username }, :basic_auth => @auth } self.class.post("/subscribe_user", ) end |
#verify_webhook_signature(params) ⇒ Object
Required Parameters: params - the hash of params the webhook passed to you. All keys must be Strings, not symbols.
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/notifo.rb', line 53 def verify_webhook_signature(params) signature = params['notifo_signature'] other_notifo_params = params.reject {|key,val| !(key =~ /\Anotifo_/ && key != "notifo_signature")} str = other_notifo_params.keys.sort.map do |key| params[key] end.join str << @auth[:password] signature == Digest::SHA1.hexdigest(CGI::escape(str)) end |