app_rail-airtable 0.2.4 → 0.2.8
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 +1 -0
- data/Gemfile.lock +2 -1
- data/README.md +1 -1
- data/app_rail-airtable.gemspec +1 -0
- data/bin/ara_generator +1 -1
- data/lib/app_rail/airtable/application_record.rb +2 -2
- 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
- metadata +16 -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: af89c3dbe402f9b53fc7c717de7c58d47fc8927e2388a21ca15d52464839a879
|
4
|
+
data.tar.gz: 74f42c9e64fe80c364d84c9b40ab7733a0d3bb597eb0f2b2d0c261673215cef8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 859b5eb8d1de6589def9b76450087c13ab8a4b02d927a9210e69f620705c4ef096630e920a0deb201d194ba97feadb5437ec4e1d4f107fd0406aa132e37f8028
|
7
|
+
data.tar.gz: e4163e04b1e771930b6b338a28463a53b18678401f68285dda7342d66214f6f64b19c5be90f01ba891a01d51461100eacc7e3aa8918817b1710ba89815f9e844
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -31,7 +31,7 @@ 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
35
|
|
36
36
|
### Servers
|
37
37
|
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
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_dependency 'activesupport'
|
24
24
|
spec.add_dependency 'sinatra'
|
25
25
|
spec.add_dependency 'airrecord'
|
26
|
+
spec.add_dependency 'thor'
|
26
27
|
|
27
28
|
spec.add_development_dependency 'rspec'
|
28
29
|
spec.add_development_dependency 'rack-test'
|
data/bin/ara_generator
CHANGED
@@ -43,7 +43,7 @@ module AppRail
|
|
43
43
|
# Customisable behaviour
|
44
44
|
|
45
45
|
# Override to provide custom sorting or filtering for index
|
46
|
-
def self.index
|
46
|
+
def self.index(user:)
|
47
47
|
all
|
48
48
|
end
|
49
49
|
|
@@ -55,7 +55,7 @@ module AppRail
|
|
55
55
|
|
56
56
|
# size is either :small, :large or :full
|
57
57
|
def image(name, index: 0, size: :full)
|
58
|
-
self[name][index]["thumbnails"][size.to_s]["url"]
|
58
|
+
self[name][index]["thumbnails"][size.to_s]["url"] if self[name] && self[name].length > index
|
59
59
|
end
|
60
60
|
|
61
61
|
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
|
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.8
|
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-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: thor
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: rspec
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -88,7 +102,6 @@ extensions: []
|
|
88
102
|
extra_rdoc_files: []
|
89
103
|
files:
|
90
104
|
- ".DS_Store"
|
91
|
-
- ".byebug_history"
|
92
105
|
- ".gitignore"
|
93
106
|
- ".rspec"
|
94
107
|
- ".travis.yml"
|
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
|