Module: Knock::Objects

Extended by:
Base, Client
Defined in:
lib/knock/objects.rb

Overview

Provides convienience methods for working with bulk operations

Instance Attribute Summary

Attributes included from Base

#key

Class Method Summary collapse

Methods included from Client

client, delete_request, execute_request, get_request, handle_error_response, post_request, put_request, user_agent

Class Method Details

.bulk_delete(collection:, object_ids: []) ⇒ Hash

Bulk deletes Objects in a collection

Parameters:

  • collection (String)

    The collection the object is in

  • object_ids (Array<String>) (defaults to: [])

    The object ids to delete

Returns:

  • (Hash)

    a BulkOperation



80
81
82
83
84
85
86
87
88
# File 'lib/knock/objects.rb', line 80

def bulk_delete(collection:, object_ids: [])
  request = post_request(
    auth: true,
    path: "/v1/objects/#{collection}/bulk/delete",
    body: {object_ids: object_ids}
  )

  execute_request(request: request)
end

.bulk_set(collection:, objects: []) ⇒ Hash

Bulk upserts Objects in a collection

Parameters:

  • collection (String)

    The collection the object is in

  • objects (Array<Hash>) (defaults to: [])

    The objects to upsert

Returns:

  • (Hash)

    a BulkOperation



49
50
51
52
53
54
55
56
57
# File 'lib/knock/objects.rb', line 49

def bulk_set(collection:, objects: [])
  request = post_request(
    auth: true,
    path: "/v1/objects/#{collection}/bulk/set",
    body: {objects: objects}
  )

  execute_request(request: request)
end

.delete(collection:, id:) ⇒ nil

Deletes an Object in a collection

Parameters:

  • collection (String)

    The collection the object is in

  • id (String)

    The object id

Returns:

  • (nil)

    Nothing



65
66
67
68
69
70
71
72
# File 'lib/knock/objects.rb', line 65

def delete(collection:, id:)
  request = delete_request(
    auth: true,
    path: "/v1/objects/#{collection}/#{id}"
  )

  execute_request(request: request)
end

.get(collection:, id:) ⇒ Hash

Retrieves an Object in a collection

Parameters:

  • collection (String)

    The collection the object is in

  • id (String)

    The object id

Returns:

  • (Hash)

    The Object



17
18
19
20
21
22
23
24
# File 'lib/knock/objects.rb', line 17

def get(collection:, id:)
  request = get_request(
    auth: true,
    path: "/v1/objects/#{collection}/#{id}"
  )

  execute_request(request: request)
end

.get_channel_data(collection:, id:, channel_id:) ⇒ Hash

Get object channel data for the given channel id

Parameters:

  • collection (String)

    The collection the object is in

  • id (String)

    The object id

  • channel_id (String)

    target channel ID

Returns:

  • (Hash)

    channel data



97
98
99
100
101
102
103
104
# File 'lib/knock/objects.rb', line 97

def get_channel_data(collection:, id:, channel_id:)
  request = get_request(
    auth: true,
    path: "/v1/objects/#{collection}/#{id}/channel_data/#{channel_id}"
  )

  execute_request(request: request)
end

.get_messages(collection:, id:, options: {}) ⇒ Hash

Get object's messages

Parameters:

  • collection (String)

    The collection the object is in

  • id (String)

    The object id

  • options (Hash) (defaults to: {})

    Options to pass to the messages endpoint query

Returns:

  • (Hash)

    Paginated messages response



131
132
133
134
135
136
137
138
139
# File 'lib/knock/objects.rb', line 131

def get_messages(collection:, id:, options: {})
  request = get_request(
    auth: true,
    path: "/v1/objects/#{collection}/#{id}/messages",
    params: options
  )

  execute_request(request: request)
end

.set(collection:, id:, properties: {}) ⇒ Hash

Upserts an Object in a collection

Parameters:

  • collection (String)

    The collection the object is in

  • id (String)

    The object id

  • properties (Hash) (defaults to: {})

    The properties to set on the object

Returns:

  • (Hash)

    The Object



33
34
35
36
37
38
39
40
41
# File 'lib/knock/objects.rb', line 33

def set(collection:, id:, properties: {})
  request = put_request(
    auth: true,
    path: "/v1/objects/#{collection}/#{id}",
    body: properties
  )

  execute_request(request: request)
end

.set_channel_data(id:, channel_id:, channel_data:) ⇒ Hash

Upserts object channel data for the given channel id

Parameters:

  • collection (String)

    The collection the object is in

  • id (String)

    The object id

  • channel_id (String)

    target channel ID

  • channel_data (Hash)

    channel data

Returns:

  • (Hash)

    channel data



114
115
116
117
118
119
120
121
122
# File 'lib/knock/objects.rb', line 114

def set_channel_data(id:, channel_id:, channel_data:)
  request = put_request(
    auth: true,
    path: "/v1/objects/#{collection}/#{id}/channel_data/#{channel_id}",
    body: {data: channel_data}
  )

  execute_request(request: request)
end