Class: Pulp::Connection::Handler

Inherits:
Object
  • Object
show all
Includes:
Pulp::Common::Debug
Defined in:
lib/pulp/connection/handler.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Pulp::Common::Debug

#debug, included

Constructor Details

#initialize(identifier, hostname, username = nil, password = nil, https = true) ⇒ Handler

Returns a new instance of Handler.



33
34
35
36
37
38
39
# File 'lib/pulp/connection/handler.rb', line 33

def initialize(identifier,hostname,username=nil,password=nil,https=true)
  @identifier = identifier
  @hostname = hostname
  @username = username
  @password = password
  @https = https
end

Class Attribute Details

.hostnameObject

Returns the value of attribute hostname.



8
9
10
# File 'lib/pulp/connection/handler.rb', line 8

def hostname
  @hostname
end

.passwordObject

Returns the value of attribute password.



8
9
10
# File 'lib/pulp/connection/handler.rb', line 8

def password
  @password
end

.usernameObject

Returns the value of attribute username.



8
9
10
# File 'lib/pulp/connection/handler.rb', line 8

def username
  @username
end

Class Method Details

.instance_for(identifier, h = nil, u = nil, p = nil, https = true) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/pulp/connection/handler.rb', line 10

def instance_for(identifier,h=nil,u=nil,p=nil,https=true)
  instances[identifier] ||= Handler.new(identifier,
                                        h||hostname,
                                        u||username,
                                        p||password,
                                        https
  )
end

.reset_allObject



23
24
25
# File 'lib/pulp/connection/handler.rb', line 23

def reset_all
  @instances = {}
end

.reset_instance(identifier) ⇒ Object



19
20
21
# File 'lib/pulp/connection/handler.rb', line 19

def reset_instance(identifier)
  instances.delete(identifier)
end

Instance Method Details

#api_pathObject



49
50
51
# File 'lib/pulp/connection/handler.rb', line 49

def api_path
  "/pulp/api" 
end

#connectionObject



45
46
47
# File 'lib/pulp/connection/handler.rb', line 45

def connection
  @connection ||= RestClient::Resource.new(url, :user => @username, :password => @password, :headers => { :accept => :json })
end

#parsedObject



41
42
43
# File 'lib/pulp/connection/handler.rb', line 41

def parsed
  JSON.parse((yield self.connection).body)
end

#urlObject



53
54
55
# File 'lib/pulp/connection/handler.rb', line 53

def url
  @url ||= "#{@https ? 'https' : 'http'}://#{@hostname}#{api_path}/#{@identifier.to_s.pluralize}"
end