Class: Prowler::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/prowler/application.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_keyObject

:nodoc:



17
18
19
# File 'lib/prowler/application.rb', line 17

def api_key
  @api_key
end

#applicationObject

:nodoc:



18
19
20
# File 'lib/prowler/application.rb', line 18

def application
  @application
end

#provider_keyObject

: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_urlObject

: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.

Raises:



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, message, *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)
    options = { :priority => args.shift, :delayed => args.shift || Prowler.delayed }
  else
    options = args.last.is_a?(Hash) ? args.pop : {}
    options = { :priority => Prowler::Priority::NORMAL, :delayed => Prowler.delayed }.merge(options)
  end

  options.merge!(
    :application => application, :providerkey => provider_key,
    :apikey => api_key, :event => event, :description => message
  )

  if options.delete(:delayed)
    enqueue_delayed_job(options)
  else
    perform(:add, options, :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.

Raises:



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_tokenObject

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.

Raises:



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

Raises:



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