Skip to content
Nick Maher edited this page Sep 26, 2016 · 4 revisions

CiscoSpark::Room

API reference

Class methods

fetch_all

Fetches all records for a given model, returns a CiscoSpark::Collection Accepts any parameters that the API allows.

room = CiscoSpark::Room.fetch_all(max: 5, ...)
=> #<CiscoSpark::Collection>

fetch

Fetches a single record for the given resource ID, returns an instance Accepts any parameters that the API allows.

room = CiscoSpark::Room.fetch('Y2lzY...', options_hash)
=> #<CiscoSpark::Room>

create

Creates a resource with given attributes, returns an instance Accepts any parameters that the API allows.

room = CiscoSpark::Room.create(email: '[email protected]')
=> #<CiscoSpark::Room>

update

Updates a resource with given attributes, returns an instance Accepts any parameters that the API allows.

room = CiscoSpark::Room.update('Y2lzY...', name: 'Ruby room')
=> #<CiscoSpark::Room>

destroy

Destroys a resource with the given ID, returns an boolean to indicate success Accepts any parameters that the API allows.

room = CiscoSpark::Room.destroy('Y2lzY...')
=> true

parse_collection

Parses a valid JSON string or a ruby hash/array into a collection of models. This is useful for processing data received from a webhook etc.

json_string = '{"items": [{ "id": "Y2lzY...", "key": "value" }]}'
people = CiscoSpark::Room.parse_collection(json_string)
=> #<CiscoSpark::Collection>

parse

Parses a valid JSON string or a ruby hash/array into a model. This is useful for processing data received from a webhook etc.

json_string = '{ "id": "Y2lzY...", "key": "value" }'
room = CiscoSpark::Room.parse(json_string)
=> #<CiscoSpark::Room>

Instance methods

memberships

Get all memberships for room

room = CiscoSpark::Room.new(id: 'Y3de...')
room.memberships(max: 5)
=> #<CiscoSpark::Collection>

messages

Get all messages for room

room = CiscoSpark::Room.new(id: 'Y3de...')
room.messages(max: 5)
=> #<CiscoSpark::Collection>

messages_before_message

Get all message before a given message, accepts a CiscoSpark::Message or a message ID

room.all_before_message('Y3de...', max: 5)
=> #<CiscoSpark::Collection>

messages_before

Get all message before a given time, accepts a DateTime or a string

room.messages_before(DateTime.now, max: 5)
=> #<CiscoSpark::Collection>

send_message

Send a message to the room

message = CiscoSpark::Message.new(text: 'Hello Spark')

room = CiscoSpark::Room.new(id: 'Y3de...')
room.send_message(message)
=> #<CiscoSpark::Message>

add_person

Creates a new membership to the room for a given person

person = CiscoSpark::Person.fetch('Y2lz')

room = CiscoSpark::Room.new(id: 'Y3de...')
room.add_person(person)
=> #<CiscoSpark::Membership>

persist

You can call persist on an instance to create or update it through the API. If the instance already has an ID a PUT will be made to update the mutable attributes

room = CiscoSpark::Room.new(name: 'Ruby room')
room.persist
=> #<CiscoSpark::Room>

fetch

You can call fetch on an instance fetch or refresh an instance

room = CiscoSpark::Room.new(id: 'Y2lzY...')
room.fetch
=> #<CiscoSpark::Room>

destroy

You can call destroy on an instance to destroy it through the API

room = CiscoSpark::Room.new(id: 'Y2lzY...')
room.destroy
=> true

to_h

Convert a model instance into a hash

room = CiscoSpark::Room.fetch('Y2lzY...')
room.to_h
=> Hash