databasedotcom 1.2.2 → 1.2.3

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.
@@ -1,6 +1,7 @@
1
1
  require 'net/https'
2
2
  require 'json'
3
3
  require 'net/http/post/multipart'
4
+ require 'date'
4
5
 
5
6
  module Databasedotcom
6
7
  # Interface for operating the Force.com REST API
@@ -19,6 +19,7 @@ module Databasedotcom
19
19
  self.attributes=(attrs)
20
20
  end
21
21
 
22
+ # Set attributes of this object, from a hash, in bulk
22
23
  def attributes=(attrs)
23
24
  attrs.each do |key, value|
24
25
  self.send("#{key}=", value)
@@ -113,10 +114,12 @@ module Databasedotcom
113
114
  self
114
115
  end
115
116
 
117
+ # Get a named attribute on this object
116
118
  def [](attr_name)
117
119
  self.send(attr_name) rescue nil
118
120
  end
119
121
 
122
+ # Set a named attribute on this object
120
123
  def []=(attr_name, value)
121
124
  raise ArgumentError.new("No attribute named #{attr_name}") unless self.class.attributes.include?(attr_name)
122
125
  self.send("#{attr_name}=", value)
@@ -130,17 +133,6 @@ module Databasedotcom
130
133
  self.description["fields"].collect { |f| [f["name"], f["relationshipName"]] }.flatten.compact
131
134
  end
132
135
 
133
- def self.register_field( name, field )
134
- attr_accessor name.to_sym
135
- self.type_map[name] = {
136
- :type => field["type"],
137
- :label => field["label"],
138
- :picklist_values => field["picklistValues"],
139
- :updateable? => field["updateable"],
140
- :createable? => field["createable"]
141
- }
142
- end
143
-
144
136
  # Materializes the dynamically created Sobject class by adding all attribute accessors for each field as described in the description of the object on Force.com
145
137
  def self.materialize(sobject_name)
146
138
  self.cattr_accessor :description
@@ -150,18 +142,18 @@ module Databasedotcom
150
142
  self.sobject_name = sobject_name
151
143
  self.description = self.client.describe_sobject(self.sobject_name)
152
144
  self.type_map = {}
153
-
145
+
154
146
  self.description["fields"].each do |field|
155
-
147
+
156
148
  # Register normal fields
157
149
  name = field["name"]
158
150
  register_field( field["name"], field )
159
-
151
+
160
152
  # Register relationship fields.
161
153
  if( field["type"] == "reference" and field["relationshipName"] )
162
154
  register_field( field["relationshipName"], field )
163
155
  end
164
-
156
+
165
157
  end
166
158
  end
167
159
 
@@ -243,7 +235,7 @@ module Databasedotcom
243
235
  def self.delete(record_id)
244
236
  self.client.delete(self.sobject_name, record_id)
245
237
  end
246
-
238
+
247
239
  # Get the total number of records
248
240
  def self.count
249
241
  self.client.query("SELECT COUNT() FROM #{self.sobject_name}").total_size
@@ -271,7 +263,7 @@ module Databasedotcom
271
263
  end
272
264
 
273
265
  limit_clause = method_name.to_s.include?('_all_by_') ? "" : " LIMIT 1"
274
-
266
+
275
267
  results = self.client.query("SELECT #{self.field_list} FROM #{self.sobject_name} WHERE #{soql_conditions_for(attrs_and_values_for_find)}#{limit_clause}")
276
268
  results = limit_clause == "" ? results : results.first rescue nil
277
269
 
@@ -314,6 +306,19 @@ module Databasedotcom
314
306
 
315
307
  private
316
308
 
309
+ def self.register_field( name, field )
310
+ public
311
+ attr_accessor name.to_sym
312
+ private
313
+ self.type_map[name] = {
314
+ :type => field["type"],
315
+ :label => field["label"],
316
+ :picklist_values => field["picklistValues"],
317
+ :updateable? => field["updateable"],
318
+ :createable? => field["createable"]
319
+ }
320
+ end
321
+
317
322
  def self.field_list
318
323
  self.description['fields'].collect { |f| f['name'] }.join(',')
319
324
  end
@@ -322,7 +327,7 @@ module Databasedotcom
322
327
  raise ArgumentError.new("No attribute named #{attr_name}") unless self.type_map.has_key?(attr_name)
323
328
  self.type_map[attr_name][key]
324
329
  end
325
-
330
+
326
331
  def self.soql_conditions_for(params)
327
332
  params.inject([]) do |arr, av|
328
333
  case av[1]
@@ -333,7 +338,7 @@ module Databasedotcom
333
338
  else
334
339
  value_str = av[1].to_s
335
340
  end
336
-
341
+
337
342
  arr << "#{av[0]} = #{value_str}"
338
343
  arr
339
344
  end.join(" AND ")
@@ -1,3 +1,3 @@
1
1
  module Databasedotcom
2
- VERSION = "1.2.2"
2
+ VERSION = "1.2.3"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: databasedotcom
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.2.2
5
+ version: 1.2.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Glenn Gillen, Danny Burkes & Richard Zhao
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-10-24 00:00:00 Z
13
+ date: 2011-10-31 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: multipart-post