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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 88c9ba34b03585c9c61882bbc0427d731a9b8ad4176094a5e92ffd8bf3ff7adb
4
- data.tar.gz: c9b0a34edb0a4fbcfb2c4d12d6d05fbaa368d31ca4506d28abda1bf95da783d3
3
+ metadata.gz: af89c3dbe402f9b53fc7c717de7c58d47fc8927e2388a21ca15d52464839a879
4
+ data.tar.gz: 74f42c9e64fe80c364d84c9b40ab7733a0d3bb597eb0f2b2d0c261673215cef8
5
5
  SHA512:
6
- metadata.gz: 6943d74c4eb6cd81e3788b87f81650d5af4c7486f882f2ef0dcebafc7ad273ac01f44a95748a7d04de86155e8f794d55d0eaa26ca927168520e8af89a09835c7
7
- data.tar.gz: 33d6a04b6e9dee379e8bffd1dab044b8feeab27c546ce22b93b6cc6d42a49c7cc3c2960791ad9ec630d9089676d116bc23968e018e4089db87fc84342717e798
6
+ metadata.gz: 859b5eb8d1de6589def9b76450087c13ab8a4b02d927a9210e69f620705c4ef096630e920a0deb201d194ba97feadb5437ec4e1d4f107fd0406aa132e37f8028
7
+ data.tar.gz: e4163e04b1e771930b6b338a28463a53b18678401f68285dda7342d66214f6f64b19c5be90f01ba891a01d51461100eacc7e3aa8918817b1710ba89815f9e844
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+ .byebug_history
data/Gemfile.lock CHANGED
@@ -1,10 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- app_rail-airtable (0.2.4)
4
+ app_rail-airtable (0.2.8)
5
5
  activesupport
6
6
  airrecord
7
7
  sinatra
8
+ thor
8
9
 
9
10
  GEM
10
11
  remote: https://rubygems.org/
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.create_from_params (create)
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.
@@ -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
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  require "bundler/setup"
3
- require 'app_rail/airtable'
3
+ require 'app_rail/airtable/generator'
4
4
  require 'byebug'
5
5
 
6
6
  AppRail::Airtable::Generator.start(ARGV)
@@ -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
@@ -1,7 +1,7 @@
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
6
  module AppRail
7
7
  module Airtable
@@ -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
- name.classify_constantize.index.map(&:ar_list_item_as_json).to_json
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
- request.body.rewind # in case someone already read it
38
- data = JSON.parse(request.body.read)
39
- new_record = name.classify_constantize.create_from_params(data.merge(params))
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
@@ -1,5 +1,5 @@
1
1
  module AppRail
2
2
  module Airtable
3
- VERSION = "0.2.4"
3
+ VERSION = "0.2.8"
4
4
  end
5
5
  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
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-09-19 00:00:00.000000000 Z
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