Module: Popcorn
- Defined in:
- lib/popcorn.rb,
lib/popcorn/version.rb,
lib/popcorn/configuration.rb
Defined Under Namespace
Classes: Configuration
Constant Summary collapse
- API_URL =
'https://popcornnotify.com'- VERSION =
"0.1.0"
Class Attribute Summary collapse
-
.configuration ⇒ Object
Returns the value of attribute configuration.
Class Method Summary collapse
Class Attribute Details
.configuration ⇒ Object
Returns the value of attribute configuration.
9 10 11 |
# File 'lib/popcorn.rb', line 9 def configuration @configuration end |
Class Method Details
.configure {|configuration| ... } ⇒ Object
12 13 14 15 |
# File 'lib/popcorn.rb', line 12 def self.configure self.configuration ||= Configuration.new yield(configuration) end |
.notify(recipients, message, opts = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/popcorn.rb', line 17 def self.notify(recipients, , opts = {}) self.configuration ||= Configuration.new # Setup Default Options = { subject: nil, verbose: false, api_key: self.configuration.api_key } = .merge(opts) # Create Faraday Client conn = Faraday.new(url: API_URL) do |f| f.request :url_encoded # Filter api_key from logs if verbose f.response :logger do |logger| logger.filter(/(api_key=)(\w+)/,'\1[FILTERED]') end if [:verbose] f.adapter Faraday.default_adapter end # Convert recipients to string if Array recipients = recipients.join(',') if recipients.is_a?(Array) # Initiate POST to /notify response = conn.post '/notify', { recipients: recipients.to_s, message: .to_s, subject: [:subject].to_s, api_key: [:api_key].to_s } # Return true or false response.success? end |