Class: Openfire::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/openfire/client.rb

Constant Summary collapse

HER_CLIENT =
Her::API.new

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, token, options = {}) ⇒ Client

Returns a new instance of Client.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/openfire/client.rb', line 8

def initialize(url, token, options={})
  url.gsub!(/\/$/,'')
  url = "http://#{url}" unless url.match /^http/
  url = "#{url}/plugins/restapi/v1/"
  headers = {
    'Authorization' => token,
    'Content-Type' => 'application/json',
    'Accept' => 'application/json'
  }
  HER_CLIENT.setup url: url, headers: headers do |c|
    c.request :json
    c.response :openfire_xml,  content_type: /^application\/xml$/
    c.response :openfire_json, content_type: /(^application\/json$)|(^$)/
    c.use Faraday::Adapter::NetHttp
  end
end

Instance Attribute Details

#her_clientObject

Returns the value of attribute her_client.



4
5
6
# File 'lib/openfire/client.rb', line 4

def her_client
  @her_client
end

Instance Method Details

#groupsObject



25
26
27
# File 'lib/openfire/client.rb', line 25

def groups
  @groups ||= Openfire::Ruby::Group
end

#usersObject



29
30
31
# File 'lib/openfire/client.rb', line 29

def users
  @users ||= Openfire::Ruby::User
end