Class: Livefyre::Conversation
- Inherits:
-
Object
- Object
- Livefyre::Conversation
- Defined in:
- lib/livefyre/conversation.rb
Overview
Public: Proxy object for a Livefyre [Conversation] (also called a Collection)
Instance Attribute Summary collapse
-
#article_id ⇒ Object
Returns the value of attribute article_id.
-
#id ⇒ Object
Returns the value of attribute id.
Class Method Summary collapse
-
.collectionMeta(client, article_id, title, link, tags) ⇒ Object
Internal: Generate a signed collectionMeta.
-
.create(client, article_id, title, link, tags = nil) ⇒ Object
Public: Create a new collection.
Instance Method Summary collapse
-
#comments ⇒ Object
Public: Fetch a list of comments from a conversation TODO: Not currently working.
-
#create_comment(user, body) ⇒ Object
Public: Create a comment on this conversation.
-
#follow_as(user) ⇒ Object
Public: Follow this conversation as the passed user.
-
#initialize(id, article_id) ⇒ Conversation
constructor
A new instance of Conversation.
-
#unfollow_as(user) ⇒ Object
Public: Unfollow this conversation as the passed user.
-
#update(title, link, tags = nil) ⇒ Object
Public: Update this collection with new metadata.
Constructor Details
#initialize(id, article_id) ⇒ Conversation
Returns a new instance of Conversation.
5 6 7 8 9 |
# File 'lib/livefyre/conversation.rb', line 5 def initialize(id, article_id) @id = id @article_id = article_id @client = Livefyre.client end |
Instance Attribute Details
#article_id ⇒ Object
Returns the value of attribute article_id.
4 5 6 |
# File 'lib/livefyre/conversation.rb', line 4 def article_id @article_id end |
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/livefyre/conversation.rb', line 4 def id @id end |
Class Method Details
.collectionMeta(client, article_id, title, link, tags) ⇒ Object
Internal: Generate a signed collectionMeta
client - [Client] identifying the site to create the collection on title - [String] Article title link - [String] Article link tags - [String, Array] Article tags
Returns [String] signed token
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/livefyre/conversation.rb', line 105 def self.collectionMeta(client, article_id, title, link, ) tag_str = case when Array .join "," when String when nil nil else raise "Invalid value given for tags: must be Array, String, or nil" end begin URI.parse(link) rescue URI::InvalidURIError => e raise "Invalid value for link: #{e.}" end = { :title => title, :url => link, :articleId => article_id, :tags => tag_str || "", } JWT.encode(, client.site_key) end |
.create(client, article_id, title, link, tags = nil) ⇒ Object
Public: Create a new collection
client - [Client] identifying the site to create the collection on article_id - [String] ID to use to identify this article title - [String] Article title link - [String] Article link tags - [String, Array] Article tags
Returns [Conversation]
85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/livefyre/conversation.rb', line 85 def self.create(client, article_id, title, link, = nil) = collectionMeta(client, article_id, title, link, ) response = client.quill.post "/api/v3.0/site/#{client.[:site_id]}/collection/create", {:collectionMeta => , :articleId => article_id}.to_json if response.success? body = JSON.parse(response.body) Conversation.new(body["data"]["collectionId"], article_id) else error = JSON.parse(response.body) raise APIException.new(error["msg"]) end end |
Instance Method Details
#comments ⇒ Object
Public: Fetch a list of comments from a conversation
TODO: Not currently working.
13 14 15 16 17 18 19 20 |
# File 'lib/livefyre/conversation.rb', line 13 def comments response = @client.bootstrap.get "/bs3/#{@client.[:domain]}/#{@client.[:network]}/#{@client.[:site_id]}/#{Base64.encode64 @article_id}/init" if response.success? JSON.parse response.body else raise APIException.new(response.body) end end |
#create_comment(user, body) ⇒ Object
Public: Create a comment on this conversation
user - [User] to create the comment as body - [String] body of the content
Returns [Comment]
42 43 44 |
# File 'lib/livefyre/conversation.rb', line 42 def create_comment(user, body) Comment.create(@client, user, self, body) end |
#follow_as(user) ⇒ Object
Public: Follow this conversation as the passed user
user - [User] to follow the conversation as
Returns [Boolean] true on success Raises [APIException] on failure
52 53 54 55 56 57 58 59 |
# File 'lib/livefyre/conversation.rb', line 52 def follow_as(user) response = @client.quill.post "/api/v3.0/collection/10584292/follow/", :lftoken => user.token, :collectionId => @id if response.success? true else raise APIException.new(response.body) end end |
#unfollow_as(user) ⇒ Object
Public: Unfollow this conversation as the passed user
user - [User] to unfollow the conversation as
Returns [Boolean] true on success Raises [APIException] on failure
67 68 69 70 71 72 73 74 |
# File 'lib/livefyre/conversation.rb', line 67 def unfollow_as(user) response = @client.quill.post "/api/v3.0/collection/10584292/unfollow/", :lftoken => user.token, :collectionId => @id if response.success? true else raise APIException.new(response.body) end end |
#update(title, link, tags = nil) ⇒ Object
Public: Update this collection with new metadata
Returns [Bool] true on success Raises [APIException] on failure
26 27 28 29 30 31 32 33 34 |
# File 'lib/livefyre/conversation.rb', line 26 def update(title, link, = nil) = self.class.collectionMeta(@client, @article_id, title, link, ) response = @client.quill.post "/api/v3.0/site/#{@client.[:site_id]}/collection/update/", {:collectionMeta => , :articleId => @article_id}.to_json if response.success? true else raise APIException.new(response.body) end end |