Class: Prowler::Application
- Inherits:
-
Object
- Object
- Prowler::Application
- Defined in:
- lib/prowler/application.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
:nodoc:.
-
#application ⇒ Object
:nodoc:.
-
#provider_key ⇒ Object
:nodoc:.
-
#send_notifications ⇒ Object
writeonly
:nodoc:.
-
#service_url ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#initialize(*args) ⇒ Application
constructor
Create an instance for sending to different accounts within a single Rails application Pass any of the following options to override the global configuration: * :application: The name of your application.
-
#notify(event, message, *args) ⇒ Object
Send a notification to your iPhone: * event: The title of notification you want to send.
-
#retrieve_api_key(token) ⇒ Object
Retrieve an API key for a user using the token provided by retrieve_token.
-
#retrieve_token ⇒ Object
Retrieve a registration token and confirmation url for the initial phase of fetching an API key for a user.
-
#verify(api_key = nil) ⇒ Object
Verify the configured API key is valid.
Constructor Details
#initialize(*args) ⇒ Application
Create an instance for sending to different accounts within a single Rails application Pass any of the following options to override the global configuration:
-
:application: The name of your application.
-
:provider_key: Key to override the rate limit of 1000 requests per hour.
-
:api_key: Your API key.
-
:service_url: Override the configured service url
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/prowler/application.rb', line 26 def initialize(*args) if args.empty? CONFIG_ATTRS.each{ |attr| send("#{attr}=".to_sym, Prowler.send(attr)) } elsif args.first.is_a?(Hash) CONFIG_ATTRS.each do |attr| send("#{attr}=".to_sym, args[0][attr] || Prowler.send(attr)) end else @service_url = Prowler.service_url @api_key, @application, @provider_key = args[0], args[1], args[2] end end |
Instance Attribute Details
#api_key ⇒ Object
:nodoc:
17 18 19 |
# File 'lib/prowler/application.rb', line 17 def api_key @api_key end |
#application ⇒ Object
:nodoc:
18 19 20 |
# File 'lib/prowler/application.rb', line 18 def application @application end |
#provider_key ⇒ Object
:nodoc:
17 18 19 |
# File 'lib/prowler/application.rb', line 17 def provider_key @provider_key end |
#send_notifications=(value) ⇒ Object
:nodoc:
18 19 20 |
# File 'lib/prowler/application.rb', line 18 def send_notifications=(value) @send_notifications = value end |
#service_url ⇒ Object
:nodoc:
17 18 19 |
# File 'lib/prowler/application.rb', line 17 def service_url @service_url end |
Instance Method Details
#notify(event, message, *args) ⇒ Object
Send a notification to your iPhone:
-
event: The title of notification you want to send.
-
message: The text of the notification message you want to send.
-
api_key: One or more API keys to be notified - uses the configured key(s) if not provided.
The following options are supported:
-
:delayed: Whether to use Delayed::Job to send notifications.
-
:priority: The priority of the notification - see Prowler::Priority.
-
:url: A custom url for the Prowl application to open.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/prowler/application.rb', line 48 def notify(event, , *args) api_key = args.first.is_a?(String) || args.first.is_a?(Array) ? args.shift : self.api_key raise ConfigurationError, "You must provide an API key to send notifications" if api_key.nil? raise ConfigurationError, "You must provide an application name to send notifications" if application.nil? if args.first.is_a?(Fixnum) = { :priority => args.shift, :delayed => args.shift || Prowler.delayed } else = args.last.is_a?(Hash) ? args.pop : {} = { :priority => Prowler::Priority::NORMAL, :delayed => Prowler.delayed }.merge() end .merge!( :application => application, :providerkey => provider_key, :apikey => api_key, :event => event, :description => ) if .delete(:delayed) enqueue_delayed_job() else perform(:add, , :post, Success) end end |
#retrieve_api_key(token) ⇒ Object
Retrieve an API key for a user using the token provided by retrieve_token. This API command requires the provider_key to be configured.
-
token: Token returned by retrieve_token command.
Returns either Prowler::ApiKey object if successful or nil if an error occurs.
94 95 96 97 |
# File 'lib/prowler/application.rb', line 94 def retrieve_api_key(token) raise ConfigurationError, "You must have a provider key to retrieve API keys" if provider_key.nil? perform("retrieve/apikey", { :providerkey => provider_key, :token => token }, :get, ApiKey) end |
#retrieve_token ⇒ Object
Retrieve a registration token and confirmation url for the initial phase of fetching an API key for a user. The token is valid for 24 hours. This API command requires the provider_key to be configured.
Returns either Prowler::Token object if successful or nil if an error occurs.
84 85 86 87 |
# File 'lib/prowler/application.rb', line 84 def retrieve_token raise ConfigurationError, "You must have a provider key to retrieve API keys" if provider_key.nil? perform("retrieve/token", { :providerkey => provider_key }, :get, Token) end |
#verify(api_key = nil) ⇒ Object
Verify the configured API key is valid
74 75 76 77 |
# File 'lib/prowler/application.rb', line 74 def verify(api_key = nil) raise ConfigurationError, "You must provide an API key to verify" if api_key.nil? && self.api_key.nil? perform(:verify, { :providerkey => provider_key, :apikey => api_key || self.api_key }, :get, Success) end |