Module: Pushover::App

Extended by:
App
Included in:
App
Defined in:
lib/pushover/app.rb

Overview

Stores a application definition in the config file.

Defined Under Namespace

Classes: App

Instance Method Summary collapse

Instance Method Details

#add(api_key, name) ⇒ Boolean

Add an application to the config file and save it.

Parameters:

  • api_key (String)

    is the api_key to be used.

  • name (String)

    is the short name that can be referenced later.

Returns:

  • (Boolean)

    return the results of the save attempt.



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

def add(api_key, name)
	App.new api_key, name
	Pushover::Config.save!
end

#current_appObject

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



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/pushover/app.rb', line 45

def current_app
	return @current_app if @current_app

	# did something get supplied on the cli? try to find it.
	if Options[:appkey]
		@current_app = Pushover::App.find Options[:appkey]
	end

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

#current_app?Boolean

Will return true if we can find an application either via the cli or save file.

Returns:

  • (Boolean)


61
62
63
64
# File 'lib/pushover/app.rb', line 61

def current_app?
	return true if current_app
	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.



30
31
32
33
# File 'lib/pushover/app.rb', line 30

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