Class: SparkApi::Models::StandardFields

Inherits:
Base
  • Object
show all
Extended by:
Finders
Defined in:
lib/spark_api/models/standard_fields.rb

Constant Summary

Constants included from Paginate

Paginate::DEFAULT_PAGE_SIZE

Instance Attribute Summary

Attributes inherited from Base

#attributes, #errors, #parent

Class Method Summary collapse

Methods included from Finders

find, find_one, first, last

Methods inherited from Base

connection, #connection, count, element_name, element_name=, first, get, #id, #initialize, #load, #method_missing, #parse_id, path, #path, #persisted?, prefix, prefix=, #resource_pluralized, #resource_uri, #respond_to?, #to_param, #to_partial_path

Methods included from Paginate

#collect, #paginate, #per_page

Methods included from Dirty

#changed, #changed?, #changed_attributes, #changes, #dirty_attributes, #previous_changes

Constructor Details

This class inherits a constructor from SparkApi::Models::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class SparkApi::Models::Base

Class Method Details

.find_and_expand_all(fields, arguments = {}, max_list_size = 1000) ⇒ Object

expand all fields passed in



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/spark_api/models/standard_fields.rb', line 8

def self.find_and_expand_all(fields, arguments={}, max_list_size=1000)
  returns = {}
  
  # find all standard fields, but expand only the location fields
  # TODO: when _expand support is added to StandardFields API, use the following
  # standard_fields = find(:all, {:ApiUser => owner, :_expand => fields.join(",")}) 
  standard_fields = find(:all, arguments)

  # filter through the list and return only the location fields found
  fields.each do |field|
    # search for field in the payload
    if standard_fields.first.attributes.has_key?(field)
      returns[field] = standard_fields.first.attributes[field]
        
      # lookup fully _expand field, if the field has a list
      if returns[field]['HasList'] && returns[field]['MaxListSize'].to_i <= max_list_size
        returns[field] = connection.get("/standardfields/#{field}", arguments).first[field]
      end
        
    end
  end
  
  returns
end

.find_nearby(prop_types = ["A"], arguments = {}) ⇒ Object

find_nearby: find fields nearby via lat/lon



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/spark_api/models/standard_fields.rb', line 35

def self.find_nearby(prop_types = ["A"], arguments={})
  return_json = {"D" => {"Success" => true, "Results" => []} }
  
  # add _expand=1 so the fields are returned
  arguments.merge!({:_expand => 1})
  
  # find and return
  return_json["D"]["Results"] = connection.get("/standardfields/nearby/#{prop_types.join(',')}", arguments)
  
  # return
  return_json
end