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.
23 24 25 |
# File 'lib/formkeep.rb', line 23 def initialize(form) @form = form end |
Instance Attribute Details
#form ⇒ String
17 18 19 |
# File 'lib/formkeep.rb', line 17 def form @form end |
Instance Method Details
#api ⇒ String
Sets API endpoint
58 59 60 |
# File 'lib/formkeep.rb', line 58 def api get_key(form) end |
#config ⇒ Pstore
Returns YAML::Store object.
30 31 32 |
# File 'lib/formkeep.rb', line 30 def config YAML::Store.new("#{Dir.home}/.formkeep.yaml") end |
#get_key(key) ⇒ String
Returns value of key.
37 38 39 40 41 42 |
# File 'lib/formkeep.rb', line 37 def get_key(key) store = config store.transaction do store[key] end end |
#latest_email ⇒ String
Returns email of latest submission.
90 91 92 |
# File 'lib/formkeep.rb', line 90 def latest_email latest_submission.fetch('email') end |
#latest_name ⇒ String
Returns name of latest submission.
84 85 86 |
# File 'lib/formkeep.rb', line 84 def latest_name latest_submission.fetch('name') end |
#latest_submission ⇒ Hash
Latest submission info
78 79 80 |
# File 'lib/formkeep.rb', line 78 def latest_submission submissions[0] end |
#read_submissions ⇒ Array
Returns all read submissions.
106 107 108 109 110 |
# File 'lib/formkeep.rb', line 106 def read_submissions submissions.select do |submission| submission.fetch('read_at') end end |
#response ⇒ String
Returns text of API call.
64 65 66 |
# File 'lib/formkeep.rb', line 64 def response Net::HTTP.get_response(URI(api)).body end |
#set_key(key, value) ⇒ String
Returns value that was added/modified.
48 49 50 51 52 53 |
# File 'lib/formkeep.rb', line 48 def set_key(key, value) store = config store.transaction do store[key] = value end end |
#sticky(text) ⇒ Nil
This requires the OS X app, Sticky Notifications.
118 119 120 |
# File 'lib/formkeep.rb', line 118 def sticky(text) StickyNotifications::Note.new.create(text, 'Formkeep') end |
#submissions ⇒ Array
Returns all submissions.
70 71 72 73 |
# File 'lib/formkeep.rb', line 70 def submissions all = JSON.parse(response)['submissions'] all.reject { |sub| sub['spam'] } end |
#unread_submissions ⇒ Array
Returns all unread submissions.
98 99 100 101 102 |
# File 'lib/formkeep.rb', line 98 def unread_submissions submissions.reject do |submission| submission.fetch('read_at') end end |