app_rail-airtable 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0d893dd5ef7b42015a34fe0dd55738ef1296799ba40bd235c4fd1c84665d6048
4
- data.tar.gz: 0bd37ae820e88d1198cd7e82a0d8a965d893d0d4c8dc32bc33975f7f7a95cbcc
3
+ metadata.gz: 59112ddcce193bb297ccdb3cebd972445183c4a9e755a1ccb7c91c695f600bb9
4
+ data.tar.gz: ee3d1ff83a53b53f367aa7c84781113457a037abf4257a9d7ccf2589a167e456
5
5
  SHA512:
6
- metadata.gz: 4a4fe2f30b7b4ef404062e5396d304abf584873b1bfb5bf32d81ed3f8d5f04a01172bac29600ed83f7e347ba28267e670ce083e5aa0b93e886357b00042bfe73
7
- data.tar.gz: 23cf52db82ae5ba37f9ea00751f867a93b7d1f800f480810b21e932e4cfec3792eede5a3569b3b0baba1143991d415e6a09c031bee7d981196d8ebcbfca2cfaf
6
+ metadata.gz: 5099f41bc41cc4a744e49586c2f727cca97cb1054131144094f1c3bbe3cbaac8acb020909acae4903d92920348a738f70ebac45f18a9150a1b3c6246b8e17807
7
+ data.tar.gz: 4afb93f8f41cd9a306b1a5262fafcc30127f7c0df95c51e82b76fabf0a04b8e8e114381a432d44fb382e835021edbc5dcdc2727bee2bda12c6b23fdc5aad1b6e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- app_rail-airtable (0.2.6)
4
+ app_rail-airtable (0.2.7)
5
5
  activesupport
6
6
  airrecord
7
7
  sinatra
@@ -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
 
@@ -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
@@ -29,33 +30,38 @@ module AppRail
29
30
  request.body.rewind
30
31
  JSON.parse(request.body.read)
31
32
  end
33
+
34
+ def params_and_json_body
35
+ request_body_as_json.merge(params)
36
+ end
32
37
  end
33
38
 
34
- def self.resources(name, only: [:index, :show, :create])
39
+ def self.resources(name, only: [:index, :show, :create], authenticated: false)
35
40
  only = [only] if only.is_a?(Symbol)
36
41
 
37
- index_route(name) if only.include?(:index)
38
- show_route(name) if only.include?(:show)
39
- create_route(name) if only.include?(:create)
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)
40
45
  end
41
46
 
42
- def self.index_route(name)
47
+ def self.index_route(name, authenticated)
43
48
  get "/#{name.to_s}" do
44
- 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
45
51
  end
46
52
  end
47
53
 
48
- def self.show_route(name)
54
+ def self.show_route(name, authenticated)
49
55
  get "/#{name.to_s}/:id" do
56
+ authenticate! if authenticated
50
57
  name.classify_constantize.find(params['id']).ar_stack_as_json.to_json
51
58
  end
52
59
  end
53
60
 
54
- def self.create_route(name)
61
+ def self.create_route(name, authenticated)
55
62
  post "/#{name.to_s}" do
56
- request.body.rewind # in case someone already read it
57
- data = JSON.parse(request.body.read)
58
- as_json = name.classify_constantize.create_with_params_as_json(data.merge(params))
63
+ authenticate! if authenticated
64
+ as_json = name.classify_constantize.create_with_params_as_json(params_and_json_body)
59
65
  [201, as_json.to_json]
60
66
  end
61
67
  end
@@ -1,5 +1,5 @@
1
1
  module AppRail
2
2
  module Airtable
3
- VERSION = "0.2.6"
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.6
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-10-01 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