Class: Prowlr

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/prowlr.rb

Defined Under Namespace

Classes: ProwlrError

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(apikey) ⇒ Prowlr

Returns a new instance of Prowlr.



13
14
15
# File 'lib/prowlr.rb', line 13

def initialize(apikey)
  @apikey = apikey
end

Class Method Details

.add(options = {}) ⇒ Object



39
40
41
42
# File 'lib/prowlr.rb', line 39

def add(options={})
  options.merge!({:application => 'prowlr gem'}) unless options[:application]
  raise_errors(post('/add', :query => options)['prowl'])
end

.raise_errors(response) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/prowlr.rb', line 44

def raise_errors(response)
  unless error = response['error']
    response['success']
  else
    raise ProwlrError, error
  end
end

.remaining_calls(apikey) ⇒ Object



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

def remaining_calls(apikey)
  verify(apikey)['remaining'].to_i rescue nil
end

.reset_date(apikey) ⇒ Object



35
36
37
# File 'lib/prowlr.rb', line 35

def reset_date(apikey)
  Time.at(verify(apikey)['resetdate'].to_i) rescue nil
end

.valid_apikey?(apikey) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/prowlr.rb', line 27

def valid_apikey?(apikey)
  verify(apikey)['code'].to_i == 200 rescue false
end

.verify(apikey) ⇒ Object



23
24
25
# File 'lib/prowlr.rb', line 23

def verify(apikey)
  raise_errors(get('/verify', :query => {:apikey => apikey})['prowl'])
end

Instance Method Details

#add(options = {}) ⇒ Object



17
18
19
20
# File 'lib/prowlr.rb', line 17

def add(options={})
  options.merge!({:apikey => @apikey})
  self.class.add(options)
end