quickbase_record 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OWYxNzdkYjc3ZjQxY2QxM2JhNmE3ZWEzNWU5YTU0ZDhmYWQ4YTY3YQ==
4
+ NTQ2NTdmMWRhOTIyN2U2MjZkODJlODVmNjZjZGUwYmNmMTM4NGE0Mg==
5
5
  data.tar.gz: !binary |-
6
- NTgwYzI4Njk3Y2IxZWZhMzFkMWYxNjY3YzNjNjUxZTY5M2UxYzg5NA==
6
+ M2U4N2Q3MmNhNjcyMzI4ZmRiNmU4NGMwNGIzZTZmNmQ0Y2E1ZTgxNQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MGYwNzM3N2JjM2ViZjUwZTI0MjZhYTkyMDBlMmM0MWU0MjhlMmYwNTU1MmFh
10
- ZTU0N2EyYzc0YmYyMGZmYzZhOTkxYmJiYTQ5NzljNDkwYzYyNjFmYjJmZjlh
11
- OWQwNjQ2ZjQwMjg3ZmMwZDI1N2U0ODVmMmYzM2VmYzM2MjAxNTc=
9
+ OGQ2YThlZDk3MGYxMWRlNmM4NWUyYTliZjAwODM1YTk2Zjc0NzVlM2JjNjg5
10
+ M2M0MDE2YWJmZTFmMzgxZjgxODNlZjI5YmRhZTRkYjVmM2U1ZjljZTY3MWI2
11
+ NGE2Yzc5NjU4MjIxZTIyZmZhMmFmOGI3Mzk3NjcwNzU0Yjk1MWQ=
12
12
  data.tar.gz: !binary |-
13
- NjQ4Nzc5Mjk2NTQwMTYxYjczOGQ3ZjcwMDEzYmQyNDI5ZmM3NjViZTYzMjZk
14
- NzU0YmY3NzEwYzgxMDgxZWFlNDY4NTNlOGZhNTg4OTg2MThlYjZmZTdiZDQ3
15
- MGNkNTVlZjVhY2Y1ZmUyZGU1NjlhYTFlOWVmNjgzNWU1Y2U2MGY=
13
+ NjQzZDNkYjFjZDhjZjY3NDQ1NTg1MmM4MDkwMWM5ZWJkYTI4MTI2MGQ4Mzc1
14
+ ZjUyMGFkMGM2ODAwODcyMDYxZjgyOWIwYjRkNjM0ZWVjYmIyZjg5ZDgwODcy
15
+ ZWFlN2JkZjExNDk5OWM1Zjk5OGRmODg0OGRkM2Q5MDA3Nzk4Zjk=
data/README.md CHANGED
@@ -77,6 +77,8 @@ The following data types are currently supported:
77
77
  - All values are converted to a Numeric (and knows if it needs to be a float)
78
78
  * **date**
79
79
  - All values are converted to a string representation of the date value: "07/30/2015" or nil for empty values
80
+ * **boolean**
81
+ - All values are converted to true or false (QuickBase returns "1" and "0")
80
82
  * **file_attachment**
81
83
  - Doesn't really do anything, only makes you feel better :) File attachments are explained below.
82
84
 
@@ -138,6 +140,17 @@ Database callbacks (i.e. `before_save :create_token!`) are not fully functional
138
140
  Post.create(content: 'Amazing post content', author: 'Cullen Jett')
139
141
  ```
140
142
 
143
+ * **.save_collection(array_of_objects)**
144
+ - Save an array of objects (of the same class)
145
+ - Uses API_ImportFromCSV under the hood, so it will edit a record if it has a record ID or create one if not.
146
+ - Returns array of record IDs
147
+ ```
148
+ @post1 = Post.new(content: 'Amazing post content', author: 'Cullen Jett')
149
+ @post2 = Post.find(123)
150
+
151
+ Post.save_collection([@post1, @post2])
152
+ ```
153
+
141
154
  * **.find(id)**
142
155
  - Query for a specific QuickBase record by it's ID
143
156
  - Returns a single object
@@ -0,0 +1,9 @@
1
+ class BooleanField < Field
2
+ def initialize(*args)
3
+ super(*args)
4
+ end
5
+
6
+ def convert(value)
7
+ value == "1"
8
+ end
9
+ end
@@ -62,6 +62,18 @@ module QuickbaseRecord
62
62
  build_array_of_new_objects(query_response)
63
63
  end
64
64
 
65
+ def save_collection(objects)
66
+ converted_objects = objects.map do |object|
67
+ current_object = {}
68
+ fields.each do |field_name, field|
69
+ current_object[field.fid] = object.send(field_name)
70
+ end
71
+ new.remove_unwritable_fields(current_object)
72
+ end
73
+
74
+ qb_client.import_from_csv(dbid, converted_objects)
75
+ end
76
+
65
77
  def build_query(query_hash)
66
78
  return convert_query_string(query_hash) if query_hash.is_a? String
67
79
 
@@ -41,4 +41,11 @@ class TableDefinition
41
41
 
42
42
  fields[field_name] = DateField.new(field_name: field_name, fid: fid, options: options)
43
43
  end
44
+
45
+ def boolean(field_name, fid, *options)
46
+ field_name = field_name.to_sym
47
+ fid = fid.to_i
48
+
49
+ fields[field_name] = BooleanField.new(field_name: field_name, fid: fid, options: options)
50
+ end
44
51
  end
@@ -1,3 +1,3 @@
1
1
  module QuickbaseRecord
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
data/spec/queries_spec.rb CHANGED
@@ -82,6 +82,14 @@ RSpec.describe QuickbaseRecord::Queries do
82
82
  end
83
83
  end
84
84
 
85
+ describe '.save_collection' do
86
+ it "does something" do
87
+ teacher1 = TeacherFake.new(name: 'Save collection teacher 1')
88
+ teacher2 = TeacherFake.new(name: 'Save collection teacher 2')
89
+ expect(TeacherFake.save_collection([teacher1, teacher2])).to be_truthy
90
+ end
91
+ end
92
+
85
93
  describe '#save' do
86
94
  it "doesn't save :read_only fields" do
87
95
  classroom = ClassroomFake.find(101)
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.4.0
4
+ version: 0.4.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: 2015-07-31 00:00:00.000000000 Z
11
+ date: 2015-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -126,6 +126,7 @@ files:
126
126
  - lib/quickbase_record/client.rb
127
127
  - lib/quickbase_record/configuration.rb
128
128
  - lib/quickbase_record/field.rb
129
+ - lib/quickbase_record/fields/boolean_field.rb
129
130
  - lib/quickbase_record/fields/date_field.rb
130
131
  - lib/quickbase_record/fields/field.rb
131
132
  - lib/quickbase_record/fields/file_attachment_field.rb