formkeep 0.0.3 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 970cf5c12d629ca062de7191353668dbced8585b
4
- data.tar.gz: 1451375588a2fc90a9947cabf606aa62cedfe905
3
+ metadata.gz: 3546579edb5c82ebe4f71cfe320a1fa8d99cf849
4
+ data.tar.gz: 3c88d322497c57aa0e5b6c5393bb0af15a1dc53a
5
5
  SHA512:
6
- metadata.gz: 56c201ce701b662d563488c5a38d80ce159f40f0d615013e8779b061c5459af08bdb1be2e90cc439a09051895ef1b7fbdfbb677437be0e81d45bace1dd97edd4
7
- data.tar.gz: 2a2429fcc0aa475aec77002d286ad9eb60909b006eb120dbed6749004cdd81a238e7aa8b930cace93785e7251eabe1f789a7365e3a1f24463443242915131808
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
- ~~~yaml
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
- ~~~rb
37
- # Check for unread submissions
35
+ ~~~
38
36
  formkeep check FORM
39
37
  ~~~
40
38
 
@@ -5,17 +5,24 @@ require 'slop'
5
5
 
6
6
  opts = Slop.parse do
7
7
  banner "Usage: formkeep check FORM"
8
- on :v, :version do
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
- run do |options, args|
14
- form = Formkeep::Cli.new(args[0]) if args
15
- if form.unread_submissions.length > 0
16
- puts "You have unread submissions!"
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 "You have no unread submissions."
25
+ puts opts
19
26
  end
20
27
  end
21
28
  end
@@ -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
- class Cli
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
@@ -1,3 +1,4 @@
1
1
  module Formkeep
2
- VERSION = "0.0.3"
2
+ # Sets version for RubyGems
3
+ VERSION = "0.0.4"
3
4
  end
@@ -2,8 +2,8 @@ require 'spec_helper'
2
2
 
3
3
  describe Formkeep do
4
4
 
5
- let(:test) {Formkeep::Cli.new("test")}
6
- let(:pixelsnatch) {Formkeep::Cli.new("pixelsnatch")}
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formkeep
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - brandonpittman