Class: Livefyre::Client
- Inherits:
-
Object
- Object
- Livefyre::Client
- Extended by:
- Forwardable
- Defined in:
- lib/livefyre/client.rb
Overview
Primary interface to the Livefyre API
Constant Summary
- ROLES =
Valid roles for #set_user_role
%w(admin member none outcast owner)
- SCOPES =
Valid scopes for #set_user_role
%w(domain site conv)
Instance Attribute Summary (collapse)
- - (Object) bootstrap
- - (Object) host
- - (Object) http_client
- - (Object) key
- - (Object) options
- - (Object) quill
- - (Object) search
- - (Object) site_key
- - (Object) stream
- - (Object) system_token
Instance Method Summary (collapse)
-
- (Object) identifier
private
Identifier to use to uniquely identify this client.
-
- (Client) initialize(options = {})
constructor
Create a new Livefyre client.
-
- (String) jid(id)
Transform the given ID into a jid.
-
- (Bool) set_user_role(user_id, role, scope = 'domain', scope_id = nil)
Sets a user's role (affiliation) in a given scope.
-
- (String) sign(data)
Sign a data structure with this client's network key.
-
- (String) to_s
private
Returns a cleaner string representation of this object.
-
- (Livefyre::User) user(uid, display_name = nil)
Create a User with this client's credentials.
-
- (Hash) validate(data)
Validates and decodes a JWT token.
Constructor Details
- (Client) initialize(options = {})
Create a new Livefyre client.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/livefyre/client.rb', line 21 def initialize( = {}) @options = .clone @host = .delete(:network) || .delete(:host) raise "Invalid host" if @host.nil? @http_client = Faraday.new(:url => "http://#{@host}") @quill = Faraday.new(:url => "http://quill.#{@host}") @stream = Faraday.new(:url => "http://stream.#{@host}") @search = Faraday.new(:url => "http://search.#{@host}") @bootstrap = Faraday.new(:url => "http://bootstrap.#{@host}") @site_key = [:site_key] @key = .delete(:secret) || .delete(:key) || .delete(:network_key) raise "Invalid secret key" if @key.nil? @system_token = .delete(:system_token) raise "Invalid system token" if @system_token.nil? end |
Instance Attribute Details
- (Object) bootstrap
11 12 13 |
# File 'lib/livefyre/client.rb', line 11 def bootstrap @bootstrap end |
- (Object) host
11 12 13 |
# File 'lib/livefyre/client.rb', line 11 def host @host end |
- (Object) http_client
11 12 13 |
# File 'lib/livefyre/client.rb', line 11 def http_client @http_client end |
- (Object) key
11 12 13 |
# File 'lib/livefyre/client.rb', line 11 def key @key end |
- (Object) options
11 12 13 |
# File 'lib/livefyre/client.rb', line 11 def @options end |
- (Object) quill
11 12 13 |
# File 'lib/livefyre/client.rb', line 11 def quill @quill end |
- (Object) search
11 12 13 |
# File 'lib/livefyre/client.rb', line 11 def search @search end |
- (Object) site_key
11 12 13 |
# File 'lib/livefyre/client.rb', line 11 def site_key @site_key end |
- (Object) stream
11 12 13 |
# File 'lib/livefyre/client.rb', line 11 def stream @stream end |
- (Object) system_token
11 12 13 |
# File 'lib/livefyre/client.rb', line 11 def system_token @system_token end |
Instance Method Details
- (Object) identifier
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.
Identifier to use to uniquely identify this client.
118 119 120 |
# File 'lib/livefyre/client.rb', line 118 def identifier @identifier ||= "RubyLib-#{Process.pid}-#{local_ip}-#{object_id}" end |
- (String) jid(id)
Transform the given ID into a jid
111 112 113 |
# File 'lib/livefyre/client.rb', line 111 def jid(id) "%s@%s" % [id, host] end |
- (Bool) set_user_role(user_id, role, scope = 'domain', scope_id = nil)
Sets a user's role (affiliation) in a given scope.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/livefyre/client.rb', line 80 def set_user_role(user_id, role, scope = 'domain', scope_id = nil) raise "Invalid scope" unless SCOPES.include? scope raise "Invalid role" unless ROLES.include? role post_data = { :affiliation => role, :lftoken => system_token, } case scope when "domain" post_data[:domain_wide] = 1 when "conv" raise "Invalid scope_id" if scope_id.nil? post_data[:conv_id] = scope_id when "site" raise "Invalid scope_id" if scope_id.nil? post_data[:site_id] = scope_id end result = post "/api/v1.1/private/management/user/#{jid(user_id)}/role/", post_data if result.success? true else raise APIException.new(result.body) end end |
- (String) sign(data)
Sign a data structure with this client's network key.
42 43 44 |
# File 'lib/livefyre/client.rb', line 42 def sign(data) JWT.encode(data, @key) 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
125 126 127 |
# File 'lib/livefyre/client.rb', line 125 def to_s "#<#{self.class.name}:0x#{object_id.to_s(16).rjust(14, "0")} host='#{host}' key='#{key}'>" end |
- (Livefyre::User) user(uid, display_name = nil)
Create a User with this client's credentials.
60 61 62 |
# File 'lib/livefyre/client.rb', line 60 def user(uid, display_name = nil) User.new(uid, self, display_name) end |
- (Hash) validate(data)
Validates and decodes a JWT token
50 51 52 |
# File 'lib/livefyre/client.rb', line 50 def validate(data) JWT.decode(data, @key) end |