-
Notifications
You must be signed in to change notification settings - Fork 74
New release #27
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
Open
simonoff
wants to merge
11
commits into
Airtable:master
Choose a base branch
from
amoniacou:new_release
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
New release #27
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f741381
Refactoring started. Docker support added. Rspec support added.
simonoff f889f87
Rubocop changes
simonoff dcc801a
Sorting by different variants
simonoff 11f0d0b
Make calls more like in Airtable.js
simonoff f33cf3f
Create, Update actions
simonoff 4929bb3
Replace and Destroy methods
simonoff ed3bc16
Binary started
simonoff 984574c
CLI finished. Code refactoring started
simonoff 612eee8
Status error catching
simonoff 4c7cb62
Fixes and new functionality updates
simonoff 8102ec6
Latest fixes
simonoff File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,3 +21,6 @@ tmp | |
| *.a | ||
| mkmf.log | ||
| .DS_Store | ||
| .idea | ||
| .env.docker | ||
| *.log | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| --require spec_helper |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| AllCops: | ||
| Exclude: | ||
| - 'spec/**/*' | ||
| TargetRubyVersion: 2.1 | ||
| Metrics/LineLength: | ||
| Max: 100 | ||
| Metrics/ClassLength: | ||
| Exclude: | ||
| - "lib/airtable/entity/table.rb" | ||
| Metrics/AbcSize: | ||
| Max: 16 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| FROM ruby:2.4.2 | ||
|
|
||
| ENV LIB_HOME /home/lib | ||
|
|
||
| WORKDIR $LIB_HOME |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,3 +2,5 @@ source 'https://rubygems.org' | |
|
|
||
| # Specify your gem's dependencies in airtable.gemspec | ||
| gemspec | ||
|
|
||
| gem 'pry' | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,29 +35,45 @@ First, be sure to register for an [airtable](https://airtable.com) account, crea | |
| @client = Airtable::Client.new("keyPCx5W") | ||
| ``` | ||
|
|
||
| Also you can have `AIRTABLE_KEY` environment variable which is your API key. | ||
|
|
||
| ```ruby | ||
| # if you have AIRTABLE_KEY variable | ||
| @client = Airtable::Client.new | ||
| ``` | ||
|
|
||
| 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 Airtable account by referencing the [API docs](https://airtable.com/api): | ||
|
|
||
| ```ruby | ||
| # Pass in the base id | ||
| @base = @client.table("appPo84QuCy2BPgLk") | ||
| ``` | ||
|
|
||
| ### Accessing a Table | ||
|
|
||
| Now we can access any table in our Airsheet account by referencing the [API docs](https://airtable.com/api): | ||
| Now we can access any table in our Airtable account by referencing the [API docs](https://airtable.com/api): | ||
|
|
||
| ```ruby | ||
| # Pass in the app key and table name | ||
| @table = @client.table("appPo84QuCy2BPgLk", "Table Name") | ||
| # Pass in the table name | ||
| @table = @base.table("Table Name") | ||
| ``` | ||
|
|
||
| ### Querying Records | ||
| ### Batch Querying All Records | ||
|
|
||
| Once you have access to a table from above, we can query a set of records in the table with: | ||
|
|
||
| ```ruby | ||
| @records = @table.records | ||
| @records = @table.select | ||
| ``` | ||
|
|
||
| We can specify a `sort` order, `limit`, and `offset` as part of our query: | ||
| We can specify a `sort` order, `per_page`, `max_records` and `offset` as part of our query: | ||
|
|
||
| ```ruby | ||
| @records = @table.records(:sort => ["Name", :asc], :limit => 50) | ||
| @records = @table.records(:sort => ["Name", :asc], :page_size => 50) | ||
| @records # => [#<Airtable::Record :name=>"Bill Lowry", :email=>"[email protected]">, ...] | ||
| @records.offset #=> "itrEN2TCbrcSN2BMs" | ||
| ``` | ||
|
|
@@ -72,16 +88,6 @@ This will return the records based on the query as well as an `offset` for the n | |
| @bill[:email] # => "[email protected]" | ||
| ``` | ||
|
|
||
| Note that you can only request a maximimum of 100 records in a single query. To retrieve more records, use the "batch" feature below. | ||
|
|
||
| ### Batch Querying All Records | ||
|
|
||
| We can also query all records in the table through a series of batch requests with: | ||
|
|
||
| ```ruby | ||
| @records = @table.all(:sort => ["Name", :asc]) | ||
| ``` | ||
|
|
||
| This executes a variable number of network requests (100 records per batch) to retrieve all records in a sheet. | ||
|
|
||
| ### Finding a Record | ||
|
|
@@ -121,6 +127,58 @@ Records can be destroyed using the `destroy` method on a table: | |
| @table.destroy(record) | ||
| ``` | ||
|
|
||
| ## Command Line Tool | ||
|
|
||
| This gem includes a simple command line tool which shows the basic functionality of the service. | ||
|
|
||
| ``` | ||
| $ airtable | ||
| Usage: airtable operation options | ||
|
|
||
| Common options: | ||
| -k, --api_key=KEY Airtable API key | ||
| -t, --table NAME Table Name | ||
| -b, --base BASE_ID Base ID | ||
| -r, --record RECORD_ID Record ID | ||
| -f, --field FIELD_NAME Field name to update or read | ||
| -v, --value VALUE Field value for update | ||
|
|
||
| Supported Operations: | ||
| get - Get Record/Field | ||
| update - Update Field | ||
|
|
||
| Examples: | ||
| airtable get -B Base -t Table | ||
| airtable get -B Base -t Table -r RECORD_ID | ||
| airtable get -B Base -t Table -f FIELD_NAME | ||
| airtable get -B Base -t Table -f FIELD_NAME -r RECORD_ID | ||
| airtable update -b Base -t table -r RECORD_ID -f FIELD_NAME -v newValue | ||
|
|
||
| -h, --help Show this message | ||
| --version Show version | ||
| ``` | ||
|
|
||
| ### Get record's JSON | ||
|
|
||
| ``` | ||
| $ airtable get -b base_id -t Table -r record_id | ||
| {"id":"record_id","fields":{...},"createdTime":"2015-11-11 23:05:58 UTC"} | ||
| ``` | ||
|
|
||
| ### Get record's field value | ||
|
|
||
| ``` | ||
| $ airtable get -b base_id -t Table -r record_id -f field_name | ||
| FIELD_VALUE | ||
| ``` | ||
|
|
||
| ### Update record's field value | ||
|
|
||
| ``` | ||
| $ airtable update -b base_id -t Table -r record_id -f field_name -v NEW_VALUE | ||
| OK | ||
| ``` | ||
|
|
||
| ## Contributing | ||
|
|
||
| 1. Fork it ( https://github.com/nesquena/airtable-ruby/fork ) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,17 @@ | ||
| require "bundler/gem_tasks" | ||
| require 'rake/testtask' | ||
| require 'bundler' | ||
| Bundler.setup | ||
| Bundler::GemHelper.install_tasks | ||
|
|
||
| Rake::TestTask.new do |t| | ||
| t.libs << 'test' | ||
| t.pattern = "test/*_test.rb" | ||
| require 'rspec/core/rake_task' | ||
|
|
||
| desc 'Run all tests' | ||
| RSpec::Core::RakeTask.new(:spec) do |t| | ||
| t.ruby_opts = %w[-w] | ||
| end | ||
|
|
||
| desc 'Run RuboCop on the lib directory' | ||
| task :rubocop do | ||
| sh 'bundle exec rubocop lib' | ||
| end | ||
|
|
||
| task default: %i[spec rubocop] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,28 +1,29 @@ | ||
| # coding: utf-8 | ||
| lib = File.expand_path('../lib', __FILE__) | ||
| $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) | ||
| 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.summary = %q{Easily connect to airtable data using ruby} | ||
| spec.description = %q{Easily connect to airtable data using ruby with access to all of the airtable features.} | ||
| spec.homepage = "https://github.com/nesquena/airtable-ruby" | ||
| spec.license = "MIT" | ||
| spec.name = 'airtable' | ||
| spec.version = Airtable::VERSION | ||
| 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' | ||
| spec.license = 'MIT' | ||
|
|
||
| spec.files = `git ls-files -z`.split("\x0") | ||
| spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } | ||
| spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) | ||
| 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)} | ||
|
Contributor
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. is
Author
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. Yes. More info there - http://bundler.io/blog/2015/03/20/moving-bins-to-exe.html |
||
| spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) | ||
| spec.require_paths = ['lib'] | ||
| spec.required_ruby_version = '>= 2.0.0' | ||
|
|
||
| spec.add_dependency "httparty", "~> 0.14.0" | ||
| spec.add_dependency "activesupport", ">= 3.0" | ||
|
|
||
| spec.add_development_dependency "bundler", "~> 1.6" | ||
| spec.add_development_dependency "rake" | ||
| spec.add_development_dependency "minitest", "~> 5.6.0" | ||
| spec.add_development_dependency "webmock", "~> 2.1.0" | ||
| spec.add_development_dependency 'bundler', '~> 1.6' | ||
| spec.add_development_dependency 'rake' | ||
| spec.add_development_dependency 'rspec', '~> 3.7' | ||
| spec.add_development_dependency 'rubocop', '~> 0.51' | ||
| spec.add_development_dependency 'simplecov', '~> 0.15' | ||
| spec.add_development_dependency 'vcr', '~> 4.0' | ||
| spec.add_development_dependency 'webmock', '~> 3.1' | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| version: '2.1' | ||
| volumes: | ||
| app-gems: | ||
| driver: local | ||
| services: | ||
| lib: | ||
| build: | ||
| context: . | ||
| dockerfile: Dockerfile | ||
| env_file: | ||
| - .env.docker | ||
| volumes: | ||
| - app-gems:/usr/local/bundle | ||
| - .:/home/lib | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| #!/usr/bin/env ruby | ||
| $stderr.sync = true | ||
| require 'airtable' | ||
| require 'airtable/cli' | ||
| ::Airtable::CLI.new(ARGV).start |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,41 @@ | ||
| require 'httparty' | ||
| require 'delegate' | ||
| require 'active_support/core_ext/hash' | ||
|
|
||
| require 'airtable/version' | ||
| require 'airtable/resource' | ||
| require 'airtable/record' | ||
| require 'airtable/record_set' | ||
| require 'airtable/table' | ||
| require 'logger' | ||
|
|
||
| # Airtable wrapper library | ||
| module Airtable | ||
| class << self | ||
| DEFAULT_URL = 'https://api.airtable.com/v0'.freeze | ||
| attr_writer :log_path | ||
|
|
||
| def debug? | ||
| !ENV['DEBUG'].nil? | ||
| end | ||
|
|
||
| def log_path | ||
| @log_path ||= 'airtable.log' | ||
| end | ||
|
|
||
| def logger | ||
| @logger ||= ::Logger.new(@log_path) | ||
| end | ||
|
|
||
| def server_url | ||
| @server_url ||= ENV.fetch('AIRTABLE_ENDPOINT_URL') { DEFAULT_URL } | ||
| end | ||
|
|
||
| def reset! | ||
| @log_path = nil | ||
| @logger = nil | ||
| @server_url = nil | ||
| end | ||
| end | ||
| end | ||
|
|
||
| require 'airtable/response' | ||
| require 'airtable/request' | ||
| require 'airtable/entity' | ||
| require 'airtable/client' | ||
| require 'airtable/error' | ||
|
|
||
| # require 'airtable/resource' | ||
| # require 'airtable/record' | ||
| # require 'airtable/record_set' |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.