-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New release #27
base: master
Are you sure you want to change the base?
New release #27
Changes from 1 commit
f741381
f889f87
dcc801a
11f0d0b
f33cf3f
4929bb3
ed3bc16
984574c
612eee8
4c7cb62
8102ec6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,11 @@ | ||
AllCops: | ||
Exclude: | ||
- 'spec/**/*' | ||
TargetRubyVersion: 2.1 | ||
TargetRubyVersion: 2.1 | ||
Metrics/LineLength: | ||
Max: 100 | ||
Metrics/ClassLength: | ||
Exclude: | ||
- "lib/airtable/entity/table.rb" | ||
Metrics/AbcSize: | ||
Max: 16 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,8 @@ require 'airtable/version' | |
Gem::Specification.new do |spec| | ||
spec.name = 'airtable' | ||
spec.version = Airtable::VERSION | ||
spec.authors = ['Nathan Esquenazi', 'Alexander Sorokin'] | ||
spec.email = ['[email protected]', '[email protected]'] | ||
spec.authors = ['Nathan Esquenazi', 'Alexander Sorokin', 'Oleksandr Simonov'] | ||
spec.email = ['[email protected]', '[email protected]', '[email protected]'] | ||
spec.summary = 'Easily connect to airtable data using ruby' | ||
spec.description = 'Easily connect to airtable data using ruby with access to all of the airtable features.' | ||
spec.homepage = 'https://github.com/nesquena/airtable-ruby' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
require 'cgi' | ||
module Airtable | ||
module Entity | ||
# Airtable Table entity | ||
|
@@ -6,9 +7,9 @@ class Table | |
DEFAULT_DIRECTION = 'asc'.freeze | ||
|
||
def initialize(base, name) | ||
@name = name | ||
@name = CGI.escape(name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think CGI.escape works - we need to use an equivalent of encodeUriComponent in JS . For example, they differ in handling of spaces - GCI.escape turns them into '+' v.s. %2B. Separately, storing |
||
@base = base | ||
@args = [@base, @name] | ||
@table_path = [@base, @name] | ||
end | ||
|
||
def select(options = {}) | ||
|
@@ -20,24 +21,24 @@ def select(options = {}) | |
end | ||
|
||
def find(id) | ||
args = [@base, [@name, id].join('/')] | ||
::Airtable::Entity::Record.new(id).__fetch__(*args) | ||
table_path = [@base, [@name, id].join('/')] | ||
::Airtable::Entity::Record.new(id).__fetch__(*table_path) | ||
end | ||
|
||
def create(fields) | ||
::Airtable::Entity::Record.new(nil, fields: fields).__create__(*@args) | ||
::Airtable::Entity::Record.new(nil, fields: fields).__create__(*@table_path) | ||
end | ||
|
||
def update(id, fields) | ||
::Airtable::Entity::Record.new(id, fields: fields).__update__(*@args) | ||
::Airtable::Entity::Record.new(id, fields: fields).__update__(*@table_path) | ||
end | ||
|
||
def replace(id, fields) | ||
::Airtable::Entity::Record.new(id, fields: fields).__replace__(*@args) | ||
::Airtable::Entity::Record.new(id, fields: fields).__replace__(*@table_path) | ||
end | ||
|
||
def destroy(id) | ||
::Airtable::Entity::Record.new(id).__destroy__(*@args) | ||
::Airtable::Entity::Record.new(id).__destroy__(*@table_path) | ||
end | ||
|
||
private | ||
|
@@ -51,16 +52,18 @@ def fetch_records(params) | |
end | ||
|
||
def update_default_params(params, options) | ||
params[:fields] = option_value_for(options, :fields) | ||
params[:maxRecords] = option_value_for(options, :max_records) | ||
params[:offset] = option_value_for(options, :offset) | ||
params[:pageSize] = option_value_for(options, :limit) || PAGE_SIZE | ||
params[:fields] = option_value_for(options, :fields) | ||
params[:maxRecords] = option_value_for(options, :max_records) | ||
params[:offset] = option_value_for(options, :offset) | ||
params[:view] = option_value_for(options, :view) | ||
params[:filterByFormula] = option_value_for(options, :filter_by_formula) | ||
params[:pageSize] = option_value_for(options, :limit) || PAGE_SIZE | ||
end | ||
|
||
def validate_params(params) | ||
if params[:fields] && !params[:fields].is_a?(::Array) | ||
raise ::Airtable::FieldsOptionError | ||
end | ||
validate_fields(params[:fields]) | ||
param_not_empty?(params[:view], ::Airtable::ViewOptionError) | ||
param_not_empty?(params[:filterByFormula], ::Airtable::FilterByFormulaOptionError) | ||
raise ::Airtable::LimitOptionError if params[:pageSize].to_i <= 0 | ||
# rubocop:disable all | ||
if params[:maxRecords] && params[:maxRecords].to_i <= 0 | ||
|
@@ -69,6 +72,16 @@ def validate_params(params) | |
# rubocop:enable all | ||
end | ||
|
||
def validate_fields(value) | ||
return if !value || value.is_a?(::Array) | ||
raise ::Airtable::FieldsOptionError | ||
end | ||
|
||
def param_not_empty?(value, klass) | ||
return if !value || (!value.empty? && value.is_a?(::String)) | ||
raise klass | ||
end | ||
|
||
def update_sort_options(params, options) | ||
sort_option = option_value_for(options, :sort) | ||
case sort_option | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@id
shouldn't need escaping for now. It can only be 17-character alphanumeric starting with "app".