Class: Send2MacClient::Runner

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRunner

Returns a new instance of Runner.



10
11
12
13
14
# File 'lib/send2mac/runner.rb', line 10

def initialize
  File.file?(config_path) ? @config = YAML.load_file(config_path) : setup_api_key
  $api_key = @config[:api_key]
  @client = Listener.new
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



8
9
10
# File 'lib/send2mac/runner.rb', line 8

def client
  @client
end

Instance Method Details

#config_pathObject



16
17
18
# File 'lib/send2mac/runner.rb', line 16

def config_path
  File.expand_path("#{ENV['HOME']}/.send2mac", __FILE__)
end

#runObject



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

def run
  client.listen
end

#setup_api_keyObject



20
21
22
23
24
25
26
27
28
29
# File 'lib/send2mac/runner.rb', line 20

def setup_api_key
  say("\nPlease enter your Send2Mac API Key")
  puts ""
  key    = ask("API Key:   ")
  this = {api_key: key.to_s}
  File.open(config_path, "w") do |f|
    f.write(this.to_yaml)
  end
  @config = YAML.load_file(config_path)
end