app_rail-airtable 0.2.3 → 0.2.7
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 +2 -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 +21 -18
- 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: 59112ddcce193bb297ccdb3cebd972445183c4a9e755a1ccb7c91c695f600bb9
|
4
|
+
data.tar.gz: ee3d1ff83a53b53f367aa7c84781113457a037abf4257a9d7ccf2589a167e456
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5099f41bc41cc4a744e49586c2f727cca97cb1054131144094f1c3bbe3cbaac8acb020909acae4903d92920348a738f70ebac45f18a9150a1b3c6246b8e17807
|
7
|
+
data.tar.gz: 4afb93f8f41cd9a306b1a5262fafcc30127f7c0df95c51e82b76fabf0a04b8e8e114381a432d44fb382e835021edbc5dcdc2727bee2bda12c6b23fdc5aad1b6e
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
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(current_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
|
@@ -1,28 +1,31 @@
|
|
1
1
|
require 'active_support/core_ext/string/inflections'
|
2
|
+
require 'app_rail/airtable/string_ext'
|
2
3
|
require 'thor'
|
3
4
|
require 'airrecord'
|
4
|
-
require 'app_rail/airtable/string_ext'
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
module AppRail
|
7
|
+
module Airtable
|
8
|
+
class Generator < Thor::Group
|
9
|
+
include Thor::Actions
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
argument :output_directory
|
12
|
+
argument :api_key
|
13
|
+
argument :base_id
|
14
|
+
argument :tables
|
13
15
|
|
14
|
-
|
15
|
-
|
16
|
-
|
16
|
+
def self.source_root
|
17
|
+
File.join(File.dirname(__FILE__), "..", "..", "..")
|
18
|
+
end
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
def create_project
|
21
|
+
# Build tables
|
22
|
+
@table_definitions = tables.split(",").map {|t| Airrecord.table(api_key, base_id, t.strip) }
|
23
|
+
directory('templates/project', output_directory)
|
24
|
+
end
|
23
25
|
|
24
|
-
|
25
|
-
|
26
|
+
def self.exit_on_failure?
|
27
|
+
true
|
28
|
+
end
|
29
|
+
end
|
26
30
|
end
|
27
|
-
|
28
31
|
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(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_with_params_as_json(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.7
|
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
|