quickbase_record 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +133 -132
- data/lib/quickbase_record/version.rb +1 -1
- data/quickbase_record.gemspec +2 -2
- metadata +4 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66af6aaf85c6d5350a049cc7a4323b54199627d9
|
4
|
+
data.tar.gz: 3c9cba75db0cd942cd63add02c5d7a77a09aaaaa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3e8a79ff986d7003f31ee40d38d719f01c1be517d86f08b644f1afe245af2165a70d03bd4b64b1ca9ed875b04516f7bb548fbbaf87f623d98c1b17912d0a8ed
|
7
|
+
data.tar.gz: 92c863cc14b32b7b170d56b2b103f5dc5825f1a004f84919fe063246e41f2fe5237acd73debe07afee6edf1aea147710fadf8096090c2ac01f53776b293dbfed
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# QuickbaseRecord
|
2
2
|
|
3
|
-
QuickbaseRecord is a baller ActiveRecord-style ORM for
|
3
|
+
QuickbaseRecord is a baller ActiveRecord-style ORM/API client for QuickBase.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -18,29 +18,30 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
$ gem install quickbase_record
|
20
20
|
|
21
|
-
##
|
22
|
-
|
23
|
-
* [Methods](#available-methods)
|
21
|
+
## Setup
|
24
22
|
|
25
23
|
### Initialize the API Client
|
26
|
-
|
24
|
+
First you'll need to configure QuickbaseRecord with your app's realm name (realm-name.quickbase.com) and provide a valid username, password, and application token (if applicable). Alternatively, you can supply a user token. This can be done in a single initializer file with a call to `QuickbaseRecord.configure`.
|
27
25
|
|
28
26
|
```
|
29
27
|
# config/initializers/quickbase_record.rb
|
30
28
|
|
31
29
|
QuickbaseRecord.configure do |config|
|
32
30
|
config.realm = "quickbase_app_realm_name"
|
31
|
+
config.token = "quickbase_app_token_if_applicable"
|
33
32
|
config.username = "valid_username"
|
34
33
|
config.password = "valid_password"
|
35
|
-
|
34
|
+
|
35
|
+
# or, instead of username/password:
|
36
|
+
|
37
|
+
config.usertoken = "quickbase_user_token"
|
36
38
|
end
|
37
39
|
```
|
38
40
|
|
39
41
|
### Include it in your Class
|
40
|
-
|
42
|
+
Now you can simply `include QuickbaseRecord::Model` in a class representing a QuickBase table and call the `.define_fields` method to supply the table's Database ID and a mapping of desired field names => QuickBase Field IDs.
|
41
43
|
|
42
|
-
|
43
|
-
.define_fields follows a similar pattern to ActiveRecord migrations. It takes a block where data types and field names are definied with a corresponding QuickBase FID.
|
44
|
+
`.define_fields` follows a similar pattern to ActiveRecord migrations. It takes a block where data types and field names are defined with a corresponding QuickBase Field ID.
|
44
45
|
|
45
46
|
```
|
46
47
|
# app/models/post.rb
|
@@ -50,6 +51,7 @@ Simply `include QuickbaseRecord::Model` in your class and use the `.define_field
|
|
50
51
|
|
51
52
|
define_fields do |t|
|
52
53
|
t.dbid 'abcde12345'
|
54
|
+
t.date :date_created, 1, :read_only
|
53
55
|
t.number :id, 3, :primary_key
|
54
56
|
t.string :content, 7
|
55
57
|
t.string :author, 8
|
@@ -62,192 +64,191 @@ Simply `include QuickbaseRecord::Model` in your class and use the `.define_field
|
|
62
64
|
```
|
63
65
|
|
64
66
|
### .define_fields
|
65
|
-
.define_fields(:field_name, fid, *options)
|
66
67
|
|
67
|
-
|
68
|
+
`.define_fields` will create attr_accessors for all fields and parse API responses to match the configured data type. Note that values will **not** be converted to anything when sending API calls.
|
68
69
|
|
69
|
-
|
70
|
-
- The dbid for the QuickBase table
|
71
|
-
- **Does not take multiple arguments, only a string of the dbid**
|
70
|
+
The following configuration options/data types are supported:
|
72
71
|
|
72
|
+
* **dbid** *required
|
73
|
+
- The Database ID for the QuickBase table
|
74
|
+
- **Does not accept multiple arguments, only a string of the Database ID**
|
73
75
|
* **string**
|
74
76
|
- All values are converted to a String
|
75
|
-
|
76
77
|
* **number**
|
77
|
-
- All values are converted to a Numeric (
|
78
|
+
- All values are converted to a Numeric (ints or floats)
|
78
79
|
* **date**
|
79
|
-
- All values are converted to a string representation of the date value: "07/30/2015"
|
80
|
+
- All values are converted to a string representation of the date value: ex: "07/30/2015". Does not currently work for Date/Time conversion, so you'll have to pull in Date/Time fields as strings and parse them yourself. Sorry.
|
80
81
|
* **boolean**
|
81
82
|
- All values are converted to true or false (QuickBase returns "1" and "0")
|
82
83
|
* **file_attachment**
|
83
|
-
- Doesn't really do anything, only makes you feel better :) File attachments are explained below.
|
84
|
+
- Doesn't really do anything, only makes you feel better :) File attachments are explained [below](#file-attachments).
|
84
85
|
|
85
86
|
Additional options may be added to field definitions:
|
86
87
|
|
87
|
-
* **:primary_key**
|
88
|
-
-
|
88
|
+
* **:primary_key** *required
|
89
|
+
- Pretty obvious.
|
89
90
|
* **:read_only**
|
90
|
-
- Fields marked as :read_only will not
|
91
|
+
- Fields marked as :read_only will not be sent along 'write' API requests -- #save, #update_attributes, #create, and .save_collection.
|
91
92
|
- Useful for formula/lookup/other fields in your QuickBase table that you can't write to.
|
92
93
|
|
93
94
|
|
94
|
-
**IMPORTANT: You must supply a "dbid" data type and mark a single field as :primary_key
|
95
|
+
**IMPORTANT: You must supply a "dbid" data type and mark a single field as :primary_key. Weird shit can happen if you don't. Eventually I'll throw some errors if they're missing, but for now it's the wild west.**
|
96
|
+
|
97
|
+
## Methods
|
98
|
+
|
99
|
+
### Query for Records
|
100
|
+
|
101
|
+
* **.find(id)**
|
102
|
+
```ruby
|
103
|
+
Post.find(params[:id])
|
104
|
+
Post.find(3123)
|
105
|
+
```
|
106
|
+
- Query for a specific QuickBase record by it's primary key.
|
107
|
+
- Returns a single object
|
108
|
+
|
109
|
+
* **.where(query_hash OR string in QuickBase query format)**
|
110
|
+
```ruby
|
111
|
+
Post.where(author: 'Cullen Jett')
|
112
|
+
```
|
113
|
+
- Query QuickBase by any field name defined in your class' field mapping
|
114
|
+
- Returns an array of objects
|
115
|
+
|
116
|
+
- Multiple field_name/value pairs are joined with 'AND'
|
117
|
+
```ruby
|
118
|
+
Post.where(id: 1, author: 'Cullen Jett')
|
119
|
+
# ^ is parsed to the QuickBase format: {'3'.EX.'1'}AND{'8'.EX.'Cullen Jett'}
|
120
|
+
```
|
121
|
+
|
122
|
+
- Values in an array are joined with 'OR'
|
123
|
+
```ruby
|
124
|
+
Post.where(author: ['Cullen Jett', 'Socrates'])
|
125
|
+
# {'8'.EX.'Cullen Jett'}OR{'8'.EX.'Socrates'}
|
126
|
+
```
|
127
|
+
|
128
|
+
- To use a comparator other than 'EX', pass the value as another hash with the key as the comparator
|
129
|
+
```ruby
|
130
|
+
Post.where(author: {XEX: 'Cullen Jett'})
|
131
|
+
# {'8'.XEX.'Cullen Jett'}
|
132
|
+
|
133
|
+
Post.where(date_created: {OBF: 'today'})
|
134
|
+
# {'1'.OBF.'today'}
|
135
|
+
```
|
136
|
+
|
137
|
+
- Also accepts a string in the standard QuickBase query format. This way works with both field names or Field IDs.
|
138
|
+
```ruby
|
139
|
+
Post.where("{'3'.EX.'1'}")
|
140
|
+
Post.where("{author.XEX.'Cullen Jett'}")
|
141
|
+
```
|
142
|
+
|
143
|
+
* **.batch_where(attributes_hash, count=1000)**
|
144
|
+
- Same as `.where`, but queries in batches of {count} since QuickBase has a limit on how much data you can get back in one go. This bad boy will call multiple queries and then concatenate all of the responses in a single array.
|
145
|
+
```ruby
|
146
|
+
Post.batch_where({date_created: ['today', 'yesterday']}, 5000)
|
147
|
+
```
|
148
|
+
|
149
|
+
* **.qid(id)**
|
150
|
+
- Accepts a QID (QuickBase report ID)
|
151
|
+
- Returns an array of objects
|
152
|
+
```ruby
|
153
|
+
Post.qid(1)
|
154
|
+
```
|
155
|
+
|
156
|
+
#### Query Options (clist, slist, options)
|
157
|
+
To query using the QuickBase query options such as 'clist', 'slist', or 'options', include :query_options as a key and a hash of `option_property: value` as values. An example is in order:
|
158
|
+
```ruby
|
159
|
+
Post.where(author: ['Cullen Jett', 'Socrates'], query_options: {clist: 'id.author', slist: 'author', options: 'num-1'})
|
160
|
+
```
|
161
|
+
|
162
|
+
#### Broken Query?
|
163
|
+
If you want to see the QuickBase query string output of a `.where()` query hash you can pass your query hash to the `.build_query()` method and it will return the QuickBase query.
|
95
164
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
If you want to see the QuickBase query string output of a .where() argument you can pass your query hash to the .build_query() method and it will return the QuickBase query.
|
100
|
-
|
101
|
-
```
|
102
|
-
Post.build_query(author: 'Cullen', title: 'Some Title')
|
103
|
-
=> "{'8'.EX.'Cullen'}AND{'9'.EX.'Some Title'}"
|
165
|
+
```ruby
|
166
|
+
Post.build_query(author: 'Cullen', title: 'Some Title')
|
167
|
+
=> "{'8'.EX.'Cullen'}AND{'9'.EX.'Some Title'}"
|
104
168
|
```
|
105
169
|
|
106
|
-
|
170
|
+
#### AdvantageQuickbase
|
171
|
+
QuickBaseRecord is built on top of the [AdvantageQuickbase gem](https://github.com/AdvantageIntegratedSolutions/Quickbase-Gem). You can access the underlying instance of the AdvantageQuickbase client with `.qb_client`. This property lives on both the class and on any instance of that class. To access the dbid for the table, call .dbid on the class.
|
107
172
|
|
108
|
-
```
|
173
|
+
```ruby
|
109
174
|
Post.qb_client.do_query(...)
|
110
175
|
@post = Post.new(...)
|
111
176
|
@post.qb_client.edit_record(self.class.dbid, self.id, {5 => 'Something', 6 => 'Something else'})
|
112
177
|
```
|
113
178
|
|
114
|
-
##
|
179
|
+
## Create and Update Records
|
115
180
|
* **.create(attributes_hash)**
|
116
|
-
|
117
|
-
- Assigns the returned object it's new ID
|
118
|
-
```
|
181
|
+
```ruby
|
119
182
|
Post.create(content: 'Amazing post content', author: 'Cullen Jett')
|
120
183
|
```
|
184
|
+
- Instantiate *and* save a new object with the given attributes
|
185
|
+
- Assigns the returned object it's new Record ID
|
121
186
|
|
122
187
|
* **.save_collection(array_of_objects)**
|
123
|
-
|
124
|
-
- Uses API_ImportFromCSV under the hood, so it will edit a record if it has a record ID or create one if not.
|
125
|
-
- Returns array of record IDs
|
126
|
-
```
|
188
|
+
```ruby
|
127
189
|
@post1 = Post.new(content: 'Amazing post content', author: 'Cullen Jett')
|
128
190
|
@post2 = Post.find(123)
|
129
191
|
|
130
192
|
Post.save_collection([@post1, @post2])
|
131
193
|
```
|
132
|
-
|
133
|
-
|
134
|
-
-
|
135
|
-
-
|
136
|
-
```
|
137
|
-
Post.find(params[:id])
|
138
|
-
```
|
139
|
-
|
140
|
-
* **.where(attributes_hash OR string)**
|
141
|
-
- Query QuickBase by any field name defined in your class' field mapping
|
142
|
-
- Returns an array of objects
|
143
|
-
```
|
144
|
-
Post.where(author: 'Cullen Jett').first
|
145
|
-
```
|
146
|
-
|
147
|
-
- Multiple field_name/value pairs are joined with 'AND'
|
148
|
-
```
|
149
|
-
Post.where(id: 1, author: 'Cullen Jett')
|
150
|
-
# {'3'.EX.'1'}AND{'8'.EX.'Cullen Jett'}
|
151
|
-
```
|
152
|
-
|
153
|
-
- Values in an array are joined with 'OR'
|
154
|
-
```
|
155
|
-
Post.where(author: ['Cullen Jett', 'Socrates'])
|
156
|
-
# {'8'.EX.'Cullen Jett'}OR{'8'.EX.'Socrates'}
|
157
|
-
|
158
|
-
Post.where({ [author: 'Cullen Jett', id: 123] })
|
159
|
-
# {'8'.EX.'Cullen Jett'}OR{'3'.EX.'123'}
|
160
|
-
```
|
161
|
-
|
162
|
-
- To use a comparator other than 'EX' pass the value as another hash with the key as the comparator
|
163
|
-
```
|
164
|
-
Post.where(author: {XEX: 'Cullen Jett'})
|
165
|
-
# {'8'.XEX.'Cullen Jett'}
|
166
|
-
```
|
167
|
-
|
168
|
-
- Combine arrays and hashes to build more complex queries
|
169
|
-
```
|
170
|
-
Post.where(id: [{XEX: 123}, {OBF: 'today'}])
|
171
|
-
# "{'3'.XEX.'123'}OR{'3'.OBF.'today'}"
|
172
|
-
|
173
|
-
Post.where(id: {XEX: 123, OAF: 'today'})
|
174
|
-
# "{'3'.XEX.'123'}AND{'3'.OAF.'today'}"
|
175
|
-
```
|
176
|
-
|
177
|
-
- Also accepts a string in the standard QuickBase query format
|
178
|
-
* Works with field names or FIDs
|
179
|
-
```
|
180
|
-
Post.where("{'3'.EX.'1'}")
|
181
|
-
Post.where("{author.XEX.'Cullen Jett'}")
|
182
|
-
```
|
183
|
-
|
184
|
-
* **Query Options (clist, slist, options)** To query using the QuickBase query options such as 'clist', 'slist', or 'options', include :query_options as a hash of option_property: value
|
185
|
-
```
|
186
|
-
Post.where(author: ['Cullen Jett', 'Socrates'], query_options: {clist: 'id.author', slist: 'author', options: 'num-1'})
|
187
|
-
```
|
188
|
-
|
189
|
-
* **.batch_where(attributes_hash, count=1000)**
|
190
|
-
- Same as .where, but queries in batches of {count}
|
191
|
-
```
|
192
|
-
Post.where({date_created: ['today', 'yesterday']}, 500) # note the necessary "{}" around the attributes_hash
|
193
|
-
```
|
194
|
-
|
195
|
-
* **.qid(id)**
|
196
|
-
- Accepts a QID (QuickBase report ID)
|
197
|
-
- Returns an array of objects
|
198
|
-
```
|
199
|
-
Post.qid(1)
|
200
|
-
```
|
194
|
+
- Save an array of objects (of the same class)
|
195
|
+
- Uses API_ImportFromCSV under the hood, so it will edit a record if it has a record ID or create one if not.
|
196
|
+
- Returns an array of Record IDs
|
197
|
+
- **IMPORTANT: make sure all of the objects have the same QuickBase properties (even if they have empty values). The AdvantageQuickbase gem will use the first object in the array to generate the clist.**
|
201
198
|
|
202
199
|
* **#save**
|
203
|
-
|
204
|
-
- Returns the object (if #save created a record in QuickBase the the returned object will now have an ID)
|
205
|
-
```
|
200
|
+
```ruby
|
206
201
|
@post = Post.new(content: 'Amazing post content', author: 'Cullen Jett')
|
207
202
|
@post.save # => <Post: @id: 1, @content: 'Amazing post content', @author: 'Cullen Jett'
|
208
203
|
|
209
204
|
@post.author = 'Socrates'
|
210
205
|
@post.save # => <Post: @id: 1, @content: 'Amazing post content', @author: 'Socrates'
|
211
206
|
```
|
207
|
+
- Creates a new record in QuickBase for objects that don't have an ID *or* edits the corresponding QuickBase record if the object already has an ID
|
208
|
+
- Returns the object (if #save created a record in QuickBase the the returned object will now have an ID)
|
212
209
|
|
213
|
-
* **#
|
214
|
-
|
215
|
-
|
210
|
+
* **#update_attributes(attributes_hash)**
|
211
|
+
```ruby
|
212
|
+
@post = Post.where(author: 'Cullen Jett').first
|
213
|
+
@post.update_attributes(author: 'Socrates', content: 'Something enlightening...') # => <Post: @id: 1, @author: 'Socrates', @content: 'Something enlightening...'
|
216
214
|
```
|
215
|
+
- **IMPORTANT: Updates *and* saves the object with the new attributes**
|
216
|
+
- Only sends the passed in attributes as arguments to API_AddRecord or API_EditRecord (depending on whether the object has an ID or not)
|
217
|
+
- Returns the object
|
218
|
+
|
219
|
+
## Delete Records
|
220
|
+
* **#delete**
|
221
|
+
```ruby
|
217
222
|
@post = Post.find(1)
|
218
223
|
@post.delete
|
219
224
|
```
|
225
|
+
- Delete the corresponding record in QuickBase
|
226
|
+
- It returns the object if successful or `false` if unsuccessful
|
220
227
|
|
221
228
|
* **.purge_records(attributes_hash OR QID)**
|
222
|
-
|
223
|
-
- Returns an array of deleted rids
|
224
|
-
- **CAUTION** If you do not supply a query parameter, this call will delete ALL of the records in the table.
|
225
|
-
```
|
229
|
+
```ruby
|
226
230
|
Post.purge_records(name: 'Cullen Jett') # attributes hash
|
227
231
|
or
|
228
232
|
Post.purge_records(9) # QID
|
229
233
|
|
230
234
|
=> [1,2,3,4,5...]
|
231
235
|
```
|
236
|
+
- Delete ALL records that match the attributes hash or are in the record corresponding to the QID argument
|
237
|
+
- Returns an array of deleted rids
|
238
|
+
- **CAUTION** If you do not supply a query parameter, this call will delete ALL of the records in the table.
|
239
|
+
|
232
240
|
|
233
|
-
* **#update_attributes(attributes_hash)**
|
234
|
-
- **IMPORTANT: Updates *and* saves the object with the new attributes**
|
235
|
-
- Only sends the passed in attributes as arguments to API_AddRecord or API_EditRecord (depending on whether the object has an ID or not)
|
236
|
-
- Returns the object
|
237
|
-
```
|
238
|
-
@post = Post.where(author: 'Cullen Jett').first
|
239
|
-
@post.update_attributes(author: 'Socrates', content: 'Something enlightening...') # => <Post: @id: 1, @author: 'Socrates', @content: 'Something enlightening...'
|
240
|
-
```
|
241
241
|
|
242
|
+
## Misc Methods
|
242
243
|
* **#assign_attributes(attributes_hash)**
|
243
|
-
|
244
|
-
- Useful for assigning multiple attributes at once, otherwise you could use the field name's attr_accessor to change a single attribute.
|
245
|
-
- Returns the object
|
246
|
-
```
|
244
|
+
```ruby
|
247
245
|
@post = Post.where(author: 'Cullen Jett').first
|
248
246
|
@post.assign_attributes(author: 'Socrates', content: 'Something enlightening...')
|
249
247
|
@post.save
|
250
248
|
```
|
249
|
+
- Only changes the objects attributes in memory (i.e. does not save to QuickBase)
|
250
|
+
- Useful for assigning multiple attributes at once, otherwise you could use the field name's attr_accessor to change a single attribute.
|
251
|
+
- Returns the object
|
251
252
|
|
252
253
|
* **.qb_client and #qb_client**
|
253
254
|
- Access the quickbase API client (advantage_quickbase gem) directly
|
@@ -255,7 +256,7 @@ You can also access the underlying instance of the AdvantageQuickbase client wit
|
|
255
256
|
## File Attachments
|
256
257
|
When ***creating*** an object with a field of type 'file attachment', you must assign it as hash with :name and :file as keys.
|
257
258
|
After the object is ***saved*** that field will then become a new hash with :filename and :url as keys.
|
258
|
-
```
|
259
|
+
```ruby
|
259
260
|
@post = Post.new(attachment: {name: 'Test File Name', file: 'path/to/your/file OR file contents'})
|
260
261
|
@post.save
|
261
262
|
@post.attachment => {filename: 'Test File Name', url: 'https://realm.quickbase.com/up/abcdefg/Test%20File%20Name'}
|
data/quickbase_record.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = QuickbaseRecord::VERSION
|
9
9
|
spec.authors = ["Cullen Jett"]
|
10
10
|
spec.email = ["cullenjett@gmail.com"]
|
11
|
-
spec.summary = "An
|
12
|
-
spec.description = "QuickbaseRecord is a baller ActiveRecord-style ORM for
|
11
|
+
spec.summary = "An ORM-style API client for QuickBase."
|
12
|
+
spec.description = "QuickbaseRecord is a baller ActiveRecord-style ORM/API client for QuickBase."
|
13
13
|
spec.homepage = "https://github.com/cullenjett/quickbase_record"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quickbase_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cullen Jett
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -94,8 +94,7 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '4.0'
|
97
|
-
description: QuickbaseRecord is a baller ActiveRecord-style ORM for
|
98
|
-
QuickBase platform as a database for Ruby or Ruby on Rails applications.
|
97
|
+
description: QuickbaseRecord is a baller ActiveRecord-style ORM/API client for QuickBase.
|
99
98
|
email:
|
100
99
|
- cullenjett@gmail.com
|
101
100
|
executables: []
|
@@ -153,7 +152,7 @@ rubyforge_project:
|
|
153
152
|
rubygems_version: 2.4.6
|
154
153
|
signing_key:
|
155
154
|
specification_version: 4
|
156
|
-
summary: An
|
155
|
+
summary: An ORM-style API client for QuickBase.
|
157
156
|
test_files:
|
158
157
|
- spec/fakes/classroom_fake.rb
|
159
158
|
- spec/fakes/student_fake.rb
|