Module: Pushover::User

Extended by:
User
Included in:
User
Defined in:
lib/pushover/user.rb

Overview

The user module, saves any user information provided.

Defined Under Namespace

Classes: User

Instance Method Summary collapse

Instance Method Details

#add(token, name) ⇒ Boolean

Add an application to the config file and save it.

Parameters:

  • token (String)

    is the token to be used.

  • name (String)

    is the short name that can be referenced later.

Returns:

  • (Boolean)

    return the results of the save attempt.



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

def add(token, name)
  User.new token, name
  Pushover::Config.save!
end

#current_userObject

Return the current user selected, or the first one saved.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/pushover/user.rb', line 42

def current_user
  return @current_user if @current_user

  # did something get supplied on the cli? try to find it.
  if Options[:user]
    @current_user = Pushover::User.find Options[:user]
  end

  # no?  do we have anything we can return?
  if !@current_user
    @current_user = Config[:users].first
  end
  @current_user
end

#current_user?Boolean

Will return true if it can find a user either via the cli or save file.

Returns:

  • (Boolean)


58
59
60
61
# File 'lib/pushover/user.rb', line 58

def current_user?
  return true if current_user
  return nil
end

#find(word) ⇒ String

Find the apikey in the applications, or pass on the word to try direct access.

Parameters:

  • word (String)

    the search token, can be an apikey or appname.

Returns:

  • (String)

    return the apikey (if it can find one) or the word itself.



27
28
29
30
# File 'lib/pushover/user.rb', line 27

def find(word)
  return Config[:users][word] if Config[:users][word]
  word
end