lib/messenger/notifo.rb in messenger-0.2.0 vs lib/messenger/notifo.rb in messenger-0.3.0
- old
+ new
@@ -1,47 +1,42 @@
-require 'httparty'
+require 'typhoeus'
require 'json'
-module Messenger
+class Messenger::Notifo
- class Notifo
+ def self.valid_url?(url)
+ !!url.match(/^notifo:\/\/.+$/)
+ end
- def self.valid_url?(url)
- !!url.match(/^notifo:\/\/.+$/)
- end
+ # URL format:
+ # notifo://username
+ #
+ # Options:
+ # :notifo_api_username => The service's API username
+ # :notifo_api_secret => The service's API secret
+ # :notifo_title => The notificaiton title
+ # :notifo_url => Open this URL
+ def self.deliver(url, message, options={})
+ raise Messenger::URLError, "The URL provided is invalid" unless valid_url?(url)
+ username = matcher(url)
+ response = Typhoeus::Request.post("https://#{options[:notifo_api_username]}:#{options[:notifo_api_secret]}@api.notifo.com/v1/send_notification",
+ :body => { :to => username, :msg => message, :title => options[:notifo_title], :uri => options[:notifo_url] }.to_param)
+ Messenger::Result.new(success?(response), response)
+ end
- # URL format:
- # notifo://username
- #
- # Options:
- # :notifo_api_username => The service's API username
- # :notifo_api_secret => The service's API secret
- # :notifo_title => The notificaiton title
- # :notifo_url => Open this URL
- def self.send(url, message, options={})
- raise URLError, "The URL provided is invalid" unless valid_url?(url)
- username = matcher(url)
- response = HTTParty.post("https://api.notifo.com/v1/send_notification",
- :body => { :to => username, :msg => message, :title => options[:notifo_title], :uri => options[:notifo_url] },
- :basic_auth => { :username => options[:notifo_api_username], :password => options[:notifo_api_secret] })
- Result.new(success?(response), response)
- end
+ def self.obfuscate(url)
+ raise Messenger::URLError, "The URL provided is invalid" unless valid_url?(url)
+ url
+ end
- def self.obfuscate(url)
- raise URLError, "The URL provided is invalid" unless valid_url?(url)
- url
- end
+private
- private
+ def self.matcher(url)
+ url.match(/^notifo:\/\/(.+)/)[1]
+ end
- def self.matcher(url)
- url.match(/^notifo:\/\/(.+)/)[1]
- end
-
- def self.success?(response)
- response.code == 200
- end
-
+ def self.success?(response)
+ response.code == 200
end
end