Class: Livefyre::Domain

Inherits:
Object
  • Object
show all
Defined in:
lib/livefyre/domain.rb

Overview

Proxy for a Livefyre domain resource

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

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

Parameters:

  • user (String, User, Integer)

    User or user ID to add as an admin

Returns:

  • (Bool)

    Returns Bool true on success

Raises:



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

Parameters:

  • user (String, User, Integer)

    User or user ID to add as an owner

Returns:

  • (Bool)

    Returns Bool true on success

Raises:



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

Parameters:

  • profile (Hash)

    Hash of user data to publish per the Livefyre profile schema

Returns:

  • (Bool)

    Returns Bool true on success

Raises:



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

Returns:

  • (Array<User>)

    Returns Array<User> An array of users

Raises:



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

Returns:

Raises:



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

Returns:

  • (Array<User>)

    Returns Array<User> An array of users

Raises:



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

Parameters:

  • user (String, User, Integer)

    User or user ID to remove as an admin

Returns:

  • (Bool)

    Returns Bool true on success

Raises:



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

Parameters:

  • user (String, User, Integer)

    User or user ID to remove as an owner

Returns:

  • (Bool)

    Returns Bool true on success

Raises:



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

Parameters:

  • query

    string to query for

  • options (Hash) (defaults to: {})

    of options

  • :fields

    list of fields to search. Default [:article, :title, :body]

  • :sort

    Sort order for options. Valid values are [:relevance, :created, :updated, :hotness, :ncomments]. Default is :relevance

  • :fields

    List of fields to return in the result. Valid values are: article_id, site_id, domain_id, title, published, updated, author, url, ncomment, nuser, annotation, nlp, hotness, hottest_value, hottest_time, peak, peak_value, peak_time, comments:5, users:5, comment_state, hit_field, dispurl, relevancy

  • :max

    Maximum number of fields to return

  • :since (DateTime)

    Minimum date of results to return

  • :until (DateTime)

    Maximum date of results to return

  • :sites

    Array of Sites or site IDs to limit results to. Maximum 5 sites.

  • :page

    Page of results to fetch. Default 1.

Returns:

  • (Array<Conversation>)

    Returns Array<Conversation> An array of matching conversations

Raises:



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, options = {})
  query = {}
  query[:return_fields] = options[:fields] if options[:fields]
  query[:fields]   = options[:fields] || [:article, :title, :body]
  query[:order]    = options[:sort] || "relevance"
  query[:max]      = options[:max].to_i if options[:max]
  query[:since]    = options[:since].utc.iso8601 if options[:since]
  query[:until]    = options[:until].utc.iso8601 if options[:until]
  query[:sites]    = options[:sites].map {|s| s.is_a?(Site) ? s.id : s.to_i }
  query[:cursor]   = (query[:max] || 10).to_i * options[:page].to_i if options[: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.

Parameters:

  • url

    A URL template that includes the string "{id}" in it somewhere

Returns:

  • (Bool)

    Returns Bool true on success

Raises:

  • APIException if the request failed



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

Returns:

  • (Array<Site>)

    Returns Array<Site> An array of sites

Raises:



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

Returns:

  • (String)

    Returns String representation of this class



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

Returns:

  • (Array<User>)

    Returns Array<User> An array of users

Raises:



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