Class: FranklyClient
- Inherits:
-
Object
- Object
- FranklyClient
- Defined in:
- lib/frankly-ruby.rb
Overview
Instances of this class can be used to authenticate and query the Frankly REST APIs.
Instance Method Summary collapse
-
#close ⇒ Object
Discards all internal state maintained by this client.
-
#create(path, params = {}, payload = {}) ⇒ Hash/Array
This method exposes a generic interface for creating objects through the Frankly API.
-
#create_announcement(payload) ⇒ Hash
Creates a new announcement object in the app.
-
#create_file(payload) ⇒ Hash
Creates a new file object on Frankly servers and returns that object.
-
#create_room(payload) ⇒ Hash
Creates a new room object in the app.
-
#create_room_message(room_id, payload) ⇒ Hash
Creates a new message object in the room with id specified as first argument.
-
#delete(path, params = {}, payload = {}) ⇒ nil
This method exposes a generic interface for deleting objects through the Frankly API.
-
#delete_announcement(announcement_id) ⇒ nil
Deletes an announcement object with id sepecified as first argument from the app.
-
#delete_room(room_id) ⇒ nil
Deletes an room object with id sepecified as first argument from the app.
-
#initialize(address = 'https://app.franklychat.com/') ⇒ FranklyClient
constructor
A new instance of FranklyClient.
-
#open(app_key, app_secret) ⇒ nil
This should be the first method called on an instance of FranklyClient, after succesfully returning the client can be used to interact with the Frankly API.
-
#read(path, params = {}, payload = {}) ⇒ Hash/Array
This method exposes a generic interface for reading objects through the Frankly API.
-
#read_announcement(announcement_id) ⇒ Hash
Retrieves an announcement object with id sepecified as first argument from the app.
-
#read_announcement_list ⇒ Array
Retrieves a list of announcements available in the app.
-
#read_announcement_room_list(announcement_id) ⇒ Array
Retrieves the list of rooms that an annoucement has been published to.
-
#read_room(room_id) ⇒ Hash
Retrieves a room object with id specified as first argument from the app.
-
#read_room_list ⇒ Array
Retrieves the list of all available rooms from the app.
-
#read_room_message_list(room_id, params) ⇒ Array
Creates a new message object in the room with id specified as first argument.
-
#update(path, params = {}, payload = {}) ⇒ Hash/Array
This method exposes a generic interface for updating objects through the Frankly API.
-
#update_file(destination_url, file_obj, file_size, mime_type, encoding = nil) ⇒ nil
Creates a new file object on Frankly servers and returns that object.
-
#update_file_from_path(destination_url, file_path) ⇒ nil
Creates a new file object on Frankly servers and returns that object.
-
#update_room(room_id, payload) ⇒ Hash
Updates an existing room object in the app and return that object.
-
#upload(url, params, payload, content_length, content_type, content_encoding) ⇒ nil
This method exposes a generic interface for uploading file contents through the Frankly API.
-
#upload_file(file_obj, file_size, mime_type, encoding = nil, params) ⇒ Hash
This method is convenience wrapper for creating a new file object on the Frankly API and setting its content.
-
#upload_file_from_path(file_path, params) ⇒ Hash
This method is convenience wrapper for creating a new file object on the Frankly API and setting its content.
Constructor Details
#initialize(address = 'https://app.franklychat.com/') ⇒ FranklyClient
Returns a new instance of FranklyClient.
266 267 268 269 270 |
# File 'lib/frankly-ruby.rb', line 266 def initialize(address='https://app.franklychat.com/') @base_url = address @headers = {} @session_token = '' end |
Instance Method Details
#close ⇒ Object
Discards all internal state maintained by this client.
300 301 302 303 |
# File 'lib/frankly-ruby.rb', line 300 def close @session_token = nil @headers = nil end |
#create(path, params = {}, payload = {}) ⇒ Hash/Array
This method exposes a generic interface for creating objects through the Frankly API. Every create_* method is implemented on top of this one.
384 385 386 |
# File 'lib/frankly-ruby.rb', line 384 def create(path, params = {}, payload = {}) JSON.parse Generic.create(@base_url, @headers, @session_token, path, params, payload) end |
#create_announcement(payload) ⇒ Hash
Creates a new announcement object in the app. The properties of that new announcement are given as hash to the method.
480 481 482 |
# File 'lib/frankly-ruby.rb', line 480 def create_announcement(payload) JSON.parse Announcement.create_announcement(@base_url, @headers, @session_token, payload.to_json) end |
#create_file(payload) ⇒ Hash
Creates a new file object on Frankly servers and returns that object. The properties of that new file are given as a hash to the method.
570 571 572 |
# File 'lib/frankly-ruby.rb', line 570 def create_file(payload) JSON.parse Files.create_file(@base_url, @headers, @session_token, payload.to_json) end |
#create_room(payload) ⇒ Hash
Creates a new room object in the app. The properties of that new room are given as hash to the method.
314 315 316 |
# File 'lib/frankly-ruby.rb', line 314 def create_room(payload) JSON.parse Rooms.create_room(@base_url, @headers, @session_token, payload.to_json) end |
#create_room_message(room_id, payload) ⇒ Hash
Creates a new message object in the room with id specified as first argument. The properties of that new message are given as hash to the method.
541 542 543 |
# File 'lib/frankly-ruby.rb', line 541 def (room_id, payload) JSON.parse Message.(@base_url, @headers, @session_token, room_id, payload) end |
#delete(path, params = {}, payload = {}) ⇒ nil
This method exposes a generic interface for deleting objects through the Frankly API. Every delete_* method is implemented on top of this one.
439 440 441 |
# File 'lib/frankly-ruby.rb', line 439 def delete(path, params = {}, payload = {}) JSON.parse Generic.delete(@base_url, @headers, @session_token, path, params, payload) end |
#delete_announcement(announcement_id) ⇒ nil
Deletes an announcement object with id sepecified as first argument from the app. Note that deleting an announcement doesn’t remove messages from rooms it has already been published to. This operation cannot be undone!
504 505 506 |
# File 'lib/frankly-ruby.rb', line 504 def delete_announcement(announcement_id) Announcement.delete_announcement(@base_url, @headers, @session_token, announcement_id) end |
#delete_room(room_id) ⇒ nil
Deletes an room object with id sepecified as first argument from the app. Note that this will cause all messages sent to this room to be deleted as well, a safer approach could be to change the room status to ‘unpublished’ to hide it without erasing data. This operation cannot be undone!
365 366 367 |
# File 'lib/frankly-ruby.rb', line 365 def delete_room(room_id) Rooms.delete_room(@base_url, @headers, @session_token, room_id) end |
#open(app_key, app_secret) ⇒ nil
This should be the first method called on an instance of FranklyClient, after succesfully returning the client can be used to interact with the Frankly API.
290 291 292 293 294 295 296 297 |
# File 'lib/frankly-ruby.rb', line 290 def open(app_key, app_secret) nonce = Auth.nonce(@base_url)[1..-2] identity_token = generate_identity_token(app_key, app_secret, nonce, nil, 'admin') session = JSON.parse Auth.open(@base_url, identity_token) @session_token = session['token'] @headers = Util.build_headers end |
#read(path, params = {}, payload = {}) ⇒ Hash/Array
This method exposes a generic interface for reading objects through the Frankly API. Every read_* method is implemented on top of this one.
402 403 404 |
# File 'lib/frankly-ruby.rb', line 402 def read(path, params = {}, payload = {}) JSON.parse Generic.read(@base_url, @headers, @session_token, path, params, payload) end |
#read_announcement(announcement_id) ⇒ Hash
Retrieves an announcement object with id sepecified as first argument from the app.
491 492 493 |
# File 'lib/frankly-ruby.rb', line 491 def read_announcement(announcement_id) JSON.parse Announcement.read_announcement(@base_url, @headers, @session_token, announcement_id) end |
#read_announcement_list ⇒ Array
Retrieves a list of announcements available in the app.
513 514 515 |
# File 'lib/frankly-ruby.rb', line 513 def read_announcement_list JSON.parse Announcement.read_announcement_list(@base_url, @headers, @session_token) end |
#read_announcement_room_list(announcement_id) ⇒ Array
Retrieves the list of rooms that an annoucement has been published to.
525 526 527 |
# File 'lib/frankly-ruby.rb', line 525 def read_announcement_room_list(announcement_id) JSON.parse Announcement.read_announcement_room_list(@base_url, @headers, @session_token, announcement_id) end |
#read_room(room_id) ⇒ Hash
Retrieves a room object with id specified as first argument from the app.
334 335 336 |
# File 'lib/frankly-ruby.rb', line 334 def read_room(room_id) JSON.parse Rooms.read_room(@base_url, @headers, @session_token, room_id) end |
#read_room_list ⇒ Array
Retrieves the list of all available rooms from the app.
323 324 325 |
# File 'lib/frankly-ruby.rb', line 323 def read_room_list JSON.parse Rooms.read_room_list(@base_url, @headers, @session_token) end |
#read_room_message_list(room_id, params) ⇒ Array
Creates a new message object in the room with id specified as first argument. The properties of that new message are given as hash to the method.
557 558 559 |
# File 'lib/frankly-ruby.rb', line 557 def (room_id, params) JSON.parse Message.(@base_url, @headers, @session_token, room_id, params) end |
#update(path, params = {}, payload = {}) ⇒ Hash/Array
This method exposes a generic interface for updating objects through the Frankly API. Every read_* method is implemented on top of this one.
420 421 422 |
# File 'lib/frankly-ruby.rb', line 420 def update(path, params = {}, payload = {}) JSON.parse Generic.update(@base_url, @headers, @session_token, path, params, payload) end |
#update_file(destination_url, file_obj, file_size, mime_type, encoding = nil) ⇒ nil
Creates a new file object on Frankly servers and returns that object. The properties of that new file are given as a hash to the method.
596 597 598 |
# File 'lib/frankly-ruby.rb', line 596 def update_file(destination_url, file_obj, file_size, mime_type, encoding = nil) Files.upload_file(@base_url, @headers, @session_token, destination_url, file_obj, file_size, mime_type, encoding) end |
#update_file_from_path(destination_url, file_path) ⇒ nil
Creates a new file object on Frankly servers and returns that object. The properties of that new file are given as a hash to the method.
612 613 614 |
# File 'lib/frankly-ruby.rb', line 612 def update_file_from_path(destination_url, file_path) Files.update_file_from_path(@base_url, @headers, @session_token, destination_url, file_path) end |
#update_room(room_id, payload) ⇒ Hash
Updates an existing room object in the app and return that object. The properties of that new room are given as a hash to the method.
350 351 352 353 |
# File 'lib/frankly-ruby.rb', line 350 def update_room(room_id, payload) JSON.parse Rooms.update_room(@base_url, @headers, @session_token, room_id, payload.to_json) end |
#upload(url, params, payload, content_length, content_type, content_encoding) ⇒ nil
This method exposes a generic interface for uploading file contents through the Frankly API. Every upload_* method is implemented on top of this one.
467 468 469 |
# File 'lib/frankly-ruby.rb', line 467 def upload(url, params, payload, content_length, content_type, content_encoding) JSON.parse Generic.upload(@base_url, @headers, @session_token, url, params, payload, content_length, content_type, content_encoding) end |
#upload_file(file_obj, file_size, mime_type, encoding = nil, params) ⇒ Hash
This method is convenience wrapper for creating a new file object on the Frankly API and setting its content.
637 638 639 |
# File 'lib/frankly-ruby.rb', line 637 def upload_file(file_obj, file_size, mime_type, encoding = nil, params) Files.upload_file(@base_url, @headers, @session_token, destination_url, file_obj, file_size, mime_type, encoding, params) end |
#upload_file_from_path(file_path, params) ⇒ Hash
This method is convenience wrapper for creating a new file object on the Frankly API and setting its content.
652 653 654 |
# File 'lib/frankly-ruby.rb', line 652 def upload_file_from_path(file_path, params) Files.upload_file_from_path(@base_url, @headers, @session_token, file_path, params) end |