quickbase_record 0.2.7 → 0.3.0
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 +8 -8
- data/lib/quickbase_record/queries.rb +36 -22
- data/lib/quickbase_record/version.rb +1 -1
- data/spec/queries_spec.rb +10 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YTI2YTdiYmM1M2ExYmMxYTg2MDIyMjFhOWJhZjE2M2E2NWYwYmNkOQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YWNiMDVmYzlhOTgyOTJmZTg2MTgxZDE1MDkyNTBiOWI0OTJiYTJjZQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
M2VhMzE1NjE2MmUxY2MzYTAzZmM3MmJlZDM5ZjQwOWM3NTA4MTUyNTkxN2Vl
|
10
|
+
MzNmNGMwZDY3NjE3YTQ1NTEyY2ZlZGMxMGRhM2NmZTQ5YTc2OGE5YjJhYTMz
|
11
|
+
M2Q0YTIyZGFmN2VjMzEyNjg5OWQxOTY3MjA5ZGMxYTQ4NDJiMzM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NDFjYWRlZTcyZTgxODBjMTc4MGExYzkyMDRmYWFmNWNmZmE4Yzc4MTdhZmRj
|
14
|
+
MGQ5YmZmNjFjNGJmMWJkMTc3ZDZmYTczMmZhZjAzOTQ5ZjcwZjY4MGZhNzhl
|
15
|
+
NmMxYzZjNTUxY2M1YWFkZDFkZTRkN2Q2NmY5NWNkZjFhZTljODQ=
|
@@ -16,9 +16,10 @@ module QuickbaseRecord
|
|
16
16
|
@clist ||= fields.reject{ |field_name| field_name == :dbid }.values.join('.')
|
17
17
|
end
|
18
18
|
|
19
|
-
def find(id)
|
20
|
-
query_options =
|
21
|
-
|
19
|
+
def find(id, query_options = {})
|
20
|
+
query_options = build_query_options(query_options[:query_options])
|
21
|
+
query = { query: build_query(id: id), clist: clist }.merge(query_options)
|
22
|
+
query_response = qb_client.do_query(dbid, query).first
|
22
23
|
|
23
24
|
return nil if query_response.nil?
|
24
25
|
|
@@ -27,23 +28,29 @@ module QuickbaseRecord
|
|
27
28
|
end
|
28
29
|
|
29
30
|
def where(query_hash)
|
30
|
-
|
31
|
-
|
31
|
+
if !query_hash.is_a? String
|
32
|
+
options = build_query_options(query_hash.delete(:query_options))
|
33
|
+
else
|
34
|
+
options = {}
|
35
|
+
end
|
36
|
+
|
37
|
+
query = { query: build_query(query_hash), clist: clist }.merge(options)
|
38
|
+
query_response = qb_client.do_query(dbid, query)
|
32
39
|
|
33
40
|
return [] if query_response.first.nil?
|
34
41
|
|
35
42
|
build_collection(query_response)
|
36
43
|
end
|
37
44
|
|
38
|
-
def create(attributes={})
|
45
|
+
def create(attributes = {})
|
39
46
|
object = new(attributes)
|
40
47
|
object.save
|
41
48
|
return object
|
42
49
|
end
|
43
50
|
|
44
51
|
def qid(id)
|
45
|
-
|
46
|
-
query_response = qb_client.do_query(dbid,
|
52
|
+
query = { qid: id, clist: clist }
|
53
|
+
query_response = qb_client.do_query(dbid, query)
|
47
54
|
|
48
55
|
return [] if query_response.first.nil?
|
49
56
|
|
@@ -72,6 +79,22 @@ module QuickbaseRecord
|
|
72
79
|
end.join("AND")
|
73
80
|
end
|
74
81
|
|
82
|
+
def build_query_options(options)
|
83
|
+
return {} unless options
|
84
|
+
|
85
|
+
result = {}
|
86
|
+
|
87
|
+
options.each do |option_name, value|
|
88
|
+
if option_name.to_sym == :options
|
89
|
+
result[option_name] = value
|
90
|
+
else
|
91
|
+
result[option_name] = convert_field_name_to_fid(value)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
return result
|
96
|
+
end
|
97
|
+
|
75
98
|
def build_collection(query_response)
|
76
99
|
query_response.map do |response|
|
77
100
|
converted_response = convert_quickbase_response(response)
|
@@ -154,16 +177,11 @@ module QuickbaseRecord
|
|
154
177
|
|
155
178
|
current_object.delete_if { |key, value| value.nil? }
|
156
179
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
end
|
163
|
-
# else
|
164
|
-
# current_object[self.class.fields[:id]] = self.id if self.id
|
165
|
-
# self.id = qb_client.import_from_csv(self.class.dbid, [current_object]).first
|
166
|
-
# end
|
180
|
+
if self.id
|
181
|
+
qb_client.edit_record(self.class.dbid, self.id, current_object)
|
182
|
+
else
|
183
|
+
self.id = qb_client.add_record(self.class.dbid, current_object)
|
184
|
+
end
|
167
185
|
|
168
186
|
return self
|
169
187
|
end
|
@@ -187,9 +205,5 @@ module QuickbaseRecord
|
|
187
205
|
end
|
188
206
|
return self
|
189
207
|
end
|
190
|
-
|
191
|
-
def has_file_attachment?(current_object)
|
192
|
-
current_object.values.any? { |value| value.is_a? Hash }
|
193
|
-
end
|
194
208
|
end
|
195
209
|
end
|
data/spec/queries_spec.rb
CHANGED
@@ -16,6 +16,11 @@ RSpec.describe QuickbaseRecord::Queries do
|
|
16
16
|
teacher = TeacherFake.find(999999)
|
17
17
|
expect(teacher).to eq(nil)
|
18
18
|
end
|
19
|
+
|
20
|
+
it "accepts query options" do
|
21
|
+
teacher = TeacherFake.find(1, query_options: {clist: 'id'})
|
22
|
+
expect(teacher.name).to be_nil
|
23
|
+
end
|
19
24
|
end
|
20
25
|
|
21
26
|
describe '.where' do
|
@@ -43,6 +48,11 @@ RSpec.describe QuickbaseRecord::Queries do
|
|
43
48
|
teachers = TeacherFake.where(name: 'Not a real TeacherFake name...')
|
44
49
|
expect(teachers).to eq([])
|
45
50
|
end
|
51
|
+
|
52
|
+
it "accepts query options" do
|
53
|
+
teachers = TeacherFake.where(subject: ['Gym', 'Biology'], query_options: {slist: 'subject', options: 'sortorder-D'})
|
54
|
+
expect(teachers.first.subject).to eq('Gym')
|
55
|
+
end
|
46
56
|
end
|
47
57
|
|
48
58
|
describe '.create' do
|