Class: Formkeep::Form
- Inherits:
-
Object
- Object
- Formkeep::Form
- Defined in:
- lib/formkeep.rb
Overview
Helper methods for accessing Formkeep API
Instance Attribute Summary collapse
-
#form ⇒ String
Name of Form to be used.
Getters collapse
-
#api ⇒ String
Sets API endpoint.
-
#config ⇒ Pstore
YAML::Store object.
-
#get_key(key) ⇒ String
Value of key.
-
#latest_email ⇒ String
Email of latest submission.
-
#latest_name ⇒ String
Name of latest submission.
-
#latest_submission ⇒ Hash
Latest submission info.
-
#response ⇒ String
Text of API call.
-
#set_key(key, value) ⇒ String
Value that was added/modified.
-
#submissions ⇒ Array
All submissions.
Parsers collapse
-
#read_submissions ⇒ Array
All read submissions.
-
#unread_submissions ⇒ Array
All unread submissions.
Process collapse
Instance Method Summary collapse
-
#initialize(form) ⇒ Formkeep::Form
constructor
Creates a Formkeep::Form object to make calling of other methods simpler.
Constructor Details
#initialize(form) ⇒ Formkeep::Form
Creates a Formkeep::Form object to make calling of other methods simpler.
24 25 26 |
# File 'lib/formkeep.rb', line 24 def initialize(form) @form = form end |
Instance Attribute Details
#form ⇒ String
Returns name of Form to be used.
18 19 20 |
# File 'lib/formkeep.rb', line 18 def form @form end |
Instance Method Details
#api ⇒ String
Sets API endpoint
59 60 61 |
# File 'lib/formkeep.rb', line 59 def api get_key(form) end |
#config ⇒ Pstore
Returns YAML::Store object.
31 32 33 |
# File 'lib/formkeep.rb', line 31 def config YAML::Store.new("#{Dir.home}/.formkeep.yaml") end |
#get_key(key) ⇒ String
Returns value of key.
38 39 40 41 42 43 |
# File 'lib/formkeep.rb', line 38 def get_key(key) store = config store.transaction do store[key] end end |
#latest_email ⇒ String
Returns email of latest submission.
91 92 93 |
# File 'lib/formkeep.rb', line 91 def latest_email latest_submission.fetch("email") end |
#latest_name ⇒ String
Returns name of latest submission.
85 86 87 |
# File 'lib/formkeep.rb', line 85 def latest_name latest_submission.fetch("name") end |
#latest_submission ⇒ Hash
Latest submission info
79 80 81 |
# File 'lib/formkeep.rb', line 79 def latest_submission submissions[0] end |
#read_submissions ⇒ Array
Returns all read submissions.
107 108 109 110 111 |
# File 'lib/formkeep.rb', line 107 def read_submissions submissions.select do |submission| submission.fetch("read_at") end end |
#response ⇒ String
Returns text of API call.
65 66 67 |
# File 'lib/formkeep.rb', line 65 def response Net::HTTP.get_response(URI(api)).body end |
#set_key(key, value) ⇒ String
Returns value that was added/modified.
49 50 51 52 53 54 |
# File 'lib/formkeep.rb', line 49 def set_key(key, value) store = config store.transaction do store[key] = value end end |
#sticky(text) ⇒ Object
115 116 117 |
# File 'lib/formkeep.rb', line 115 def sticky(text) StickyNotifications::Note.new.create(text) end |
#submissions ⇒ Array
Returns all submissions.
71 72 73 74 |
# File 'lib/formkeep.rb', line 71 def submissions all = JSON.parse(response)["submissions"] all.reject { |sub| sub["spam"] } end |
#unread_submissions ⇒ Array
Returns all unread submissions.
99 100 101 102 103 |
# File 'lib/formkeep.rb', line 99 def unread_submissions submissions.reject do |submission| submission.fetch("read_at") end end |