formkeep 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -4
- data/bin/formkeep +13 -6
- data/lib/formkeep.rb +25 -6
- data/lib/formkeep/version.rb +2 -1
- data/spec/formkeep_spec.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3546579edb5c82ebe4f71cfe320a1fa8d99cf849
|
4
|
+
data.tar.gz: 3c88d322497c57aa0e5b6c5393bb0af15a1dc53a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9964cf22048441282f6c3bf192f2bba58aa5cc6aaf9164a99b1c45217466d46f23ba3004aee9d91577436b67f2e7f9b9a35b636a24bc5fe5f505b11cb4699dd7
|
7
|
+
data.tar.gz: 64946daf0ab1a3d931288233d2abab29ef06c67245436f6aeef29c0d74452aec19c62943bc2d4e1dcd9d1e80c04f8bcce3021a41099714301d2eca0c97c9b642
|
data/README.md
CHANGED
@@ -24,8 +24,7 @@ Or install it yourself as:
|
|
24
24
|
|
25
25
|
It should look something like this:
|
26
26
|
|
27
|
-
~~~
|
28
|
-
---
|
27
|
+
~~~
|
29
28
|
form_name: api_endpoint_url_in_full
|
30
29
|
~~~
|
31
30
|
|
@@ -33,8 +32,7 @@ You can have as many form entries as you like. They don't necessarily need to be
|
|
33
32
|
|
34
33
|
## Usage
|
35
34
|
|
36
|
-
~~~
|
37
|
-
# Check for unread submissions
|
35
|
+
~~~
|
38
36
|
formkeep check FORM
|
39
37
|
~~~
|
40
38
|
|
data/bin/formkeep
CHANGED
@@ -5,17 +5,24 @@ require 'slop'
|
|
5
5
|
|
6
6
|
opts = Slop.parse do
|
7
7
|
banner "Usage: formkeep check FORM"
|
8
|
-
on :
|
8
|
+
on :h, :help, "Display help"
|
9
|
+
on :v, :version, "Display version" do
|
9
10
|
puts Formkeep::VERSION
|
11
|
+
exit
|
10
12
|
end
|
11
13
|
|
12
14
|
command 'check' do
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
banner <<-EOF
|
16
|
+
Usage: formkeep check FORM
|
17
|
+
|
18
|
+
Please make sure you have a valid Formkeep API endpoint saved in ~/.formkeep.yaml
|
19
|
+
EOF
|
20
|
+
run do |opts, args|
|
21
|
+
unless args.empty?
|
22
|
+
form = Formkeep::Form.new(args[0])
|
23
|
+
puts form.unread_submissions.length
|
17
24
|
else
|
18
|
-
puts
|
25
|
+
puts opts
|
19
26
|
end
|
20
27
|
end
|
21
28
|
end
|
data/lib/formkeep.rb
CHANGED
@@ -5,20 +5,31 @@ require 'net/http'
|
|
5
5
|
require 'yaml/store'
|
6
6
|
|
7
7
|
# @author Brandon Pittman
|
8
|
+
# Helper methods for accessing Formkeep API
|
8
9
|
module Formkeep
|
9
|
-
|
10
|
+
# @author Brandon Pittman
|
11
|
+
# Helper methods for accessing Formkeep API
|
12
|
+
class Form
|
10
13
|
|
14
|
+
# @!attribute form
|
15
|
+
# @return [String] name of Form to be used
|
11
16
|
attr_accessor :form
|
12
17
|
|
18
|
+
# Creates a Formkeep::Form object to make calling of other methods simpler.
|
19
|
+
# @param [String] form name from `~/.formkeep.yaml`
|
20
|
+
# @return [Formkeep::Form] Form object
|
13
21
|
def initialize(form)
|
14
22
|
@form = form
|
15
23
|
end
|
16
24
|
|
17
25
|
# @!group Getters
|
26
|
+
# @return [Pstore] YAML::Store object
|
18
27
|
def config
|
19
28
|
YAML::Store.new("#{Dir.home}/.formkeep.yaml")
|
20
29
|
end
|
21
30
|
|
31
|
+
# @param [String] key to look up
|
32
|
+
# @return [String] value of key
|
22
33
|
def get_key(key)
|
23
34
|
store = config
|
24
35
|
store.transaction do
|
@@ -26,6 +37,9 @@ module Formkeep
|
|
26
37
|
end
|
27
38
|
end
|
28
39
|
|
40
|
+
# @param [String] key to add/modify
|
41
|
+
# @param [String] value to add/modify
|
42
|
+
# @return [String] value that was added/modified
|
29
43
|
def set_key(key, value)
|
30
44
|
store = config
|
31
45
|
store.transaction do
|
@@ -34,39 +48,48 @@ module Formkeep
|
|
34
48
|
end
|
35
49
|
|
36
50
|
# Sets API endpoint
|
51
|
+
# @return [String] API endpoint URL
|
37
52
|
def api
|
38
53
|
get_key(form)
|
39
54
|
end
|
40
55
|
|
56
|
+
# @return [String] text of API call
|
41
57
|
def response
|
42
58
|
Net::HTTP.get_response(URI(api)).body
|
43
59
|
end
|
44
60
|
|
61
|
+
# @return [Array] all submissions
|
45
62
|
def submissions
|
46
|
-
JSON.parse(response)["submissions"]
|
63
|
+
all = JSON.parse(response)["submissions"]
|
64
|
+
all.reject { |sub| sub["spam"] }
|
47
65
|
end
|
48
66
|
|
49
67
|
# Latest submission info
|
68
|
+
# @return [Hash] first submission from submissions array
|
50
69
|
def latest_submission
|
51
70
|
submissions[0]
|
52
71
|
end
|
53
72
|
|
73
|
+
# @return [String] name of latest submission
|
54
74
|
def latest_name
|
55
75
|
latest_submission.fetch("name")
|
56
76
|
end
|
57
77
|
|
78
|
+
# @return [String] email of latest submission
|
58
79
|
def latest_email
|
59
80
|
latest_submission.fetch("email")
|
60
81
|
end
|
61
82
|
# @!endgroup
|
62
83
|
|
63
84
|
# @!group Parsers
|
85
|
+
# @return [Array] all unread submissions
|
64
86
|
def unread_submissions
|
65
87
|
submissions.reject do |submission|
|
66
88
|
submission.fetch("read_at")
|
67
89
|
end
|
68
90
|
end
|
69
91
|
|
92
|
+
# @return [Array] all read submissions
|
70
93
|
def read_submissions
|
71
94
|
submissions.select do |submission|
|
72
95
|
submission.fetch("read_at")
|
@@ -75,7 +98,3 @@ module Formkeep
|
|
75
98
|
# @!endgroup
|
76
99
|
end
|
77
100
|
end
|
78
|
-
|
79
|
-
form = Formkeep::Cli.new("pixelsnatch")
|
80
|
-
form.latest_submission.class # => Hash
|
81
|
-
form.submissions.class # => Array
|
data/lib/formkeep/version.rb
CHANGED
data/spec/formkeep_spec.rb
CHANGED
@@ -2,8 +2,8 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Formkeep do
|
4
4
|
|
5
|
-
let(:test) {Formkeep::
|
6
|
-
let(:pixelsnatch) {Formkeep::
|
5
|
+
let(:test) {Formkeep::Form.new("test")}
|
6
|
+
let(:pixelsnatch) {Formkeep::Form.new("pixelsnatch")}
|
7
7
|
|
8
8
|
it 'has a version number' do
|
9
9
|
expect(Formkeep::VERSION).not_to be nil
|