app_rail-airtable 0.2.5 → 0.2.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile.lock +3 -1
- data/README.md +3 -1
- data/app_rail-airtable.gemspec +1 -0
- data/bin/ara_generator +1 -1
- data/lib/app_rail/airtable/application_record.rb +1 -1
- data/lib/app_rail/airtable/authentication_record.rb +27 -0
- data/lib/app_rail/airtable/generator.rb +1 -1
- data/lib/app_rail/airtable/sinatra.rb +33 -9
- data/lib/app_rail/airtable/version.rb +1 -1
- data/lib/app_rail/airtable.rb +2 -1
- metadata +17 -3
- data/.byebug_history +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e09f5f21d40b2186a9b4d985d85305c0f4e54e4066d74ee45a5c43a32a303ad
|
4
|
+
data.tar.gz: 0ab6b313e24780b1f83e2359638e783ff3d7ca7b6958b14c7c80ba479262e07c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5cdd4ff73e660d69000ac91e1204047f7637a7d58e351e1253639a60423828ccf3c8417083aeaadf1d4d3660584302cbfab9a39f5f737a5b501257fdf6f0359e
|
7
|
+
data.tar.gz: b9e534d2132bf753fd8cdf8d1126cdf629921177bbaf164e6ca21cabd64b9b207830dcbc9087a09f480c03d0c5ebb8e0101a8ae1d6625da851dc8bc8e589eee3
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
app_rail-airtable (0.2.
|
4
|
+
app_rail-airtable (0.2.9)
|
5
5
|
activesupport
|
6
6
|
airrecord
|
7
|
+
bcrypt
|
7
8
|
sinatra
|
8
9
|
thor
|
9
10
|
|
@@ -19,6 +20,7 @@ GEM
|
|
19
20
|
airrecord (1.0.7)
|
20
21
|
faraday (>= 0.10, < 2.0)
|
21
22
|
net-http-persistent
|
23
|
+
bcrypt (3.1.16)
|
22
24
|
byebug (11.1.3)
|
23
25
|
concurrent-ruby (1.1.9)
|
24
26
|
connection_pool (2.2.5)
|
data/README.md
CHANGED
@@ -31,7 +31,9 @@ You should create a model class for each table you want to use in your App. Mode
|
|
31
31
|
To provide support for routes, models can implement
|
32
32
|
* ar_list_item (index)
|
33
33
|
* ar_stack (show)
|
34
|
-
* self.
|
34
|
+
* self.create_as_json (create)
|
35
|
+
|
36
|
+
In order to support authentication you should create a class (normally `User`) and inherit from `AppRail::Airtable::AuthenticationRecord`. Your table needs `Email`, `Password Hash` and `Access Token` columns.
|
35
37
|
|
36
38
|
### Servers
|
37
39
|
You should create a single server which extends `AppRail::Airtable::Sinatra`, then add routes with the `resources` macro to add `index`, `show` and `create` routes. You can also provide your own routes.
|
data/app_rail-airtable.gemspec
CHANGED
data/bin/ara_generator
CHANGED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'bcrypt'
|
2
|
+
|
3
|
+
module AppRail
|
4
|
+
module Airtable
|
5
|
+
class AuthenticationRecord < ApplicationRecord
|
6
|
+
include BCrypt
|
7
|
+
airtable_attr "Email", "Password Hash", "Access Token"
|
8
|
+
|
9
|
+
def self.create_session_as_json(email:, password:)
|
10
|
+
user = find_by_email_and_password(email, Password.create(password))
|
11
|
+
user&.oauth_session
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.find_by_email_and_password(email, password_hash)
|
15
|
+
all(filter: "AND({Email} = \"#{email}\",{Password Hash} = \"#{password_hash}\")").first
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.find_by_access_token(access_token)
|
19
|
+
all(filter: "{Access Token} = \"#{access_token}\"").first
|
20
|
+
end
|
21
|
+
|
22
|
+
def oauth_session
|
23
|
+
{ access_token: self["Access Token"], scope: :user, refresh_token: "", token_type: :bearer, expires_in: 60000 }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -2,6 +2,7 @@ require 'sinatra'
|
|
2
2
|
require 'json'
|
3
3
|
require 'active_support'
|
4
4
|
|
5
|
+
# TODO: MBS - move to configure block or other
|
5
6
|
Airrecord.api_key = ENV.fetch("AIRTABLE_API_KEY")
|
6
7
|
|
7
8
|
class Symbol
|
@@ -23,24 +24,47 @@ end
|
|
23
24
|
module AppRail
|
24
25
|
module Airtable
|
25
26
|
class Sinatra < Sinatra::Base
|
27
|
+
|
28
|
+
helpers do
|
29
|
+
def request_body_as_json
|
30
|
+
request.body.rewind
|
31
|
+
JSON.parse(request.body.read)
|
32
|
+
end
|
33
|
+
|
34
|
+
def params_and_json_body
|
35
|
+
request_body_as_json.merge(params)
|
36
|
+
end
|
37
|
+
end
|
26
38
|
|
27
|
-
def self.resources(name)
|
39
|
+
def self.resources(name, only: [:index, :show, :create], authenticated: false)
|
40
|
+
only = [only] if only.is_a?(Symbol)
|
41
|
+
|
42
|
+
index_route(name, authenticated) if only.include?(:index)
|
43
|
+
show_route(name, authenticated) if only.include?(:show)
|
44
|
+
create_route(name, authenticated) if only.include?(:create)
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.index_route(name, authenticated)
|
28
48
|
get "/#{name.to_s}" do
|
29
|
-
|
49
|
+
authenticate! if authenticated
|
50
|
+
name.classify_constantize.index(user: authenticated ? current_user : nil).map(&:ar_list_item_as_json).to_json
|
30
51
|
end
|
31
|
-
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.show_route(name, authenticated)
|
32
55
|
get "/#{name.to_s}/:id" do
|
56
|
+
authenticate! if authenticated
|
33
57
|
name.classify_constantize.find(params['id']).ar_stack_as_json.to_json
|
34
58
|
end
|
35
|
-
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.create_route(name, authenticated)
|
36
62
|
post "/#{name.to_s}" do
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
[201, {id: new_record.id}.to_json]
|
63
|
+
authenticate! if authenticated
|
64
|
+
as_json = name.classify_constantize.create_as_json(current_user: authenticated ? current_user : nil, params: params_and_json_body)
|
65
|
+
[201, as_json.to_json]
|
41
66
|
end
|
42
67
|
end
|
43
|
-
|
44
68
|
end
|
45
69
|
end
|
46
70
|
end
|
data/lib/app_rail/airtable.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
require "app_rail/airtable/version"
|
2
|
+
require "app_rail/airtable/string_ext"
|
2
3
|
require "app_rail/airtable/application_record"
|
4
|
+
require "app_rail/airtable/authentication_record"
|
3
5
|
require "app_rail/airtable/sinatra"
|
4
6
|
require "app_rail/airtable/generator"
|
5
|
-
require "app_rail/airtable/string_ext"
|
6
7
|
|
7
8
|
module AppRail
|
8
9
|
module Airtable
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: app_rail-airtable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Brooke-Smith
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-10-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bcrypt
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: rspec
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -102,7 +116,6 @@ extensions: []
|
|
102
116
|
extra_rdoc_files: []
|
103
117
|
files:
|
104
118
|
- ".DS_Store"
|
105
|
-
- ".byebug_history"
|
106
119
|
- ".gitignore"
|
107
120
|
- ".rspec"
|
108
121
|
- ".travis.yml"
|
@@ -117,6 +130,7 @@ files:
|
|
117
130
|
- bin/setup
|
118
131
|
- lib/app_rail/airtable.rb
|
119
132
|
- lib/app_rail/airtable/application_record.rb
|
133
|
+
- lib/app_rail/airtable/authentication_record.rb
|
120
134
|
- lib/app_rail/airtable/generator.rb
|
121
135
|
- lib/app_rail/airtable/sinatra.rb
|
122
136
|
- lib/app_rail/airtable/string_ext.rb
|
data/.byebug_history
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
exit
|
2
|
-
@table_definitions.first.all.first.fields.keys
|
3
|
-
@table_definitions.first.all.first.fields
|
4
|
-
@table_definitions.first.all.first
|
5
|
-
@table_definitions.first.first
|
6
|
-
@table_definitions.first.instance_variable_get("@fields")
|
7
|
-
@table_definitions.first.instance_variable_get("fields")
|
8
|
-
@table_definitions.first.instance_variable_get("@fields")
|
9
|
-
@table_definitions.first.fields
|
10
|
-
@table_definitions.first.table_name
|
11
|
-
@table_definitions.first.name
|
12
|
-
@table_definitions.first.all
|
13
|
-
@table_definitions.first
|
14
|
-
@table_definitions
|