Class: MorningPages::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/morning-pages/config.rb

Instance Method Summary collapse

Constructor Details

#initialize(config_path, server) ⇒ Config

Returns a new instance of Config.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/morning-pages/config.rb', line 6

def initialize(config_path, server)
  @config_path = config_path
  @server = server
  containing_folder = File.dirname(config_path)

  unless (File.exists?(containing_folder))
    FileUtils.mkdir_p(containing_folder)
  end

  @config = {}
  if (File.exists?(@config_path))
    @config = YAML.load(File.read(@config_path))
  end
end

Instance Method Details

#post_stats!(params) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/morning-pages/config.rb', line 35

def post_stats!(params)
  response = HTTParty.post("#{@server}/stats", :body => params.merge(:key => @config[:key]))
  return false if response.code != 200
  true
rescue Timeout::Error
  return false
end

#register!(params) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/morning-pages/config.rb', line 25

def register!(params)
  response = HTTParty.post("#{@server}/register", :body => params)
  return false if response.code != 200
  save(params.merge(:key => response.fetch("key")))
  write!
  true
rescue Timeout::Error
  return false
end

#registered?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/morning-pages/config.rb', line 21

def registered?
  @config.include? :username
end