formkeep 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +3 -3
- data/bin/formkeep +4 -4
- data/lib/formkeep.rb +13 -0
- data/lib/formkeep/version.rb +1 -1
- data/spec/formkeep_spec.rb +3 -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: 39010b85dae02b735ece32fba20d702fd3da5f76
|
|
4
|
+
data.tar.gz: 8780c7d4e51078f7ab0a079a3815c5b3feafbcbd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e272a06f95e4b4d6c9b751ca0f3b78a8ca64f64d152e8194f3a424dd37eb3acee2b5d7f1ef5255d2cb4157e8d5d64719f782c3ac0ac24c70d4a36cb3f981fbaf
|
|
7
|
+
data.tar.gz: 894ca58ff3ab786fe8d4a1d723ef1cbc2cd1311b64a432602d7d7778af152f026791c9db2d370aaa645a145fcd95afcd875355906d8e941d49ee3faeb2067b66
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -24,7 +24,7 @@ Or install it yourself as:
|
|
|
24
24
|
|
|
25
25
|
It should look something like this:
|
|
26
26
|
|
|
27
|
-
~~~
|
|
27
|
+
~~~rb
|
|
28
28
|
form_name: api_endpoint_url_in_full
|
|
29
29
|
~~~
|
|
30
30
|
|
|
@@ -32,8 +32,8 @@ You can have as many form entries as you like. They don't necessarily need to be
|
|
|
32
32
|
|
|
33
33
|
## Usage
|
|
34
34
|
|
|
35
|
-
~~~
|
|
36
|
-
formkeep
|
|
35
|
+
~~~rb
|
|
36
|
+
formkeep unread FORM
|
|
37
37
|
~~~
|
|
38
38
|
|
|
39
39
|
## Contributing
|
data/bin/formkeep
CHANGED
|
@@ -4,16 +4,16 @@ require 'formkeep'
|
|
|
4
4
|
require 'slop'
|
|
5
5
|
|
|
6
6
|
opts = Slop.parse do
|
|
7
|
-
banner "Usage: formkeep
|
|
7
|
+
banner "Usage: formkeep unread FORM"
|
|
8
8
|
on :h, :help, "Display help"
|
|
9
9
|
on :v, :version, "Display version" do
|
|
10
10
|
puts Formkeep::VERSION
|
|
11
11
|
exit
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
-
command '
|
|
14
|
+
command 'unread' do
|
|
15
15
|
banner <<-EOF
|
|
16
|
-
Usage: formkeep
|
|
16
|
+
Usage: formkeep unread FORM
|
|
17
17
|
|
|
18
18
|
Please make sure you have a valid Formkeep API endpoint saved in ~/.formkeep.yaml
|
|
19
19
|
EOF
|
|
@@ -28,4 +28,4 @@ opts = Slop.parse do
|
|
|
28
28
|
end
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
-
puts opts unless ARGV[0] == '
|
|
31
|
+
puts opts unless ARGV[0] == 'unread'
|
data/lib/formkeep.rb
CHANGED
|
@@ -13,23 +13,27 @@ module Formkeep
|
|
|
13
13
|
|
|
14
14
|
# @!attribute form
|
|
15
15
|
# @return [String] name of Form to be used
|
|
16
|
+
# @since 0.0.4
|
|
16
17
|
attr_accessor :form
|
|
17
18
|
|
|
18
19
|
# Creates a Formkeep::Form object to make calling of other methods simpler.
|
|
19
20
|
# @param [String] form name from `~/.formkeep.yaml`
|
|
20
21
|
# @return [Formkeep::Form] Form object
|
|
22
|
+
# @since 0.0.4
|
|
21
23
|
def initialize(form)
|
|
22
24
|
@form = form
|
|
23
25
|
end
|
|
24
26
|
|
|
25
27
|
# @!group Getters
|
|
26
28
|
# @return [Pstore] YAML::Store object
|
|
29
|
+
# @since 0.0.4
|
|
27
30
|
def config
|
|
28
31
|
YAML::Store.new("#{Dir.home}/.formkeep.yaml")
|
|
29
32
|
end
|
|
30
33
|
|
|
31
34
|
# @param [String] key to look up
|
|
32
35
|
# @return [String] value of key
|
|
36
|
+
# @since 0.0.4
|
|
33
37
|
def get_key(key)
|
|
34
38
|
store = config
|
|
35
39
|
store.transaction do
|
|
@@ -40,6 +44,7 @@ module Formkeep
|
|
|
40
44
|
# @param [String] key to add/modify
|
|
41
45
|
# @param [String] value to add/modify
|
|
42
46
|
# @return [String] value that was added/modified
|
|
47
|
+
# @since 0.0.4
|
|
43
48
|
def set_key(key, value)
|
|
44
49
|
store = config
|
|
45
50
|
store.transaction do
|
|
@@ -49,16 +54,19 @@ module Formkeep
|
|
|
49
54
|
|
|
50
55
|
# Sets API endpoint
|
|
51
56
|
# @return [String] API endpoint URL
|
|
57
|
+
# @since 0.0.4
|
|
52
58
|
def api
|
|
53
59
|
get_key(form)
|
|
54
60
|
end
|
|
55
61
|
|
|
56
62
|
# @return [String] text of API call
|
|
63
|
+
# @since 0.0.4
|
|
57
64
|
def response
|
|
58
65
|
Net::HTTP.get_response(URI(api)).body
|
|
59
66
|
end
|
|
60
67
|
|
|
61
68
|
# @return [Array] all submissions
|
|
69
|
+
# @since 0.0.4
|
|
62
70
|
def submissions
|
|
63
71
|
all = JSON.parse(response)["submissions"]
|
|
64
72
|
all.reject { |sub| sub["spam"] }
|
|
@@ -66,16 +74,19 @@ module Formkeep
|
|
|
66
74
|
|
|
67
75
|
# Latest submission info
|
|
68
76
|
# @return [Hash] first submission from submissions array
|
|
77
|
+
# @since 0.0.4
|
|
69
78
|
def latest_submission
|
|
70
79
|
submissions[0]
|
|
71
80
|
end
|
|
72
81
|
|
|
73
82
|
# @return [String] name of latest submission
|
|
83
|
+
# @since 0.0.4
|
|
74
84
|
def latest_name
|
|
75
85
|
latest_submission.fetch("name")
|
|
76
86
|
end
|
|
77
87
|
|
|
78
88
|
# @return [String] email of latest submission
|
|
89
|
+
# @since 0.0.4
|
|
79
90
|
def latest_email
|
|
80
91
|
latest_submission.fetch("email")
|
|
81
92
|
end
|
|
@@ -83,6 +94,7 @@ module Formkeep
|
|
|
83
94
|
|
|
84
95
|
# @!group Parsers
|
|
85
96
|
# @return [Array] all unread submissions
|
|
97
|
+
# @since 0.0.4
|
|
86
98
|
def unread_submissions
|
|
87
99
|
submissions.reject do |submission|
|
|
88
100
|
submission.fetch("read_at")
|
|
@@ -90,6 +102,7 @@ module Formkeep
|
|
|
90
102
|
end
|
|
91
103
|
|
|
92
104
|
# @return [Array] all read submissions
|
|
105
|
+
# @since 0.0.4
|
|
93
106
|
def read_submissions
|
|
94
107
|
submissions.select do |submission|
|
|
95
108
|
submission.fetch("read_at")
|
data/lib/formkeep/version.rb
CHANGED
data/spec/formkeep_spec.rb
CHANGED
|
@@ -4,6 +4,7 @@ describe Formkeep do
|
|
|
4
4
|
|
|
5
5
|
let(:test) {Formkeep::Form.new("test")}
|
|
6
6
|
let(:pixelsnatch) {Formkeep::Form.new("pixelsnatch")}
|
|
7
|
+
let(:subs) {pixelsnatch.submissions}
|
|
7
8
|
|
|
8
9
|
it 'has a version number' do
|
|
9
10
|
expect(Formkeep::VERSION).not_to be nil
|
|
@@ -14,10 +15,10 @@ describe Formkeep do
|
|
|
14
15
|
end
|
|
15
16
|
|
|
16
17
|
it "it pulls a submissions array" do
|
|
17
|
-
expect(
|
|
18
|
+
expect(subs.class).to eq(Array)
|
|
18
19
|
end
|
|
19
20
|
|
|
20
21
|
it "pulls the latest submission" do
|
|
21
|
-
expect(pixelsnatch.latest_submission.class).to eq(Hash) if
|
|
22
|
+
expect(pixelsnatch.latest_submission.class).to eq(Hash) if subs.length > 0
|
|
22
23
|
end
|
|
23
24
|
end
|