oxy 0.1.4 → 0.1.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/.gitignore +62 -0
- data/bin/console +4 -4
- data/lib/oxy/firebase/submission.rb +2 -0
- data/lib/oxy/firebase/submissions.rb +68 -0
- data/lib/oxy/middleware/rsvp.rb +6 -6
- data/lib/oxy/module/subscribe.rb +9 -0
- data/lib/oxy/version.rb +1 -1
- data/lib/oxy.rb +3 -1
- data/oxy.gemspec +1 -1
- metadata +19 -17
- data/lib/oxy/google_contact.rb +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02a23f55b9b4cf46d59ef0f671a472a225153ac8
|
4
|
+
data.tar.gz: a2e6b315527a05744f8bc523d6066118cbcc186d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9497cc4a6a0342b8005970df6005cdd3093dc9f7a5f31115d0b1f9f2daa172ec324125c60c5658d19ee0f928ddcb7a671439c4fd7853ab0ac40752a319894b87
|
7
|
+
data.tar.gz: de94ce90f57007c111b57c666dbddc3cdac9bc0ad73e323c4d3b292bcc259fc5f5c0ac0b361fd80fc67ae3204a8a6a3e6ea88a370e598f5b4e717e321231b637
|
data/.gitignore
CHANGED
@@ -7,3 +7,65 @@
|
|
7
7
|
/pkg/
|
8
8
|
/spec/reports/
|
9
9
|
/tmp/
|
10
|
+
|
11
|
+
# Created by https://www.gitignore.io/api/osx
|
12
|
+
|
13
|
+
### OSX ###
|
14
|
+
*.DS_Store
|
15
|
+
.AppleDouble
|
16
|
+
.LSOverride
|
17
|
+
|
18
|
+
# Icon must end with two \r
|
19
|
+
Icon
|
20
|
+
|
21
|
+
# Thumbnails
|
22
|
+
._*
|
23
|
+
|
24
|
+
# Files that might appear in the root of a volume
|
25
|
+
.DocumentRevisions-V100
|
26
|
+
.fseventsd
|
27
|
+
.Spotlight-V100
|
28
|
+
.TemporaryItems
|
29
|
+
.Trashes
|
30
|
+
.VolumeIcon.icns
|
31
|
+
.com.apple.timemachine.donotpresent
|
32
|
+
|
33
|
+
# Directories potentially created on remote AFP share
|
34
|
+
.AppleDB
|
35
|
+
.AppleDesktop
|
36
|
+
Network Trash Folder
|
37
|
+
Temporary Items
|
38
|
+
.apdisk
|
39
|
+
|
40
|
+
# End of https://www.gitignore.io/api/osx
|
41
|
+
|
42
|
+
# Created by https://www.gitignore.io/api/osx
|
43
|
+
|
44
|
+
### OSX ###
|
45
|
+
*.DS_Store
|
46
|
+
.AppleDouble
|
47
|
+
.LSOverride
|
48
|
+
|
49
|
+
# Icon must end with two \r
|
50
|
+
Icon
|
51
|
+
|
52
|
+
# Thumbnails
|
53
|
+
._*
|
54
|
+
|
55
|
+
# Files that might appear in the root of a volume
|
56
|
+
.DocumentRevisions-V100
|
57
|
+
.fseventsd
|
58
|
+
.Spotlight-V100
|
59
|
+
.TemporaryItems
|
60
|
+
.Trashes
|
61
|
+
.VolumeIcon.icns
|
62
|
+
.com.apple.timemachine.donotpresent
|
63
|
+
|
64
|
+
# Directories potentially created on remote AFP share
|
65
|
+
.AppleDB
|
66
|
+
.AppleDesktop
|
67
|
+
Network Trash Folder
|
68
|
+
Temporary Items
|
69
|
+
.apdisk
|
70
|
+
|
71
|
+
# End of https://www.gitignore.io/api/osx
|
data/bin/console
CHANGED
@@ -7,8 +7,8 @@ require "oxy"
|
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
8
8
|
|
9
9
|
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
|
11
|
-
|
10
|
+
require "pry"
|
11
|
+
Pry.start
|
12
12
|
|
13
|
-
require "irb"
|
14
|
-
IRB.start(__FILE__)
|
13
|
+
# require "irb"
|
14
|
+
# IRB.start(__FILE__)
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require "httparty"
|
2
|
+
|
3
|
+
class Submissions
|
4
|
+
include HTTParty
|
5
|
+
|
6
|
+
format :json
|
7
|
+
|
8
|
+
def self.find_by(email_address)
|
9
|
+
# fabricate lookup key based on MD5 hash of the email address
|
10
|
+
lookup_key = to_lookup_key(email_address)
|
11
|
+
# fetch response from Firebase
|
12
|
+
response = get("/submissions/#{lookup_key}.json", default_options)
|
13
|
+
# parse it into JSON
|
14
|
+
parse(response)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.find_submission(email_address)
|
18
|
+
# fabricate lookup key based on MD5 hash of the email address
|
19
|
+
lookup_key = to_lookup_key(email_address)
|
20
|
+
# fetch response from Firebase
|
21
|
+
response = get("/submissions/#{lookup_key}.json", default_options)
|
22
|
+
# return response's parsed body
|
23
|
+
response.parsed_response
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.push(submission)
|
27
|
+
# fabricate lookup key based on MD5
|
28
|
+
lookup_key = to_lookup_key(submission["email_address"])
|
29
|
+
# build body
|
30
|
+
json_string = { "#{lookup_key}" => submission }.to_json
|
31
|
+
# merge options
|
32
|
+
options = default_options.merge(:body => json_string)
|
33
|
+
# push the submission entry to Firebase
|
34
|
+
put("/submissions.json", options)
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.drop(email_address = nil)
|
38
|
+
# prepare
|
39
|
+
path = "/submissions"
|
40
|
+
# fabricate lookup key based on MD5
|
41
|
+
if email_address
|
42
|
+
lookup_key = to_lookup_key(email_address)
|
43
|
+
path += "/#{lookup_key}"
|
44
|
+
end
|
45
|
+
# delete the entry
|
46
|
+
delete("#{path}.json", default_options)
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
def self.parse(response)
|
51
|
+
# yield nil if response is not parseable
|
52
|
+
return nil unless response && response.parsed_response
|
53
|
+
# parse it from JSON
|
54
|
+
JSON.parse(response.body, { :object_class => Submission })
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.to_lookup_key(email_address)
|
58
|
+
Digest::MD5.hexdigest(email_address)
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.default_options
|
62
|
+
{
|
63
|
+
:base_uri => ENV["FIREBASE_URL"],
|
64
|
+
:query => { :auth => ENV["FIREBASE_SECRET"] },
|
65
|
+
:headers => { "Content-Type" => "application/json" }
|
66
|
+
}
|
67
|
+
end
|
68
|
+
end
|
data/lib/oxy/middleware/rsvp.rb
CHANGED
@@ -5,7 +5,7 @@ require "threaded"
|
|
5
5
|
class Oxy::RSVP
|
6
6
|
# The set of allowed fields. Requests that do not have fields
|
7
7
|
# present in this list will not be eligible to be enqueued.
|
8
|
-
ELIGIBLE_FORMS_FIELDS = ['email_address']
|
8
|
+
ELIGIBLE_FORMS_FIELDS = ['email_address', 'first_name', 'last_name']
|
9
9
|
|
10
10
|
# ctor.
|
11
11
|
def initialize(app, logger = $stderr)
|
@@ -17,10 +17,10 @@ class Oxy::RSVP
|
|
17
17
|
def call(env)
|
18
18
|
# instantiate the request object
|
19
19
|
req = Rack::Request.new(env)
|
20
|
-
if req.path == "/rsvp" && req.post?
|
21
|
-
# enqueue
|
22
|
-
Threaded.enqueue(
|
23
|
-
# redirect
|
20
|
+
if req.path == "/rsvp" && req.post?
|
21
|
+
# enqueue background processing for valid submissions only
|
22
|
+
Threaded.enqueue(Subscribe, req.POST, @logger) if valid_form(req.POST)
|
23
|
+
# redirect anyways
|
24
24
|
[302, { "Location" => "/thank-you" }, []]
|
25
25
|
else
|
26
26
|
@app.call(env)
|
@@ -30,7 +30,7 @@ class Oxy::RSVP
|
|
30
30
|
private
|
31
31
|
# only request with eligible form fields are valid
|
32
32
|
def valid_form(form)
|
33
|
-
unless
|
33
|
+
unless form.all? { |key, _| ELIGIBLE_FORMS_FIELDS.include?(key) }
|
34
34
|
@logger.write("[RSVP]: Received an invalid form ~> #{form.inspect}\n")
|
35
35
|
return false
|
36
36
|
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# Very simple subscribe-alike module that uses Firebase to store the data
|
2
|
+
class Subscribe
|
3
|
+
def self.call(form, logger = $stderr)
|
4
|
+
# push new submission
|
5
|
+
Submissions.push(form)
|
6
|
+
# log the request
|
7
|
+
logger.write("[Oxy::Subscribe]: #{form["email_address"]} has requested to be subscribed...\n")
|
8
|
+
end
|
9
|
+
end
|
data/lib/oxy/version.rb
CHANGED
data/lib/oxy.rb
CHANGED
data/oxy.gemspec
CHANGED
@@ -23,11 +23,11 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_runtime_dependency "rack-contrib", "~> 1.2"
|
24
24
|
spec.add_runtime_dependency "puma", "~> 3.10"
|
25
25
|
spec.add_runtime_dependency "threaded", "~> 0.0.4"
|
26
|
+
spec.add_runtime_dependency "httparty", "~> 0.15.6"
|
26
27
|
|
27
28
|
spec.add_development_dependency "bundler", "~> 1.15"
|
28
29
|
spec.add_development_dependency "rake", "~> 10.0"
|
29
30
|
spec.add_development_dependency "minitest", "~> 5.0"
|
30
|
-
spec.add_development_dependency "httparty"
|
31
31
|
spec.add_development_dependency "rack-test"
|
32
32
|
|
33
33
|
spec.add_development_dependency "pry"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oxy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pavel Tsurbeleu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-11-
|
11
|
+
date: 2017-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 0.0.4
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: httparty
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.15.6
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.15.6
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: bundler
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,20 +122,6 @@ dependencies:
|
|
108
122
|
- - "~>"
|
109
123
|
- !ruby/object:Gem::Version
|
110
124
|
version: '5.0'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: httparty
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - ">="
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '0'
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - ">="
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: rack-test
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -225,8 +225,10 @@ files:
|
|
225
225
|
- bin/oxy
|
226
226
|
- bin/setup
|
227
227
|
- lib/oxy.rb
|
228
|
-
- lib/oxy/
|
228
|
+
- lib/oxy/firebase/submission.rb
|
229
|
+
- lib/oxy/firebase/submissions.rb
|
229
230
|
- lib/oxy/middleware/rsvp.rb
|
231
|
+
- lib/oxy/module/subscribe.rb
|
230
232
|
- lib/oxy/server.rb
|
231
233
|
- lib/oxy/version.rb
|
232
234
|
- oxy.gemspec
|