Module: Supplejack::Record::ClassMethods
- Defined in:
- lib/supplejack/record.rb
Instance Method Summary collapse
-
#find(id_or_array, options = {}) ⇒ Supplejack::Record
Finds a record or array of records from the Supplejack API.
Instance Method Details
#find(id_or_array, options = {}) ⇒ Supplejack::Record
Finds a record or array of records from the Supplejack API
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/supplejack/record.rb', line 110 def find(id_or_array, ={}) if id_or_array.is_a?(Array) = {:record_ids => id_or_array, :fields => Supplejack.fields.join(',') } response = get("/records/multiple", ) response["records"].map {|attributes| new(attributes) } else begin # handle malformed id's before requesting anything. id = id_or_array.to_i raise(Supplejack::MalformedRequest, "'#{id_or_array}' is not a valid record id") if id <= 0 # Do not send any parameters in the :search key when the user didn't specify any options # And also always send the :fields parameter # search_klass = Supplejack::Search search_klass = Supplejack.search_klass.classify.constantize if Supplejack.search_klass.present? = .try(:any?) search = search_klass.new() = search.api_params = search.merge_extra_filters() = {:search => } [:fields] = [:search].delete(:fields) .delete(:search) unless response = get("/records/#{id}", ) new(response['record']) rescue RestClient::ResourceNotFound => e raise Supplejack::RecordNotFound, "Record with ID #{id_or_array} was not found" end end end |