Class: Prowler
- Inherits:
-
Object
- Object
- Prowler
- Defined in:
- lib/prowler.rb
Defined Under Namespace
Modules: Priority Classes: ConfigurationError, DelayedJob
Constant Summary collapse
- SERVICE_URL =
"https://prowl.weks.net/publicapi"
- USER_AGENT =
"Prowler/1.1.1"
- MULTIPLE_APIKEY_COMMANDS =
%w(add)
Class Attribute Summary collapse
-
.api_key ⇒ Object
Returns the value of attribute api_key.
-
.application ⇒ Object
Returns the value of attribute application.
-
.delayed ⇒ Object
:nodoc:.
-
.open_timeout ⇒ Object
:nodoc:.
-
.provider_key ⇒ Object
Returns the value of attribute provider_key.
-
.read_timeout ⇒ Object
:nodoc:.
-
.root_certificates ⇒ Object
Location of the root certificates file.
-
.send_notifications ⇒ Object
:nodoc:.
-
.verify_certificate ⇒ Object
Returns the value of attribute verify_certificate.
Instance Attribute Summary collapse
-
#api_key ⇒ Object
:nodoc:.
-
#application ⇒ Object
:nodoc:.
-
#provider_key ⇒ Object
:nodoc:.
-
#send_notifications ⇒ Object
:nodoc:.
Class Method Summary collapse
-
.configure {|_self| ... } ⇒ Object
Call this method to configure your account details in an initializer.
-
.configured? ⇒ Boolean
Whether the library has been configured.
-
.enqueue_delayed_job(config, event, message, priority) ⇒ Object
:nodoc:.
-
.logger ⇒ Object
Returns the default logger or a logger that prints to STDOUT.
-
.notify(event, message, priority = Priority::NORMAL, delayed = self.delayed) ⇒ Object
Send a notification to your iPhone: * event: The title of notification you want to send.
-
.perform(command, api_key, provider_key, data = {}, method = :post) ⇒ Object
:nodoc:.
-
.reset_configuration ⇒ Object
Reset configuration.
-
.verify ⇒ Object
Verify the configured API key is valid.
-
.verify_certificate? ⇒ Boolean
Whether to verify the server’s SSL certificate.
Instance Method Summary collapse
-
#initialize(api_key, application, provider_key = nil) ⇒ Prowler
constructor
Create an instance for sending to different accounts within a single Rails application * api_key: Your API key.
-
#notify(event, message, priority = Priority::NORMAL, delayed = self.class.delayed) ⇒ Object
Send a notification to your iPhone: * event: The title of notification you want to send.
-
#verify ⇒ Object
Verify the configured API key is valid.
Constructor Details
#initialize(api_key, application, provider_key = nil) ⇒ Prowler
Create an instance for sending to different accounts within a single Rails application
-
api_key: Your API key.
-
application: The name of your application.
-
provider_key: Key to override the rate limit of 1000 requests per hour. (Optional)
264 265 266 |
# File 'lib/prowler.rb', line 264 def initialize(api_key, application, provider_key = nil) @api_key, @application, @provider_key = api_key, application, provider_key end |
Class Attribute Details
.api_key ⇒ Object
Returns the value of attribute api_key.
94 95 96 |
# File 'lib/prowler.rb', line 94 def api_key @api_key end |
.application ⇒ Object
Returns the value of attribute application.
95 96 97 |
# File 'lib/prowler.rb', line 95 def application @application end |
.delayed ⇒ Object
:nodoc:
108 109 110 |
# File 'lib/prowler.rb', line 108 def delayed @delayed end |
.open_timeout ⇒ Object
:nodoc:
96 97 98 |
# File 'lib/prowler.rb', line 96 def open_timeout @open_timeout end |
.provider_key ⇒ Object
Returns the value of attribute provider_key.
94 95 96 |
# File 'lib/prowler.rb', line 94 def provider_key @provider_key end |
.read_timeout ⇒ Object
:nodoc:
96 97 98 |
# File 'lib/prowler.rb', line 96 def read_timeout @read_timeout end |
.root_certificates ⇒ Object
Location of the root certificates file. Default: RAILS_ROOT/config/cacert.pem
130 131 132 |
# File 'lib/prowler.rb', line 130 def root_certificates @root_certificates end |
.send_notifications ⇒ Object
:nodoc:
104 105 106 |
# File 'lib/prowler.rb', line 104 def send_notifications @send_notifications end |
.verify_certificate ⇒ Object
Returns the value of attribute verify_certificate.
97 98 99 |
# File 'lib/prowler.rb', line 97 def verify_certificate @verify_certificate end |
Instance Attribute Details
#api_key ⇒ Object
:nodoc:
257 258 259 |
# File 'lib/prowler.rb', line 257 def api_key @api_key end |
#application ⇒ Object
:nodoc:
258 259 260 |
# File 'lib/prowler.rb', line 258 def application @application end |
#provider_key ⇒ Object
:nodoc:
257 258 259 |
# File 'lib/prowler.rb', line 257 def provider_key @provider_key end |
#send_notifications ⇒ Object
:nodoc:
258 259 260 |
# File 'lib/prowler.rb', line 258 def send_notifications @send_notifications end |
Class Method Details
.configure {|_self| ... } ⇒ Object
Call this method to configure your account details in an initializer.
100 101 102 |
# File 'lib/prowler.rb', line 100 def configure yield self end |
.configured? ⇒ Boolean
Whether the library has been configured
119 120 121 |
# File 'lib/prowler.rb', line 119 def configured? !@application.nil? && !@api_key.nil? end |
.enqueue_delayed_job(config, event, message, priority) ⇒ Object
:nodoc:
188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/prowler.rb', line 188 def enqueue_delayed_job(config, event, , priority) #:nodoc: record = Delayed::Job.enqueue(DelayedJob.new do |job| job.api_key = config.api_key job.provider_key = config.provider_key job.application = config.application job.event = event job. = job.priority = priority end) !record.new_record? end |
.logger ⇒ Object
Returns the default logger or a logger that prints to STDOUT.
135 136 137 138 139 |
# File 'lib/prowler.rb', line 135 def logger ActiveRecord::Base.logger rescue @logger ||= Logger.new(STDERR) end |
.notify(event, message, priority = Priority::NORMAL, delayed = self.delayed) ⇒ 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.
-
priority: The priority of the notification - see Prowler::Priority. (Optional)
-
delayed: Whether to use Delayed::Job to send notifications. (Optional)
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/prowler.rb', line 154 def notify(event, , priority = Priority::NORMAL, delayed = self.delayed) 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 delayed enqueue_delayed_job(self, event, , priority) else perform( :add, api_key, provider_key, { :application => application, :event => event, :description => , :priority => priority } ) end end |
.perform(command, api_key, provider_key, data = {}, method = :post) ⇒ Object
:nodoc:
178 179 180 181 182 183 184 185 186 |
# File 'lib/prowler.rb', line 178 def perform(command, api_key, provider_key, data = {}, method = :post) #:nodoc: params = { :apikey => format_api_key(command, api_key), :provider_key => provider_key }.merge(data).delete_if { |k,v| v.nil? } case method when :post perform_post(command, params) else perform_get(command, params) end end |
.reset_configuration ⇒ Object
Reset configuration
113 114 115 116 |
# File 'lib/prowler.rb', line 113 def reset_configuration @application = @api_key = @provider_key = nil @delayed = @verify_certificate = @root_certificates = nil end |
.verify ⇒ Object
Verify the configured API key is valid
173 174 175 176 |
# File 'lib/prowler.rb', line 173 def verify raise ConfigurationError, "You must provide an API key to verify" if api_key.nil? perform(:verify, api_key, provider_key, {}, :get) end |
.verify_certificate? ⇒ Boolean
Whether to verify the server’s SSL certificate
124 125 126 |
# File 'lib/prowler.rb', line 124 def verify_certificate? @verify_certificate ||= false end |
Instance Method Details
#notify(event, message, priority = Priority::NORMAL, delayed = self.class.delayed) ⇒ 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.
-
priority: The priority of the notification - see Prowler::Priority. (Optional)
-
delayed: Whether to use Delayed::Job to send notifications. (Optional)
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
# File 'lib/prowler.rb', line 273 def notify(event, , priority = Priority::NORMAL, delayed = self.class.delayed) 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 delayed self.class.enqueue_delayed_job(self, event, , priority) else self.class.perform( :add, api_key, provider_key, { :application => application, :event => event, :description => , :priority => priority } ) end end |
#verify ⇒ Object
Verify the configured API key is valid
292 293 294 295 |
# File 'lib/prowler.rb', line 292 def verify raise ConfigurationError, "You must provide an API key to verify" if api_key.nil? self.class.perform(:verify, api_key, provider_key, {}, :get) end |