Skip to content
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

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

New release #27

wants to merge 11 commits into from

Conversation

simonoff
Copy link

No description provided.

airtable.gemspec Outdated
spec.name = 'airtable'
spec.version = Airtable::VERSION
spec.authors = ['Nathan Esquenazi', 'Alexander Sorokin']
spec.email = ['nesquena@gmail.com', 'syrnick@gmail.com']
Copy link
Contributor

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.

Copy link
Author

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

end

def __create__(base, name)
res = base.__make_request__(:post, name, { fields: fields })
Copy link
Contributor

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.

end

def create(fields)
::Airtable::Entity::Record.new(nil, fields: fields).__create__(*@args)
Copy link
Contributor

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]

Copy link
Author

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.

Copy link
Contributor

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

self
end

def __update__(base, name)
Copy link
Contributor

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

end

def __update__(base, name)
args = [:patch, [name, @id].join('/'), fields: fields]
Copy link
Contributor

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

end

class << self
def all(base, name, params)
Copy link
Contributor

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.

Copy link
Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good

res << new(*args)
end
return unless result['offset']
__fetch__(base, name, params.merge(offset: result['offset']), res)
Copy link
Contributor

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.

Copy link
Author

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?

Copy link
Contributor

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)
Copy link
Contributor

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

Copy link
Author

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.

Copy link
Author

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)}
Copy link
Contributor

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/ ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -2,3 +2,5 @@ source 'https://rubygems.org'

# Specify your gem's dependencies in airtable.gemspec
gemspec

gem 'pry'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is pry needed here?

Copy link
Author

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.

end

def select(options = {})
params = {}
Copy link
Contributor

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.

Copy link
Author

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.

Copy link
Author

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
Copy link

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

Copy link
Author

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):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Airsheet -> Airtable

Copy link
Author

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:
Copy link

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."

Copy link
Author

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.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wait that's a good point. I just realized that in the REST API (and Javascript library) these are called maxRecords (instead of limit) and pageSize (instead of max_records)

screen shot 2018-01-05 at 8 44 42 am

This seems like a good opportunity to make the ruby library consistent with those

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.
Copy link

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."

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -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('/')
Copy link
Contributor

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".

@@ -6,9 +7,9 @@ class Table
DEFAULT_DIRECTION = 'asc'.freeze

def initialize(base, name)
@name = name
@name = CGI.escape(name)
Copy link
Contributor

@syrnick syrnick Jan 10, 2018

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 .

3cc21ea

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants