-
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
Conversation
airtable.gemspec
Outdated
spec.name = 'airtable' | ||
spec.version = Airtable::VERSION | ||
spec.authors = ['Nathan Esquenazi', 'Alexander Sorokin'] | ||
spec.email = ['[email protected]', '[email protected]'] |
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.
Feel free to put your name here. Nathan wrote original version, so we'll put his name into Readme/Acknowledgements.
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.
@syrnick thx!. Will do it.
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.
Done
lib/airtable/entity/record.rb
Outdated
end | ||
|
||
def __create__(base, name) | ||
res = base.__make_request__(:post, name, { fields: fields }) |
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.
this name
needs escaping equivalent to JS encodeURIComponent (e.g. 3cc21ea). I had hard time finding a better way to do it.
lib/airtable/entity/table.rb
Outdated
end | ||
|
||
def create(fields) | ||
::Airtable::Entity::Record.new(nil, fields: fields).__create__(*@args) |
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.
it would be clearer to spell out *@args
as [@base, @name]
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.
Ok, i will try to change but possible rubocop will not like it.
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.
I see. If it does, lets use a more descriptive name, so it can't be confused with the method arguments. Right now someone might look at this and think that *@args
is the arguments to def create
.
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.
Done
lib/airtable/entity/record.rb
Outdated
self | ||
end | ||
|
||
def __update__(base, name) |
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.
Lets rename name
to table_name
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.
Done
lib/airtable/entity/record.rb
Outdated
end | ||
|
||
def __update__(base, name) | ||
args = [:patch, [name, @id].join('/'), fields: fields] |
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.
Important: name
(i.e. tableName
) must be properly encoded as it may have special characters (e.g. 3cc21ea). Try it with a table that's named Some &.#%?// table
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.
Done
lib/airtable/entity/record.rb
Outdated
end | ||
|
||
class << self | ||
def all(base, name, params) |
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.
It seems that all
and __fetch__
should be class methods on Table, not Record.
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.
No. Table
class is already too big. And better to use such methods in Record
to follow the Ruby/Ruby on Rails way.
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.
sounds good
lib/airtable/entity/record.rb
Outdated
res << new(*args) | ||
end | ||
return unless result['offset'] | ||
__fetch__(base, name, params.merge(offset: result['offset']), res) |
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.
lets add a comment that ruby can easily handle 10k deep stack and that should be plenty to fetch any table.
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.
You mean to add to README?
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.
no, just here. recursion is a bit of a red flag unless the language always does tail call optimization (ruby has an option that's off by default). Hence, it helps to add a comment to the implementation justifying why it shouldn't cause trouble. There are esoteric scenarios where this will blow up. E.g. iterating over a large base (50k records) with page_size set to 1 (really bad idea of course).
README.md
Outdated
Supported Operations: | ||
Get Record (if only RECORD_ID provided) | ||
Get Field (if RECORD_ID and FIELD_ID are provided) | ||
Update Field (if RECORD_ID, FIELD_ID and VALUE are provided) |
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.
Lets make the operation explicit:
airtable get -b Base -t table
airtable get -b Base -t table -f FIELD_NAME
airtable update -b Base -t table -r RECORD_ID -f FIELD_NAME -v newValue
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.
Sure. Will start working on it shortly.
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.
Done
spec.require_paths = ["lib"] | ||
spec.files = `git ls-files -z`.split("\x0") | ||
spec.bindir = 'exe' | ||
spec.executables = `git ls-files -- exe/*`.split("\n").map {|f| File.basename(f)} |
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.
is exe/
better than bin/
?
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.
Yes. More info there - http://bundler.io/blog/2015/03/20/moving-bins-to-exe.html
@@ -2,3 +2,5 @@ source 'https://rubygems.org' | |||
|
|||
# Specify your gem's dependencies in airtable.gemspec | |||
gemspec | |||
|
|||
gem 'pry' |
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.
Is pry needed here?
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.
Its for development purposes. Really helpful. Gemfile is not pushed to the gem file so used only for development environment of gem file only.
lib/airtable/entity/table.rb
Outdated
end | ||
|
||
def select(options = {}) | ||
params = {} |
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.
Lets add support for view
(should be a string if present) and filterByFormula
(should be a string if present) parameters.
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.
Ah, yes it will be added. I want to finished with current codebase and functionality first.
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.
Done
README.md
Outdated
@@ -33,28 +33,38 @@ First, be sure to register for an [airtable](https://airtable.com) account, crea | |||
```ruby | |||
# Pass in api key to client | |||
@client = Airtable::Client.new("keyPCx5W") | |||
# Or if you have AIRTABLE_KEY varibale you can use |
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.
typo: varibale -> variable
is this referring to an environment variable? if so, let's make that clearer
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.
Done
README.md
Outdated
Your API key carries the same privileges as your user account, so be sure to keep it secret! | ||
|
||
### Accessing a Base | ||
|
||
Now we can access any base in our Airsheet account by referencing the [API docs](https://airtable.com/api): |
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.
Airsheet -> Airtable
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.
Done
README.md
Outdated
``` | ||
|
||
We can specify a `sort` order, `limit`, and `offset` as part of our query: | ||
We can specify a `sort` order, `limit`, `max_records` and `offset` as part of our query: |
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.
Maybe take out max_records
from here since it can be confusing to see next to limit
and most people don't need to use it. We can add a note about it below where we say "This executes a variable number of network requests (100 records per batch) to retrieve all records in a sheet."
instead could say:
"This executes a variable number of network requests (by default 100 records per batch) to retrieve all records in a sheet. You can use max_records
to customize the number of records to fetch per batch."
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.
Then I think better to use per_page
instead of max_records
.
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.
README.md
Outdated
@@ -121,6 +121,52 @@ Records can be destroyed using the `destroy` method on a table: | |||
@table.destroy(record) | |||
``` | |||
|
|||
## Command Line Tool | |||
|
|||
This gem is include a very simple command line tool which can show basic functionality of service. |
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.
"This gem includes a simple command line tool which shows the basic functionality of the service."
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.
Done
lib/airtable/entity/base.rb
Outdated
@@ -12,7 +12,7 @@ def table(name) | |||
end | |||
|
|||
def __make_request__(method, path, data) | |||
url = [::Airtable.server_url, @id, path].join('/') | |||
url = [::Airtable.server_url, CGI.escape(@id), path].join('/') |
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".
lib/airtable/entity/table.rb
Outdated
@@ -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 comment
The 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 @name
as encoded might be confusing later on. If someone does p table.name
, they would n't expect the encoding. It'd be better to either:
a) have an accessor url_encoded_name that does encoding on the fly.
b) wrap name access in url_encode e.g. @table_path = [@base, url_encode(@name)]
c) add in instance variable @url_encoded_name = url_encode(@name)
No description provided.