app_rail-airtable 0.2.3 → 0.2.7

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: c2f18121969b1289392808cbd8d44b13c24fdadee380024e1f84815f9c439197
4
- data.tar.gz: 7d81150a6b3a7c23f147a536488d24461e074ae13b51558164ce1006ab9e7e79
3
+ metadata.gz: 59112ddcce193bb297ccdb3cebd972445183c4a9e755a1ccb7c91c695f600bb9
4
+ data.tar.gz: ee3d1ff83a53b53f367aa7c84781113457a037abf4257a9d7ccf2589a167e456
5
5
  SHA512:
6
- metadata.gz: 7177fc23a347032cc2b03041e6d74238789b937e9e73fea3fee66584c78ddf6928ece275780be6882af03fc624f665797049eb70266412589cb52d3ec810d4d5
7
- data.tar.gz: d137d55da455f248203ed5b6996d23b54f2f7cb1301a8e07f8506c37bed397d44456076e61819faaa370d2412cff06e90aa47a824fbe990c1f60495709bc22a7
6
+ metadata.gz: 5099f41bc41cc4a744e49586c2f727cca97cb1054131144094f1c3bbe3cbaac8acb020909acae4903d92920348a738f70ebac45f18a9150a1b3c6246b8e17807
7
+ data.tar.gz: 4afb93f8f41cd9a306b1a5262fafcc30127f7c0df95c51e82b76fabf0a04b8e8e114381a432d44fb382e835021edbc5dcdc2727bee2bda12c6b23fdc5aad1b6e
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.3)
4
+ app_rail-airtable (0.2.7)
5
5
  activesupport
6
6
  airrecord
7
7
  sinatra
8
+ thor
8
9
 
9
10
  GEM
10
11
  remote: https://rubygems.org/
@@ -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(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
- class AppRail::Airtable::Generator < Thor::Group
7
- include Thor::Actions
6
+ module AppRail
7
+ module Airtable
8
+ class Generator < Thor::Group
9
+ include Thor::Actions
8
10
 
9
- argument :output_directory
10
- argument :api_key
11
- argument :base_id
12
- argument :tables
11
+ argument :output_directory
12
+ argument :api_key
13
+ argument :base_id
14
+ argument :tables
13
15
 
14
- def self.source_root
15
- File.join(File.dirname(__FILE__), "..", "..", "..")
16
- end
16
+ def self.source_root
17
+ File.join(File.dirname(__FILE__), "..", "..", "..")
18
+ end
17
19
 
18
- def create_project
19
- # Build tables
20
- @table_definitions = tables.split(",").map {|t| Airrecord.table(api_key, base_id, t.strip) }
21
- directory('templates/project', output_directory)
22
- end
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
- def self.exit_on_failure?
25
- true
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
- name.classify_constantize.index.map(&:ar_list_item_as_json).to_json
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
- 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_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
@@ -1,5 +1,5 @@
1
1
  module AppRail
2
2
  module Airtable
3
- VERSION = "0.2.3"
3
+ VERSION = "0.2.7"
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.3
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-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