Class: Livefyre::User
- Inherits:
-
Object
- Object
- Livefyre::User
- Defined in:
- lib/livefyre/user.rb
Overview
Interface for dealing with Livefyre users by User ID.
Instance Attribute Summary (collapse)
Class Method Summary (collapse)
-
+ (User) get_user(userish, client)
Fetch a Livefyre::User from a user record or ID.
-
+ (String) get_user_id(userish)
Coerce a string or [User] into a user ID.
-
+ (Bool) refresh(id)
Convenience method to refresh a user by ID.
Instance Method Summary (collapse)
-
- (Object) client=(client)
Setter for the client to associate with this user.
-
- (Boolean) follow_conversation(conversation)
Follow the given conversation.
-
- (User) initialize(id, client = nil, display_name = nil, args = {})
constructor
Create a new Livefyre User proxy.
-
- (String) jid
Internal - Fetch an internal Jabber-style ID for this user.
-
- (Hash) profile
Retrieve user information and recent comments for this user from Livefyre.
-
- (Bool) push(data)
Update this user's profile on Livefyre.
-
- (Bool) refresh
Invoke Livefyre ping-to-pull to refresh this user's data.
-
- (String) to_s
private
Returns a cleaner string representation of this object.
-
- (String) token(max_age = 86400)
Creates a signed JWT token for this user.
-
- (Boolean) unfollow_conversation(conversation)
Unfollow the given conversation.
Constructor Details
- (User) initialize(id, client = nil, display_name = nil, args = {})
Create a new Livefyre User proxy.
11 12 13 14 15 16 |
# File 'lib/livefyre/user.rb', line 11 def initialize(id, client = nil, display_name = nil, args = {}) @id = id @client = client || Livefyre.client @display_name = display_name @options = args end |
Instance Attribute Details
- (Object) display_name
4 5 6 |
# File 'lib/livefyre/user.rb', line 4 def display_name @display_name end |
- (Object) id
4 5 6 |
# File 'lib/livefyre/user.rb', line 4 def id @id end |
Class Method Details
+ (User) get_user(userish, client)
Fetch a Livefyre::User from a user record or ID
145 146 147 148 149 150 151 152 153 |
# File 'lib/livefyre/user.rb', line 145 def self.get_user(userish, client) case userish when User userish.client = client userish else new get_user_id(userish), client end end |
+ (String) get_user_id(userish)
Coerce a string or [User] into a user ID
116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/livefyre/user.rb', line 116 def self.get_user_id(userish) case userish when String userish.split("@", 2).first when Fixnum userish when User userish.id else raise "Invalid user ID" end end |
+ (Bool) refresh(id)
Convenience method to refresh a user by ID
135 136 137 |
# File 'lib/livefyre/user.rb', line 135 def self.refresh(id) new(id).refresh end |
Instance Method Details
- (Object) client=(client)
Setter for the client to associate with this user
37 38 39 |
# File 'lib/livefyre/user.rb', line 37 def client=(client) @client = client end |
- (Boolean) follow_conversation(conversation)
Follow the given conversation
97 98 99 |
# File 'lib/livefyre/user.rb', line 97 def follow_conversation(conversation) conversation.follow_as self end |
- (String) jid
Internal - Fetch an internal Jabber-style ID for this user
44 45 46 |
# File 'lib/livefyre/user.rb', line 44 def jid "#{id}@#{@client.host}" end |
- (Hash) profile
Retrieve user information and recent comments for this user from Livefyre
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/livefyre/user.rb', line 23 def profile response = @client.get "/profile/#{id}/", {:actor_token => token} if response.success? begin JSON.parse(response.body)["data"] rescue JSON::ParserError => e raise APIException.new("Parse error: #{e.}") end else raise APIException.new(result.body) end end |
- (Bool) push(data)
Update this user's profile on Livefyre
70 71 72 73 74 75 76 77 |
# File 'lib/livefyre/user.rb', line 70 def push(data) result = @client.post "/profiles/?actor_token=#{CGI.escape @client.system_token}&id=#{id}", {:data => data.to_json} if result.success? true else raise APIException.new(result.body) end end |
- (Bool) refresh
Invoke Livefyre ping-to-pull to refresh this user's data
83 84 85 86 87 88 89 90 |
# File 'lib/livefyre/user.rb', line 83 def refresh result = @client.post "/api/v3_0/user/#{id}/refresh", {:lftoken => @client.system_token} if result.success? true else raise APIException.new(result.body) end end |
- (String) to_s
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.
Returns a cleaner string representation of this object
158 159 160 |
# File 'lib/livefyre/user.rb', line 158 def to_s "#<#{self.class.name}:0x#{object_id.to_s(16).rjust(14, "0")} id='#{id}' display_name='#{display_name}'>" end |
- (String) token(max_age = 86400)
Creates a signed JWT token for this user
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/livefyre/user.rb', line 53 def token(max_age = 86400) data = { :domain => @client.host, :user_id => id, :expires => Time.now.to_i + max_age }.tap do |opts| opts[:display_name] = @display_name unless @display_name.nil? end JWT.encode(data, @client.key) end |
- (Boolean) unfollow_conversation(conversation)
Unfollow the given conversation
106 107 108 |
# File 'lib/livefyre/user.rb', line 106 def unfollow_conversation(conversation) conversation.unfollow_as self end |