quickbase_record 0.0.2 → 0.1.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/client.rb +8 -1
- data/lib/quickbase_record/configuration.rb +2 -1
- data/lib/quickbase_record/queries.rb +18 -32
- data/lib/quickbase_record/version.rb +1 -1
- data/quickbase_record-0.0.2.gem +0 -0
- data/spec/queries_spec.rb +36 -22
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ODYyYTFkNjQ2ZWJlY2MyYmM4ZTIzMjMxZGIwZGQ0NmIxYmM2ZTk3OA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ODM0YjlmNmM0ZWY2ODZlODhkZGYwNjRjYjAyZDlkOWNkZDZmYjU5Yw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZWM1MTQ2OGQ0ZjIyMDFjM2U1MjhjNmEzZDBhZWZmZWM1M2VjMGQyMjgxZDFl
|
10
|
+
ZjI1M2FjNjZjODFmNDU3Yjg1ZTNkN2Y1ZWM5Yzc2ODlhOWQ0NjQ2ZTYyNGUw
|
11
|
+
OTRhYTA0ZTY1MjVhMTIxYWQ1MTQxMzUyMWNiMjUyMWYzYjdjN2E=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZDBkNjQzZmM0ZWViZTUwNjY0MWIzMDQ3MDgzOWFlYzViMDM2ZWU3NTgwZTI2
|
14
|
+
OWNmNDcxYmZmNmI3YmU3MTE3ODZmNDI2OTM4NDk1MTU3MDZkYWQ4ODMxNTk2
|
15
|
+
NTY0Y2JhMWFkN2U2NDAwODg2ZjdmYzFiNTNiNzU0NTFjMTUxMzQ=
|
@@ -2,12 +2,19 @@ module QuickbaseRecord
|
|
2
2
|
module Client
|
3
3
|
include ActiveSupport::Concern
|
4
4
|
|
5
|
+
module ClassMethods
|
6
|
+
def qb_client
|
7
|
+
self.new.qb_client
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
5
11
|
def qb_client
|
6
12
|
realm = QuickbaseRecord.configuration.realm
|
7
13
|
username = QuickbaseRecord.configuration.username
|
8
14
|
password = QuickbaseRecord.configuration.password
|
15
|
+
token = QuickbaseRecord.configuration.token
|
9
16
|
|
10
|
-
@qb_client ||= AdvantageQuickbase::API.new(realm, username, password)
|
17
|
+
@qb_client ||= AdvantageQuickbase::API.new(realm, username, password, token)
|
11
18
|
end
|
12
19
|
end
|
13
20
|
end
|
@@ -19,8 +19,10 @@ module QuickbaseRecord
|
|
19
19
|
def find(id)
|
20
20
|
query_options = { query: build_query(id: id), clist: clist }
|
21
21
|
query_response = qb_client.do_query(dbid, query_options).first
|
22
|
-
converted_response = convert_quickbase_response(query_response)
|
23
22
|
|
23
|
+
return false if query_response.nil?
|
24
|
+
|
25
|
+
converted_response = convert_quickbase_response(query_response)
|
24
26
|
new(converted_response)
|
25
27
|
end
|
26
28
|
|
@@ -28,12 +30,9 @@ module QuickbaseRecord
|
|
28
30
|
query_options = { query: build_query(query_hash), clist: clist }
|
29
31
|
query_response = qb_client.do_query(dbid, query_options)
|
30
32
|
|
31
|
-
|
32
|
-
converted_response = convert_quickbase_response(response)
|
33
|
-
new(converted_response)
|
34
|
-
end
|
33
|
+
return false if query_response.first.nil?
|
35
34
|
|
36
|
-
|
35
|
+
build_array_of_new_objects(query_response)
|
37
36
|
end
|
38
37
|
|
39
38
|
def create(attributes={})
|
@@ -43,28 +42,11 @@ module QuickbaseRecord
|
|
43
42
|
return object
|
44
43
|
end
|
45
44
|
|
46
|
-
def query(query_string)
|
47
|
-
query_options = { query: build_query(query_string), clist: clist }
|
48
|
-
query_response = qb_client.do_query(dbid, query_options)
|
49
|
-
|
50
|
-
array_of_new_objects = query_response.map do |response|
|
51
|
-
converted_response = convert_quickbase_response(response)
|
52
|
-
new(converted_response)
|
53
|
-
end
|
54
|
-
|
55
|
-
return array_of_new_objects
|
56
|
-
end
|
57
|
-
|
58
45
|
def qid(id)
|
59
46
|
query_options = { qid: id, clist: clist }
|
60
47
|
query_response = qb_client.do_query(dbid, query_options)
|
61
48
|
|
62
|
-
|
63
|
-
converted_response = convert_quickbase_response(response)
|
64
|
-
new(converted_response)
|
65
|
-
end
|
66
|
-
|
67
|
-
return array_of_new_objects
|
49
|
+
build_array_of_new_objects(query_response)
|
68
50
|
end
|
69
51
|
|
70
52
|
def build_query(query_hash)
|
@@ -84,6 +66,13 @@ module QuickbaseRecord
|
|
84
66
|
|
85
67
|
private
|
86
68
|
|
69
|
+
def build_array_of_new_objects(query_response)
|
70
|
+
query_response.map do |response|
|
71
|
+
converted_response = convert_quickbase_response(response)
|
72
|
+
new(converted_response)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
87
76
|
def join_with_and(fid, value, comparitor="EX")
|
88
77
|
"{'#{fid}'.#{comparitor}.'#{value}'}"
|
89
78
|
end
|
@@ -122,17 +111,14 @@ module QuickbaseRecord
|
|
122
111
|
result[field_name] = value
|
123
112
|
end
|
124
113
|
|
125
|
-
result
|
114
|
+
return result
|
126
115
|
end
|
127
116
|
|
128
117
|
def convert_query_string(query_string)
|
129
118
|
match_found = false
|
130
|
-
|
131
119
|
uses_field_name = query_string.match(/\{'?(.*)'?\..*\.'?.*'?\}/)[1].to_i == 0
|
132
120
|
|
133
|
-
|
134
|
-
return query_string
|
135
|
-
end
|
121
|
+
return query_string unless uses_field_name
|
136
122
|
|
137
123
|
fields.each do |field_name, fid|
|
138
124
|
field_name = field_name.to_s
|
@@ -147,7 +133,7 @@ module QuickbaseRecord
|
|
147
133
|
raise ArgumentError, "Invalid arguments on #{self}.query() - no matching field name found. \nMake sure the field is part of your class configuration."
|
148
134
|
end
|
149
135
|
|
150
|
-
query_string
|
136
|
+
return query_string
|
151
137
|
end
|
152
138
|
end
|
153
139
|
|
@@ -159,17 +145,17 @@ module QuickbaseRecord
|
|
159
145
|
current_object[self.class.fields[:id]] = self.id if self.id
|
160
146
|
end
|
161
147
|
self.id = qb_client.import_from_csv(self.class.dbid, [current_object]).first
|
148
|
+
return self
|
162
149
|
end
|
163
150
|
|
164
151
|
def delete
|
165
152
|
return false if !self.id
|
166
|
-
|
167
153
|
successful = qb_client.delete_record(self.class.dbid, self.id)
|
168
|
-
|
169
154
|
return successful ? self.id : false
|
170
155
|
end
|
171
156
|
|
172
157
|
def update_attributes(attributes={})
|
158
|
+
return false if attributes.blank?
|
173
159
|
self.assign_attributes(attributes)
|
174
160
|
self.save
|
175
161
|
return self
|
Binary file
|
data/spec/queries_spec.rb
CHANGED
@@ -11,6 +11,11 @@ RSpec.describe QuickbaseRecord::Queries do
|
|
11
11
|
teacher = TeacherFake.find(1)
|
12
12
|
expect(teacher).to be_a TeacherFake
|
13
13
|
end
|
14
|
+
|
15
|
+
it "returns false if no QuickBase records are found" do
|
16
|
+
teacher = TeacherFake.find(999999)
|
17
|
+
expect(teacher).to be false
|
18
|
+
end
|
14
19
|
end
|
15
20
|
|
16
21
|
describe '.where' do
|
@@ -23,6 +28,21 @@ RSpec.describe QuickbaseRecord::Queries do
|
|
23
28
|
teachers = TeacherFake.where(id: 1)
|
24
29
|
expect(teachers.first).to be_a TeacherFake
|
25
30
|
end
|
31
|
+
|
32
|
+
it "accepts a string in QuickBase query format" do
|
33
|
+
teachers = TeacherFake.where("{'3'.EX.'1'}")
|
34
|
+
expect(teachers.first.id).to eq('1')
|
35
|
+
end
|
36
|
+
|
37
|
+
it "accepts a string in QuickBase query format using field names" do
|
38
|
+
teachers = TeacherFake.where("{'id'.EX.'1'}")
|
39
|
+
expect(teachers.first.id).to eq('1')
|
40
|
+
end
|
41
|
+
|
42
|
+
it "returns false if no QuickBase records are found" do
|
43
|
+
teachers = TeacherFake.where(name: 'Not a real TeacherFake name...')
|
44
|
+
expect(teachers).to be false
|
45
|
+
end
|
26
46
|
end
|
27
47
|
|
28
48
|
describe '.create' do
|
@@ -37,23 +57,6 @@ RSpec.describe QuickbaseRecord::Queries do
|
|
37
57
|
end
|
38
58
|
end
|
39
59
|
|
40
|
-
describe '.query' do
|
41
|
-
it "returns an array of objects" do
|
42
|
-
teachers = TeacherFake.query("{id.EX.'1'}")
|
43
|
-
expect(teachers).to be_a Array
|
44
|
-
end
|
45
|
-
|
46
|
-
it "returns an object of the Teacher class" do
|
47
|
-
teachers = TeacherFake.query("{id.EX.'1'}")
|
48
|
-
expect(teachers.first).to be_a TeacherFake
|
49
|
-
end
|
50
|
-
|
51
|
-
it "accepts FIDs instead of field names" do
|
52
|
-
teachers = TeacherFake.query("{'3'.EX.'1'}")
|
53
|
-
expect(teachers.first.id).to eq('1')
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
60
|
describe '.qid' do
|
58
61
|
it "returns an array of objects" do
|
59
62
|
teachers = TeacherFake.qid(1)
|
@@ -67,18 +70,22 @@ RSpec.describe QuickbaseRecord::Queries do
|
|
67
70
|
end
|
68
71
|
|
69
72
|
describe '#save' do
|
70
|
-
it "creates a new record for an object without an ID and sets it's new ID" do
|
73
|
+
it "creates a new record in QuickBase for an object without an ID and sets it's new ID" do
|
71
74
|
cullen = TeacherFake.new(name: 'Cullen Jett', salary: '1,000,000.00')
|
72
|
-
|
73
|
-
expect(
|
74
|
-
|
75
|
+
cullen.save
|
76
|
+
expect(cullen.id).to be_truthy
|
77
|
+
end
|
78
|
+
|
79
|
+
it "returns the object on successful save" do
|
80
|
+
cullen = TeacherFake.where(name: 'Cullen Jett').first
|
81
|
+
expect(cullen.save).to be_a TeacherFake
|
75
82
|
end
|
76
83
|
|
77
84
|
it "edits an object that has an existing ID" do
|
78
85
|
cullen = TeacherFake.where(name: 'Cullen Jett').first
|
79
86
|
cullen.subject = 'Ruby on Rails'
|
80
87
|
cullen.name = "THE #{cullen.name}"
|
81
|
-
expect(cullen.save).to be_truthy
|
88
|
+
expect(cullen.save.id).to be_truthy
|
82
89
|
cullen.delete
|
83
90
|
end
|
84
91
|
end
|
@@ -117,6 +124,7 @@ RSpec.describe QuickbaseRecord::Queries do
|
|
117
124
|
teacher.update_attributes(name: 'teacher2', salary: 40000)
|
118
125
|
expect(teacher.name).to eq('teacher2')
|
119
126
|
expect(teacher.salary).to eq(40000)
|
127
|
+
teacher.delete
|
120
128
|
end
|
121
129
|
|
122
130
|
it "saves the object" do
|
@@ -125,6 +133,12 @@ RSpec.describe QuickbaseRecord::Queries do
|
|
125
133
|
expect(teacher.id).to be_truthy
|
126
134
|
teacher.delete
|
127
135
|
end
|
136
|
+
|
137
|
+
it "returns false if no attributes are passed" do
|
138
|
+
teacher = TeacherFake.new()
|
139
|
+
teacher.update_attributes()
|
140
|
+
expect(teacher.update_attributes()).to be false
|
141
|
+
end
|
128
142
|
end
|
129
143
|
|
130
144
|
# This is sort of a private method, but it seems pretty important so I'm keeping these tests.
|
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.0
|
4
|
+
version: 0.1.0
|
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-06-
|
11
|
+
date: 2015-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -129,6 +129,7 @@ files:
|
|
129
129
|
- lib/quickbase_record/model.rb
|
130
130
|
- lib/quickbase_record/queries.rb
|
131
131
|
- lib/quickbase_record/version.rb
|
132
|
+
- quickbase_record-0.0.2.gem
|
132
133
|
- quickbase_record.gemspec
|
133
134
|
- spec/fakes/student_fake.rb
|
134
135
|
- spec/fakes/teacher_fake.rb
|