app_rail-airtable 0.4.1 → 0.4.4

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: 635c1b4e200ee31f032f974ca3da84df53b766825c10ac3d4c867ac5b1533c2b
4
- data.tar.gz: 5949f7165d856d5bfab33fb42cf157b859346651c5b927aa548b098841a5f5a5
3
+ metadata.gz: 9bdf887a34ccfd9c7954686766bab870a20c4374aa5f88a7e8e11a01d62430a4
4
+ data.tar.gz: b835884ff719353097b0d70277c52b1bda4bc5bf9ed23008ee9b0005bce1354c
5
5
  SHA512:
6
- metadata.gz: 352a2c5566fa8b24966d8ce524a6d9b8fc0ebc91b3559b79d0bff16fd9c5436a9bbe6a0893084f15c4fbdd071382da25b455e7b915a271a5a45fcf8c11f9f5c6
7
- data.tar.gz: 2febff28b74cf2b538b6d8767fc308946d48f7e75bff35991d8e30e4ac29a6794e21d75d37e213ef51a3d9dcf791a078c4890ec62fd931904d7199f74fd54d69
6
+ metadata.gz: a0c589cae34adf401da10ef37daa174ff9eec6e8a9c5b93c5bc632059e52f41be0e685001ae3d9fe29e837678adf1709c7509cabb5dbe37af1f7438a5780afcb
7
+ data.tar.gz: e48ced1c4155d951decd90d83a38c371e4d50a135a29320c21f723ede9a4e535561fe302faf68b9a3a0256aa89e8f957c77e36f2096431f35551c6f132a618c2
data/Gemfile.lock CHANGED
@@ -1,9 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- app_rail-airtable (0.4.1)
4
+ app_rail-airtable (0.4.4)
5
5
  activesupport
6
6
  airrecord
7
+ app_rail-steps
7
8
  bcrypt
8
9
  faraday (~> 2.2)
9
10
  faraday-net_http_persistent (~> 2.0)
@@ -13,15 +14,16 @@ PATH
13
14
  GEM
14
15
  remote: https://rubygems.org/
15
16
  specs:
16
- activesupport (7.0.2.3)
17
+ activesupport (7.0.2.4)
17
18
  concurrent-ruby (~> 1.0, >= 1.0.2)
18
19
  i18n (>= 1.6, < 2)
19
20
  minitest (>= 5.1)
20
21
  tzinfo (~> 2.0)
21
- airrecord (1.0.9)
22
- faraday (>= 0.10, < 3.0)
22
+ airrecord (1.0.10)
23
+ faraday (>= 1.0, < 3.0)
23
24
  faraday-net_http_persistent
24
25
  net-http-persistent
26
+ app_rail-steps (0.2.9)
25
27
  bcrypt (3.1.17)
26
28
  byebug (11.1.3)
27
29
  concurrent-ruby (1.1.10)
@@ -28,6 +28,7 @@ Gem::Specification.new do |spec|
28
28
  spec.require_paths = ['lib']
29
29
  spec.add_dependency 'activesupport'
30
30
  spec.add_dependency 'airrecord'
31
+ spec.add_dependency 'app_rail-steps'
31
32
  spec.add_dependency 'bcrypt'
32
33
  spec.add_dependency 'faraday', '~> 2.2'
33
34
  spec.add_dependency 'faraday-net_http_persistent', '~> 2.0' # workaround to make Faraday work after upgrading to 2.2.0
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'airrecord'
4
- require 'app_rail-steps'
4
+ require 'app_rail/steps'
5
5
  require 'active_support/core_ext/string/inflections'
6
6
 
7
7
  module AppRail
@@ -6,6 +6,8 @@ require 'securerandom'
6
6
  module AppRail
7
7
  module Airtable
8
8
  module Authenticatable
9
+ class AlreadyExistsError < StandardError; end
10
+
9
11
  include BCrypt
10
12
 
11
13
  def self.included(klass)
@@ -15,6 +17,8 @@ module AppRail
15
17
 
16
18
  module ClassMethods
17
19
  def create(email:, password:)
20
+ raise AlreadyExistsError if find_by_email(email)
21
+
18
22
  user = new('Email' => email, 'Password Hash' => password_hash(password), 'Access Token' => next_access_token)
19
23
  user.create
20
24
  user
@@ -30,10 +34,14 @@ module AppRail
30
34
  end
31
35
 
32
36
  def find_by_email_and_password(email, password)
33
- user = all(filter: "{Email} = \"#{email}\"").first
37
+ user = find_by_email(email)
34
38
  user&.valid_password?(password) ? user : nil
35
39
  end
36
40
 
41
+ def find_by_email(email)
42
+ all(filter: "{Email} = \"#{email}\"").first
43
+ end
44
+
37
45
  def find_by_access_token(access_token)
38
46
  all(filter: "{Access Token} = \"#{access_token}\"").first
39
47
  end
@@ -12,6 +12,10 @@ class Symbol
12
12
  ActiveSupport::Inflector.pluralize(self)
13
13
  end
14
14
 
15
+ def singularize
16
+ ActiveSupport::Inflector.singularize(self)
17
+ end
18
+
15
19
  def classify
16
20
  ActiveSupport::Inflector.classify(self)
17
21
  end
@@ -77,9 +81,13 @@ module AppRail
77
81
  def self.create_route(name, authenticated_route)
78
82
  post "/#{name}" do
79
83
  authenticate! if authenticated_route
80
- as_json = name.classify_constantize.create_as_json(current_user: authenticated_route ? current_user : nil,
81
- params: params_and_body_as_json)
82
- [201, as_json.to_json]
84
+ begin
85
+ as_json = name.classify_constantize.create_as_json(current_user: authenticated_route ? current_user : nil,
86
+ params: params_and_body_as_json)
87
+ [201, as_json.to_json]
88
+ rescue AppRail::Airtable::Authenticatable::AlreadyExistsError
89
+ [422, { error: "#{name.singularize} already exists" }]
90
+ end
83
91
  end
84
92
  end
85
93
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module AppRail
4
4
  module Airtable
5
- VERSION = '0.4.1'
5
+ VERSION = '0.4.4'
6
6
  end
7
7
  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.4.1
4
+ version: 0.4.4
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: 2022-04-18 00:00:00.000000000 Z
11
+ date: 2022-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: app_rail-steps
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: bcrypt
43
57
  requirement: !ruby/object:Gem::Requirement