Class: Livefyre::Conversation
- Inherits:
-
Object
- Object
- Livefyre::Conversation
- Defined in:
- lib/livefyre/conversation.rb
Overview
Proxy object for a Livefyre [Conversation] (also called a Collection)
Instance Attribute Summary (collapse)
Class Method Summary (collapse)
-
+ (String) collectionMeta(client, article_id, title, link, tags)
private
Generate a signed collectionMeta.
-
+ (Conversation) create(client, article_id, title, link, tags = nil)
Create a new collection.
Instance Method Summary (collapse)
-
- (Object) comments
Fetch a list of comments from a conversation.
-
- (Comment) create_comment(user, body)
Create a comment on this conversation.
-
- (Boolean) follow_as(user)
Follow this conversation as the passed user.
-
- (Conversation) initialize(id, article_id)
constructor
A new instance of Conversation.
-
- (Boolean) unfollow_as(user)
Unfollow this conversation as the passed user.
-
- (Bool) update(title, link, tags = nil)
Update this collection with new metadata.
Constructor Details
- (Conversation) initialize(id, article_id)
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
- (Object) article_id
4 5 6 |
# File 'lib/livefyre/conversation.rb', line 4 def article_id @article_id end |
- (Object) id
4 5 6 |
# File 'lib/livefyre/conversation.rb', line 4 def id @id end |
Class Method Details
+ (String) collectionMeta(client, article_id, title, link, tags)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Generate a signed collectionMeta
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 |
+ (Conversation) create(client, article_id, title, link, tags = nil)
Create a new collection
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
- (Object) comments
Not currently working.
Fetch a list of comments from a conversation
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 |
- (Comment) create_comment(user, body)
Create a comment on this conversation
42 43 44 |
# File 'lib/livefyre/conversation.rb', line 42 def create_comment(user, body) Comment.create(@client, user, self, body) end |
- (Boolean) follow_as(user)
Follow this conversation as the passed user
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 |
- (Boolean) unfollow_as(user)
Unfollow this conversation as the passed user
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 |
- (Bool) update(title, link, tags = nil)
Update this collection with new metadata
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 |