app_rail-airtable 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f9ec1d3dd50d2b81b46a1f6804319b97424192accf1e825830ade564c4901aa5
4
+ data.tar.gz: '0220939ea9dfd1ca57806f60328ca0bd4ea09417fdc2aeb1b61e70687024aeef'
5
+ SHA512:
6
+ metadata.gz: d13146f0116ea27771ac901dcc514938fa5e3b23e1b1342f6123a76a7e39bdb3b1dd1c7a2ce1bd477cc2a579a7c313ed44e521652f99ca9e8dcb78dba6b7a364
7
+ data.tar.gz: e6cfc76d2a99c122d3643dd587bdef60a5e7131f04c4f7d0de0ed60ed76c2c130f6ded6d74123864fa6cb45c15cb904e0c7fcd2e4500720ce2479f4de6ae3132
data/.DS_Store ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.4
6
+ before_install: gem install bundler -v 2.1.4
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in app_rail-airtable.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,91 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ app_rail-airtable (0.1.0)
5
+ activesupport
6
+ airrecord
7
+ sinatra
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ activesupport (6.1.4.1)
13
+ concurrent-ruby (~> 1.0, >= 1.0.2)
14
+ i18n (>= 1.6, < 2)
15
+ minitest (>= 5.1)
16
+ tzinfo (~> 2.0)
17
+ zeitwerk (~> 2.3)
18
+ airrecord (1.0.7)
19
+ faraday (>= 0.10, < 2.0)
20
+ net-http-persistent
21
+ concurrent-ruby (1.1.9)
22
+ connection_pool (2.2.5)
23
+ diff-lcs (1.4.4)
24
+ faraday (1.7.2)
25
+ faraday-em_http (~> 1.0)
26
+ faraday-em_synchrony (~> 1.0)
27
+ faraday-excon (~> 1.1)
28
+ faraday-httpclient (~> 1.0.1)
29
+ faraday-net_http (~> 1.0)
30
+ faraday-net_http_persistent (~> 1.1)
31
+ faraday-patron (~> 1.0)
32
+ faraday-rack (~> 1.0)
33
+ multipart-post (>= 1.2, < 3)
34
+ ruby2_keywords (>= 0.0.4)
35
+ faraday-em_http (1.0.0)
36
+ faraday-em_synchrony (1.0.0)
37
+ faraday-excon (1.1.0)
38
+ faraday-httpclient (1.0.1)
39
+ faraday-net_http (1.0.1)
40
+ faraday-net_http_persistent (1.2.0)
41
+ faraday-patron (1.0.0)
42
+ faraday-rack (1.0.0)
43
+ i18n (1.8.10)
44
+ concurrent-ruby (~> 1.0)
45
+ minitest (5.14.4)
46
+ multipart-post (2.1.1)
47
+ mustermann (1.1.1)
48
+ ruby2_keywords (~> 0.0.1)
49
+ net-http-persistent (4.0.1)
50
+ connection_pool (~> 2.2)
51
+ rack (2.2.3)
52
+ rack-protection (2.1.0)
53
+ rack
54
+ rack-test (1.1.0)
55
+ rack (>= 1.0, < 3)
56
+ rake (12.3.3)
57
+ rspec (3.10.0)
58
+ rspec-core (~> 3.10.0)
59
+ rspec-expectations (~> 3.10.0)
60
+ rspec-mocks (~> 3.10.0)
61
+ rspec-core (3.10.1)
62
+ rspec-support (~> 3.10.0)
63
+ rspec-expectations (3.10.1)
64
+ diff-lcs (>= 1.2.0, < 2.0)
65
+ rspec-support (~> 3.10.0)
66
+ rspec-mocks (3.10.2)
67
+ diff-lcs (>= 1.2.0, < 2.0)
68
+ rspec-support (~> 3.10.0)
69
+ rspec-support (3.10.2)
70
+ ruby2_keywords (0.0.5)
71
+ sinatra (2.1.0)
72
+ mustermann (~> 1.0)
73
+ rack (~> 2.2)
74
+ rack-protection (= 2.1.0)
75
+ tilt (~> 2.0)
76
+ tilt (2.0.10)
77
+ tzinfo (2.0.4)
78
+ concurrent-ruby (~> 1.0)
79
+ zeitwerk (2.4.2)
80
+
81
+ PLATFORMS
82
+ ruby
83
+
84
+ DEPENDENCIES
85
+ app_rail-airtable!
86
+ rack-test
87
+ rake (~> 12.0)
88
+ rspec (~> 3.0)
89
+
90
+ BUNDLED WITH
91
+ 2.1.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Matt Brooke-Smith
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # AppRail::Airtable
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/app_rail/airtable`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'app_rail-airtable'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install app_rail-airtable
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/app_rail-airtable.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,29 @@
1
+ require_relative 'lib/app_rail/airtable/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "app_rail-airtable"
5
+ spec.version = AppRail::Airtable::VERSION
6
+ spec.authors = ["Matt Brooke-Smith"]
7
+ spec.email = ["matt@futureworkshops.com"]
8
+
9
+ spec.summary = %q{Gem to help building App Rail servers using Airtable as a backend}
10
+ spec.homepage = "https://github.com/FutureWorkshops/app_rail-airtable"
11
+ spec.license = "MIT"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+
14
+ spec.metadata["homepage_uri"] = spec.homepage
15
+ spec.metadata["source_code_uri"] = "https://github.com/FutureWorkshops/app_rail-airtable"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.require_paths = ["lib"]
23
+ spec.add_dependency 'activesupport'
24
+ spec.add_dependency 'sinatra'
25
+ spec.add_dependency 'airrecord'
26
+
27
+ spec.add_development_dependency 'rspec'
28
+ spec.add_development_dependency 'rack-test'
29
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "app_rail/airtable"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,49 @@
1
+ require 'airrecord'
2
+
3
+ module AppRail
4
+ module Airtable
5
+ class ApplicationRecord < Airrecord::Table
6
+
7
+ def self.ar_list_item(text:, detail_text:, image: nil, sf_symbol: nil, material_icon: nil)
8
+ define_method(:ar_list_item_as_json) do
9
+ {
10
+ id: self.id,
11
+ text: method_value_or_property(text).to_s,
12
+ detailText: method_value_or_property(detail_text).to_s,
13
+ imageURL: method_value_or_property(image),
14
+ sfSymbolName: sf_symbol,
15
+ materialIconName: material_icon
16
+ }.compact
17
+ end
18
+ end
19
+
20
+ def self.ar_stack(text_items:)
21
+ define_method(:ar_stack_as_json) do
22
+ text_items.map{|ti| {type: :text, label: ti, text: self[ti].to_s} }
23
+ end
24
+ end
25
+
26
+ # Customisable behaviour
27
+
28
+ # Override to provide custom sorting or filtering for index
29
+ def self.index
30
+ all
31
+ end
32
+
33
+ private
34
+
35
+ # TODO: Method call not working?
36
+ def method_value_or_property(name)
37
+ return nil unless name
38
+
39
+ respond_to?(name) ? send(name) : self[name]
40
+ end
41
+
42
+ # size is either :small, :large or :full
43
+ def image(name, index: 0, size: :full)
44
+ self[name][index]["thumbnails"][size.to_s]["url"]
45
+ end
46
+
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,46 @@
1
+ require 'sinatra'
2
+ require 'json'
3
+ require 'active_support'
4
+
5
+ Airrecord.api_key = ENV.fetch("AIRTABLE_API_KEY")
6
+
7
+ class Symbol
8
+
9
+ def pluralize
10
+ ActiveSupport::Inflector.pluralize(self)
11
+ end
12
+
13
+ def classify
14
+ ActiveSupport::Inflector.classify(self)
15
+ end
16
+
17
+ def classify_constantize
18
+ ActiveSupport::Inflector.constantize(classify)
19
+ end
20
+
21
+ end
22
+
23
+ module AppRail
24
+ module Airtable
25
+ class Sinatra < Sinatra::Base
26
+
27
+ def self.resource(name)
28
+ get "/#{name.to_s}" do
29
+ name.classify_constantize.index.map(&:ar_list_item_as_json).to_json
30
+ end
31
+
32
+ get "/#{name.to_s}/:id" do
33
+ name.classify_constantize.find(params['id']).ar_stack_as_json.to_json
34
+ end
35
+
36
+ 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]
41
+ end
42
+ end
43
+
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,5 @@
1
+ module AppRail
2
+ module Airtable
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ require "app_rail/airtable/version"
2
+ require "app_rail/airtable/application_record"
3
+ require "app_rail/airtable/sinatra"
4
+
5
+ module AppRail
6
+ module Airtable
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: app_rail-airtable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Matt Brooke-Smith
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-09-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sinatra
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: airrecord
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'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rack-test
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email:
85
+ - matt@futureworkshops.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".DS_Store"
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - Gemfile.lock
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - app_rail-airtable.gemspec
100
+ - bin/console
101
+ - bin/setup
102
+ - lib/app_rail/airtable.rb
103
+ - lib/app_rail/airtable/application_record.rb
104
+ - lib/app_rail/airtable/sinatra.rb
105
+ - lib/app_rail/airtable/version.rb
106
+ homepage: https://github.com/FutureWorkshops/app_rail-airtable
107
+ licenses:
108
+ - MIT
109
+ metadata:
110
+ homepage_uri: https://github.com/FutureWorkshops/app_rail-airtable
111
+ source_code_uri: https://github.com/FutureWorkshops/app_rail-airtable
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: 2.3.0
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubygems_version: 3.1.6
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: Gem to help building App Rail servers using Airtable as a backend
131
+ test_files: []