Class: Livefyre::Domain
- Inherits:
-
Object
- Object
- Livefyre::Domain
- Defined in:
- lib/livefyre/domain.rb
Overview
Proxy for a Livefyre domain resource
Instance Attribute Summary (collapse)
Instance Method Summary (collapse)
-
- (Bool) add_admin(user)
Adds a user to the list of owners for this domain.
-
- (Bool) add_owner(user)
Adds a user to the list of owners for this domain.
-
- (Bool) add_user(profile)
Push a user profile to this domain.
-
- (Array<User>) admins
Retrieve a list of owners associated with this domain.
-
- (Site) create_site(url)
Create a new site on this domain.
-
- (Domain) initialize(client = nil)
constructor
A new instance of Domain.
-
- (Array<User>) owners
Retrieve a list of owners associated with this domain.
-
- (Bool) remove_admin(user)
Removes a user from the list of owners for this domain.
-
- (Bool) remove_owner(user)
Removes a user from the list of owners for this domain.
-
- (Array<Conversation>) search_conversations(query, options = {})
Search conversations on this domain.
-
- (Bool) set_pull_url(url)
Sets the profile pull URL for the entire network.
-
- (Array<Site>) sites
Get a list of sites for this domain.
-
- (String) to_s
private
Returns a cleaner string representation of this object.
-
- (Array<User>) users
Get a list of users on this domain.
Constructor Details
- (Domain) initialize(client = nil)
A new instance of Domain
6 7 8 |
# File 'lib/livefyre/domain.rb', line 6 def initialize(client = nil) @client = client || Livefyre.client end |
Instance Attribute Details
- (Object) client
4 5 6 |
# File 'lib/livefyre/domain.rb', line 4 def client @client end |
Instance Method Details
- (Bool) add_admin(user)
Adds a user to the list of owners for this domain
172 173 174 175 176 177 178 179 180 |
# File 'lib/livefyre/domain.rb', line 172 def add_admin(user) user = User.get_user(user, client) response = client.post "/admins/?actor_token=#{CGI.escape user.token}", {:jid => user.jid} if response.success? true else raise APIException.new(response.body) end end |
- (Bool) add_owner(user)
Adds a user to the list of owners for this domain
125 126 127 128 129 130 131 132 133 |
# File 'lib/livefyre/domain.rb', line 125 def add_owner(user) user = User.get_user(user, client) response = client.post "/owners/?actor_token=#{CGI.escape client.system_token}", {:jid => user.jid} if response.success? true else raise APIException.new(response.body) end end |
- (Bool) add_user(profile)
Push a user profile to this domain
80 81 82 83 84 85 86 87 88 |
# File 'lib/livefyre/domain.rb', line 80 def add_user(profile) raise "Invalid ID" if profile["id"].nil? response = client.post "/profiles/?actor_token=#{CGI.escape client.system_token}&id=#{CGI.escape profile["id"]}", profile if response.success? true else raise APIException.new(response.body) end end |
- (Array<User>) admins
Retrieve a list of owners associated with this domain
155 156 157 158 159 160 161 162 163 164 |
# File 'lib/livefyre/domain.rb', line 155 def admins response = client.get "/admins/", {:actor_token => client.system_token} if response.success? JSON.parse(response.body).map do |u| client.user u.split("@", 2).first end else raise APIException.new(response.body) end end |
- (Site) create_site(url)
Create a new site on this domain
94 95 96 97 98 99 100 101 102 |
# File 'lib/livefyre/domain.rb', line 94 def create_site(url) response = client.post "/sites/?actor_token=#{CGI.escape client.system_token}&url=#{CGI.escape url}" if response.success? opts = JSON.parse response.body Site.new(opts["id"], client, opts) else raise APIException.new(response.body) end end |
- (Array<User>) owners
Retrieve a list of owners associated with this domain
108 109 110 111 112 113 114 115 116 117 |
# File 'lib/livefyre/domain.rb', line 108 def owners response = client.get "/owners/", {:actor_token => client.system_token} if response.success? JSON.parse(response.body).map do |u| client.user u.split("@", 2).first end else raise APIException.new(response.body) end end |
- (Bool) remove_admin(user)
Removes a user from the list of owners for this domain
188 189 190 191 192 193 194 195 196 |
# File 'lib/livefyre/domain.rb', line 188 def remove_admin(user) user = User.get_user(user, client) response = client.delete "/admin/#{user.jid}/?actor_token=#{CGI.escape client.system_token}" if response.success? true else raise APIException.new(response.body) end end |
- (Bool) remove_owner(user)
Removes a user from the list of owners for this domain
141 142 143 144 145 146 147 148 149 |
# File 'lib/livefyre/domain.rb', line 141 def remove_owner(user) user = User.get_user(user, client) response = client.delete "/owner/#{user.jid}/?actor_token=#{CGI.escape client.system_token}" if response.success? true else raise APIException.new(response.body) end end |
- (Array<Conversation>) search_conversations(query, options = {})
Search conversations on this domain
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/livefyre/domain.rb', line 40 def search_conversations(query, = {}) query = {} query[:return_fields] = [:fields] if [:fields] query[:fields] = [:fields] || [:article, :title, :body] query[:order] = [:sort] || "relevance" query[:max] = [:max].to_i if [:max] query[:since] = [:since].utc.iso8601 if [:since] query[:until] = [:until].utc.iso8601 if [:until] query[:sites] = [:sites].map {|s| s.is_a?(Site) ? s.id : s.to_i } query[:cursor] = (query[:max] || 10).to_i * [:page].to_i if [:page] query[:apitoken] = client.system_token ## TODO: I expect this is wrong; this param seems to expect the old-style API token. response = client.search.get "/api/v1.1/public/search/convs/", query if response.success? JSON.parse(response.body) else raise APIException.new(response.body) end end |
- (Bool) set_pull_url(url)
Sets the profile pull URL for the entire network.
204 205 206 207 208 209 210 211 |
# File 'lib/livefyre/domain.rb', line 204 def set_pull_url(url) result = client.post "/", {:pull_profile_url => url, :actor_token => client.system_token} if result.success? return true else raise APIException.new(result.body) end end |
- (Array<Site>) sites
Get a list of sites for this domain
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/livefyre/domain.rb', line 14 def sites response = client.get "/sites/?actor_token=#{CGI.escape client.system_token}" if response.success? JSON.parse(response.body).map do |site| Site.new(site["id"], client, site) end else raise APIException.new(response.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
216 217 218 |
# File 'lib/livefyre/domain.rb', line 216 def to_s "#<#{self.class.name}:0x#{object_id.to_s(16).rjust(14, "0")} host='#{client.host}'>" end |
- (Array<User>) users
Get a list of users on this domain
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/livefyre/domain.rb', line 63 def users response = client.get "/profiles/?actor_token=#{CGI.escape client.system_token}" if response.success? JSON.parse(response.body).map do |site| User.new(site["id"], client, site["display_name"]) end else raise APIException.new(response.body) end end |