Class: FastProwl

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

Overview

Create a FastProwl instance and iPhone-spam away via Prowl! ;-)

Defined Under Namespace

Classes: MissingAPIKey, PriorityOutOfRange, TooManyAPIKeys

Constant Summary collapse

API_URL =
'https://prowlapp.com/publicapi/'
PRIORITY_RANGE =
-2..2
USER_AGENT =

You can change this using the user_agent() method

'FastProwl 0.3.1 (http://github.com/tofumatt/FastProwl)'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(defaults = {}, hydra = {}) ⇒ FastProwl

Supply Prowl defaults in a hash (:apikey, :providerkey, etc.), along with optional Typhoeus Hydra options.



18
19
20
21
22
23
# File 'lib/fastprowl.rb', line 18

def initialize(defaults = {}, hydra = {})
  @defaults = defaults
  @responses = []
  @hydra = Typhoeus::Hydra.new(hydra)
  @user_agent = USER_AGENT
end

Class Method Details

.add(params = {}) ⇒ Object

Send a single Prowl notification immediately.



52
53
54
55
56
# File 'lib/fastprowl.rb', line 52

def self.add(params = {})
  prowl = new
  prowl.add(params)
  prowl.run
end

.verify(apikey) ⇒ Object

Verify a Prowl API key immediately. Returns true if the key is valid; false otherwise.



60
61
62
63
64
# File 'lib/fastprowl.rb', line 60

def self.verify(apikey)
  prowl = new(:apikey => apikey)
  prowl.valid?
  prowl.run
end

Instance Method Details

#add(params = {}) ⇒ Object

Queue a notification request in the Hydra.



26
27
28
# File 'lib/fastprowl.rb', line 26

def add(params = {})
  @hydra.queue(request('add', params))
end

#defaults(params) ⇒ Object

Modify this instance’s defaults



31
32
33
# File 'lib/fastprowl.rb', line 31

def defaults(params)
  @defaults = @defaults.merge(params)
end

#runObject

Run all queued Hydra requests.



36
37
38
39
# File 'lib/fastprowl.rb', line 36

def run
  @hydra.run
  status
end

#user_agent(user_agent) ⇒ Object

Change the user-agent sent to the Prowl server.



42
43
44
# File 'lib/fastprowl.rb', line 42

def user_agent(user_agent)
  @user_agent = user_agent
end

#valid?Boolean

Queue a verify API call in the Hydra.

Returns:

  • (Boolean)


47
48
49
# File 'lib/fastprowl.rb', line 47

def valid?
  @hydra.queue(request('verify'))
end