class Stream::CollectionsClient
Public Instance Methods
add(collection_name, collection_data, id: nil, user_id: nil)
click to toggle source
# File lib/stream/collections.rb, line 3 def add(collection_name, collection_data, id: nil, user_id: nil) data = { id: id, user_id: user_id, data: collection_data } uri = "/collections/#{collection_name}/" make_collection_request(:post, {}, data, endpoint: uri) end
create_reference(collection, id)
click to toggle source
# File lib/stream/collections.rb, line 55 def create_reference(collection, id) k = id k = id['id'] if id.respond_to?(:keys) && !id['id'].nil? "SO:#{collection}:#{k}" end
delete(collection_name, id)
click to toggle source
# File lib/stream/collections.rb, line 26 def delete(collection_name, id) uri = "collections/#{collection_name}/#{id}/" make_collection_request(:delete, {}, {}, endpoint: uri) end
delete_many(collection, ids = [])
click to toggle source
# File lib/stream/collections.rb, line 47 def delete_many(collection, ids = []) params = { collection_name: collection, ids: ids.join(',') } make_collection_request(:delete, params, {}) end
get(collection_name, id)
click to toggle source
# File lib/stream/collections.rb, line 13 def get(collection_name, id) uri = "collections/#{collection_name}/#{id}/" make_collection_request(:get, {}, {}, endpoint: uri) end
select(collection, ids = [])
click to toggle source
# File lib/stream/collections.rb, line 40 def select(collection, ids = []) params = { foreign_ids: ids.map { |id| "#{collection}:#{id}" }.join(',') } make_collection_request(:get, params, {}) end
update(collection_name, id, data: nil)
click to toggle source
# File lib/stream/collections.rb, line 18 def update(collection_name, id, data: nil) data = { data: data } uri = "collections/#{collection_name}/#{id}/" make_collection_request(:put, {}, data, endpoint: uri) end
upsert(collection, objects = [])
click to toggle source
# File lib/stream/collections.rb, line 31 def upsert(collection, objects = []) data = { data: { collection => objects } } make_collection_request(:post, {}, data) end
Private Instance Methods
make_collection_request(method, params, data, endpoint: '/collections/')
click to toggle source
# File lib/stream/collections.rb, line 63 def make_collection_request(method, params, data, endpoint: '/collections/') auth_token = Stream::Signer.create_jwt_token('collections', '*', @api_secret, '*', '*') make_request(method, endpoint, auth_token, params, data) end