Class: Formkeep::Cli
- Inherits:
-
Object
- Object
- Formkeep::Cli
- Defined in:
- lib/formkeep.rb
Instance Attribute Summary collapse
-
#form ⇒ Object
Returns the value of attribute form.
Getters collapse
-
#api ⇒ Object
Sets API endpoint.
- #config ⇒ Object
- #get_key(key) ⇒ Object
- #latest_email ⇒ Object
- #latest_name ⇒ Object
-
#latest_submission ⇒ Object
Latest submission info.
- #response ⇒ Object
- #set_key(key, value) ⇒ Object
- #submissions ⇒ Object
Parsers collapse
Instance Method Summary collapse
-
#initialize(form) ⇒ Cli
constructor
A new instance of Cli.
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
#form ⇒ Object
Returns the value of attribute form.
11 12 13 |
# File 'lib/formkeep.rb', line 11 def form @form end |
Instance Method Details
#api ⇒ Object
Sets API endpoint
37 38 39 |
# File 'lib/formkeep.rb', line 37 def api get_key(form) end |
#config ⇒ Object
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_email ⇒ Object
58 59 60 |
# File 'lib/formkeep.rb', line 58 def latest_email latest_submission.fetch("email") end |
#latest_name ⇒ Object
54 55 56 |
# File 'lib/formkeep.rb', line 54 def latest_name latest_submission.fetch("name") end |
#latest_submission ⇒ Object
Latest submission info
50 51 52 |
# File 'lib/formkeep.rb', line 50 def latest_submission submissions[0] end |
#read_submissions ⇒ Object
70 71 72 73 74 |
# File 'lib/formkeep.rb', line 70 def read_submissions submissions.select do |submission| submission.fetch("read_at") end end |
#response ⇒ Object
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 |
#submissions ⇒ Object
45 46 47 |
# File 'lib/formkeep.rb', line 45 def submissions JSON.parse(response)["submissions"] end |
#unread_submissions ⇒ Object
64 65 66 67 68 |
# File 'lib/formkeep.rb', line 64 def unread_submissions submissions.reject do |submission| submission.fetch("read_at") end end |