quickbase_record 0.2.4 → 0.2.5
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/.gitignore +1 -1
- data/lib/quickbase_record/client.rb +1 -1
- data/lib/quickbase_record/field_mapping.rb +23 -0
- data/lib/quickbase_record/model.rb +1 -3
- data/lib/quickbase_record/queries.rb +12 -11
- data/lib/quickbase_record/version.rb +1 -1
- data/quickbase_record-0.2.4.gem +0 -0
- data/spec/fakes/student_fake.rb +0 -8
- data/spec/field_spec.rb +14 -0
- data/spec/model_spec.rb +15 -0
- data/spec/queries_spec.rb +1 -5
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZmU2ODcwN2Y1NzUxMjBiZWUyYWYzNzYxMmFlMDE5MTVjNmNjZTQzMA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZDZkZTVmZDUwMDM0YmNhNjIzYWE0ZjE3ODdlMDQwYTQ3OTJiMmE3Ng==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZDg0MDdkYzc4YjMyMDk1NzJlZTY5NTkzYWExMzc1NWYxMmJiOGVhYWM0NWI3
|
10
|
+
ZDVkMjQ2YmRlODBkMTBlOTU4Y2ZiYzE2YjMwZmUzNTE3YWE3OTgyZTgyYWIx
|
11
|
+
ZmQwZmJkZWI4ZTFkZTYwN2MwNjU0N2IxNzIwNTZlZDIyYTE1ZDQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NTVmNGZmYjliMTNlNGNjMDJmNjE0MmNjNDZjYzQxNWVjMTdhNDU4NGM2NDQ0
|
14
|
+
Y2JmNDA4NjQ5YzA4MWU2ZGVlNjc3ODE0ZTNmMzBhM2M5M2Y3MGM5OWZkN2U0
|
15
|
+
N2I5NTc4OTJmNDAxMDNiN2I3ODQ5ZjE2MTNhZGZhYmQ2MDA0ZTM=
|
data/.gitignore
CHANGED
@@ -14,7 +14,7 @@ module QuickbaseRecord
|
|
14
14
|
password = QuickbaseRecord.configuration.password
|
15
15
|
token = QuickbaseRecord.configuration.token
|
16
16
|
|
17
|
-
@qb_client
|
17
|
+
@qb_client = AdvantageQuickbase::API.new(realm, username, password, token)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -3,7 +3,30 @@ module QuickbaseRecord
|
|
3
3
|
attr_accessor :fields
|
4
4
|
|
5
5
|
def initialize(fields={})
|
6
|
+
# @fields = create_fields(fields)
|
6
7
|
@fields = fields
|
7
8
|
end
|
9
|
+
|
10
|
+
def create_fields(fields_hash)
|
11
|
+
converted_fields_hash = {}
|
12
|
+
fields_hash.each do |key, value|
|
13
|
+
converted_fields_hash[key] = Field.new(value)
|
14
|
+
end
|
15
|
+
return converted_fields_hash
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class Field
|
20
|
+
attr_accessor :value
|
21
|
+
|
22
|
+
def initialize(value)
|
23
|
+
@value = format_value(value)
|
24
|
+
end
|
25
|
+
|
26
|
+
def format_value(value)
|
27
|
+
return value if value.is_a? Integer
|
28
|
+
|
29
|
+
|
30
|
+
end
|
8
31
|
end
|
9
32
|
end
|
@@ -25,8 +25,6 @@ module QuickbaseRecord
|
|
25
25
|
def initialize(attributes={})
|
26
26
|
create_attr_accesssors
|
27
27
|
assign_attributes(attributes) if attributes
|
28
|
-
|
29
|
-
super()
|
30
28
|
end
|
31
29
|
|
32
30
|
def persisted?
|
@@ -34,7 +32,7 @@ module QuickbaseRecord
|
|
34
32
|
end
|
35
33
|
|
36
34
|
def create_attr_accesssors
|
37
|
-
self.class.fields.each do |field_name,
|
35
|
+
self.class.fields.each do |field_name, value|
|
38
36
|
self.class.send(:attr_accessor, field_name)
|
39
37
|
end
|
40
38
|
end
|
@@ -32,11 +32,10 @@ module QuickbaseRecord
|
|
32
32
|
|
33
33
|
return [] if query_response.first.nil?
|
34
34
|
|
35
|
-
|
35
|
+
build_collection(query_response)
|
36
36
|
end
|
37
37
|
|
38
38
|
def create(attributes={})
|
39
|
-
raise StandardErrror, "You cannot call #{self}.create() with an :id attribute" if attributes.include?(:id)
|
40
39
|
object = new(attributes)
|
41
40
|
object.save
|
42
41
|
return object
|
@@ -48,7 +47,7 @@ module QuickbaseRecord
|
|
48
47
|
|
49
48
|
return [] if query_response.first.nil?
|
50
49
|
|
51
|
-
|
50
|
+
build_collection(query_response)
|
52
51
|
end
|
53
52
|
|
54
53
|
def build_query(query_hash)
|
@@ -73,9 +72,7 @@ module QuickbaseRecord
|
|
73
72
|
end.join("AND")
|
74
73
|
end
|
75
74
|
|
76
|
-
|
77
|
-
|
78
|
-
def build_array_of_new_objects(query_response)
|
75
|
+
def build_collection(query_response)
|
79
76
|
query_response.map do |response|
|
80
77
|
converted_response = convert_quickbase_response(response)
|
81
78
|
new(converted_response)
|
@@ -141,7 +138,7 @@ module QuickbaseRecord
|
|
141
138
|
end
|
142
139
|
|
143
140
|
if !match_found
|
144
|
-
raise ArgumentError, "Invalid arguments on #{self}.
|
141
|
+
raise ArgumentError, "Invalid arguments on #{self}.where() - no matching field name found. \nMake sure the field is part of your class configuration."
|
145
142
|
end
|
146
143
|
|
147
144
|
return query_string
|
@@ -170,7 +167,7 @@ module QuickbaseRecord
|
|
170
167
|
end
|
171
168
|
|
172
169
|
def delete
|
173
|
-
return false
|
170
|
+
return false unless self.id
|
174
171
|
successful = qb_client.delete_record(self.class.dbid, self.id)
|
175
172
|
return successful ? self.id : false
|
176
173
|
end
|
@@ -178,12 +175,16 @@ module QuickbaseRecord
|
|
178
175
|
def update_attributes(attributes={})
|
179
176
|
return false if attributes.blank?
|
180
177
|
self.assign_attributes(attributes)
|
181
|
-
|
178
|
+
updated_attributes = {}
|
179
|
+
attributes.each { |field_name, value| updated_attributes[self.class.convert_field_name_to_fid(field_name)] = value }
|
180
|
+
if self.id
|
181
|
+
qb_client.edit_record(self.class.dbid, self.id, updated_attributes)
|
182
|
+
else
|
183
|
+
self.id = qb_client.add_record(self.class.dbid, updated_attributes)
|
184
|
+
end
|
182
185
|
return self
|
183
186
|
end
|
184
187
|
|
185
|
-
private
|
186
|
-
|
187
188
|
def has_file_attachment?(current_object)
|
188
189
|
current_object.values.any? { |value| value.is_a? Hash }
|
189
190
|
end
|
Binary file
|
data/spec/fakes/student_fake.rb
CHANGED
data/spec/field_spec.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# require 'quickbase_record/field_mapping'
|
2
|
+
|
3
|
+
# RSpec.describe QuickbaseRecord::Field do
|
4
|
+
# describe '#value' do
|
5
|
+
# it "returns the value if an integer is passed" do
|
6
|
+
# expect(QuickbaseRecord::Field.new(123).value).to eq(123)
|
7
|
+
# end
|
8
|
+
|
9
|
+
# it "returns a formatted date if a hash with the key :date is passed" do
|
10
|
+
# value = {date: 123}
|
11
|
+
# expect(QuickbaseRecord::Field.new(value).to)
|
12
|
+
# end
|
13
|
+
# end
|
14
|
+
# end
|
data/spec/model_spec.rb
CHANGED
@@ -13,6 +13,21 @@ RSpec.describe QuickbaseRecord::Model do
|
|
13
13
|
|
14
14
|
expect(StudentFake.fields[:id]).to eq(3)
|
15
15
|
end
|
16
|
+
|
17
|
+
# it "formats fields as dates given a hash value" do
|
18
|
+
# StudentFake.define_fields ({
|
19
|
+
# :dbid => 'bjzrx8ckw',
|
20
|
+
# :date_created => {date: 1},
|
21
|
+
# :id => 3,
|
22
|
+
# :name => 6,
|
23
|
+
# :grade => 7,
|
24
|
+
# :email => 8
|
25
|
+
# })
|
26
|
+
|
27
|
+
# puts StudentFake.find(1).inspect
|
28
|
+
|
29
|
+
# expect(StudentFake.find(1).date_created).to eq('1/1/2015')
|
30
|
+
# end
|
16
31
|
end
|
17
32
|
|
18
33
|
describe 'initialize' do
|
data/spec/queries_spec.rb
CHANGED
@@ -51,10 +51,6 @@ RSpec.describe QuickbaseRecord::Queries do
|
|
51
51
|
expect(teacher.id).to be > 1
|
52
52
|
teacher.delete
|
53
53
|
end
|
54
|
-
|
55
|
-
it "throws an error if an :id argument is passed" do
|
56
|
-
expect { TeacherFake.create(id: 1, name: 'Professor Dumbledore') }.to raise_error
|
57
|
-
end
|
58
54
|
end
|
59
55
|
|
60
56
|
describe '.qid' do
|
@@ -127,7 +123,7 @@ RSpec.describe QuickbaseRecord::Queries do
|
|
127
123
|
end
|
128
124
|
|
129
125
|
describe '#update_attributes' do
|
130
|
-
it "assigns an objects attributes given a hash attributes
|
126
|
+
it "assigns an objects attributes given a hash of attributes" do
|
131
127
|
teacher = TeacherFake.new(name: 'teacher1', salary: 35000)
|
132
128
|
teacher.update_attributes(name: 'teacher2', salary: 40000)
|
133
129
|
expect(teacher.name).to eq('teacher2')
|
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.2.
|
4
|
+
version: 0.2.5
|
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-
|
11
|
+
date: 2015-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -120,9 +120,11 @@ files:
|
|
120
120
|
- quickbase_record-0.2.1.gem
|
121
121
|
- quickbase_record-0.2.2.gem
|
122
122
|
- quickbase_record-0.2.3.gem
|
123
|
+
- quickbase_record-0.2.4.gem
|
123
124
|
- quickbase_record.gemspec
|
124
125
|
- spec/fakes/student_fake.rb
|
125
126
|
- spec/fakes/teacher_fake.rb
|
127
|
+
- spec/field_spec.rb
|
126
128
|
- spec/model_spec.rb
|
127
129
|
- spec/queries_spec.rb
|
128
130
|
- spec/quickbase_record_config.rb
|
@@ -153,6 +155,7 @@ summary: An ActiveRecord-style ORM for using Intuit QuickBase tables as models.
|
|
153
155
|
test_files:
|
154
156
|
- spec/fakes/student_fake.rb
|
155
157
|
- spec/fakes/teacher_fake.rb
|
158
|
+
- spec/field_spec.rb
|
156
159
|
- spec/model_spec.rb
|
157
160
|
- spec/queries_spec.rb
|
158
161
|
- spec/quickbase_record_config.rb
|