Class: Formkeep::Cli

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

Instance Attribute Summary collapse

Getters collapse

Parsers collapse

Instance Method Summary collapse

Constructor Details

#initialize(form) ⇒ Cli

Returns a new instance of Cli.



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

def initialize(form)
  @form = form
end

Instance Attribute Details

#formObject

Returns the value of attribute form.



11
12
13
# File 'lib/formkeep.rb', line 11

def form
  @form
end

Instance Method Details

#apiObject

Sets API endpoint



37
38
39
# File 'lib/formkeep.rb', line 37

def api
  get_key(form)
end

#configObject



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

def config
  YAML::Store.new("#{Dir.home}/.formkeep.yaml")
end

#get_key(key) ⇒ Object



22
23
24
25
26
27
# File 'lib/formkeep.rb', line 22

def get_key(key)
  store = config
  store.transaction do
    store[key]
  end
end

#latest_emailObject



58
59
60
# File 'lib/formkeep.rb', line 58

def latest_email
  latest_submission.fetch("email")
end

#latest_nameObject



54
55
56
# File 'lib/formkeep.rb', line 54

def latest_name
  latest_submission.fetch("name")
end

#latest_submissionObject

Latest submission info



50
51
52
# File 'lib/formkeep.rb', line 50

def latest_submission
  submissions[0]
end

#read_submissionsObject



70
71
72
73
74
# File 'lib/formkeep.rb', line 70

def read_submissions
  submissions.select do |submission|
    submission.fetch("read_at")
  end
end

#responseObject



41
42
43
# File 'lib/formkeep.rb', line 41

def response
  Net::HTTP.get_response(URI(api)).body
end

#set_key(key, value) ⇒ Object



29
30
31
32
33
34
# File 'lib/formkeep.rb', line 29

def set_key(key, value)
  store = config
  store.transaction do
    store[key] = value
  end
end

#submissionsObject



45
46
47
# File 'lib/formkeep.rb', line 45

def submissions
  JSON.parse(response)["submissions"]
end

#unread_submissionsObject



64
65
66
67
68
# File 'lib/formkeep.rb', line 64

def unread_submissions
  submissions.reject do |submission|
    submission.fetch("read_at")
  end
end