Class: Stream::CollectionsClient

Inherits:
Client
  • Object
show all
Defined in:
lib/stream/collections.rb

Instance Attribute Summary

Attributes inherited from Client

#api_key, #api_secret, #app_id, #client_options

Instance Method Summary collapse

Methods inherited from Client

#collections, #create_user_session_token, #create_user_token, #feed, #get_default_params, #get_http_client, #initialize, #make_query_params, #make_request, #og, #personalization, #reactions, #update_activities, #update_activity, #users

Methods included from Activities

#activity_partial_update, #batch_activity_partial_update, #get_activities

Methods included from Batch

#add_to_many, #follow_many, #unfollow_many

Constructor Details

This class inherits a constructor from Stream::Client

Instance Method Details

#add(collection_name, collection_data, id: nil, user_id: nil) ⇒ Object



3
4
5
6
7
8
9
10
11
# 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) ⇒ Object



55
56
57
58
59
# 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) ⇒ Object



26
27
28
29
# 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 = []) ⇒ Object



47
48
49
50
51
52
53
# 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) ⇒ Object



13
14
15
16
# 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 = []) ⇒ Object



40
41
42
43
44
45
# 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) ⇒ Object



18
19
20
21
22
23
24
# 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 = []) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/stream/collections.rb', line 31

def upsert(collection, objects = [])
  data = {
    data: {
      collection => objects
    }
  }
  make_collection_request(:post, {}, data)
end