Class: Pulp::Connection::Base

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

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Pulp::Common::Lifecycle

#fields, included, #locked_fields, #record_fields, #special_fields, #user_fields

Constructor Details

#initialize(data = {}) ⇒ Base

Returns a new instance of Base.



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

def initialize(data={})
  set_fields(data)
end

Class Attribute Details

.hostnameObject

Returns the value of attribute hostname.



17
18
19
# File 'lib/pulp/connection/base.rb', line 17

def hostname
  @hostname
end

.httpsObject

Returns the value of attribute https.



17
18
19
# File 'lib/pulp/connection/base.rb', line 17

def https
  @https
end

.passwordObject

Returns the value of attribute password.



17
18
19
# File 'lib/pulp/connection/base.rb', line 17

def password
  @password
end

.usernameObject

Returns the value of attribute username.



17
18
19
# File 'lib/pulp/connection/base.rb', line 17

def username
  @username
end

Class Method Details

.baseObject



73
74
75
# File 'lib/pulp/connection/base.rb', line 73

def base
  Pulp::Connection::Handler.instance_for(self.identifier, hostname, username, password, (https.nil? ? true : https))
end

.base_delete(cmd, item = nil, params = nil) ⇒ Object



62
63
64
# File 'lib/pulp/connection/base.rb', line 62

def base_delete(cmd,item=nil,params=nil)
  base.parsed{|conn| conn[s(parse_item_cmd(item,cmd))].delete(merge_params(params)) }
end

.base_get(cmd, item = nil, params = nil) ⇒ Object



58
59
60
# File 'lib/pulp/connection/base.rb', line 58

def base_get(cmd,item=nil,params=nil)
  base.parsed{|conn| conn[s(parse_item_cmd(item,cmd))].get(merge_params(params)) }
end

.base_post(cmd, item = nil, params = nil) ⇒ Object



66
67
68
# File 'lib/pulp/connection/base.rb', line 66

def base_post(cmd,item=nil,params=nil)
  base.parsed{|conn| conn[s(parse_item_cmd(item,cmd))].post(params.nil? ? nil : params.to_json, :content_type => :json ) }
end

.base_put(cmd, item = nil, params = nil) ⇒ Object



69
70
71
# File 'lib/pulp/connection/base.rb', line 69

def base_put(cmd,item=nil,params=nil)
  base.parsed{|conn| conn[s(parse_item_cmd(item,cmd))].put(params.nil? ? nil : params.to_json, :content_type => :json ) }
end

.base_unparsed_delete(cmd, item = nil, params = nil) ⇒ Object



35
36
37
# File 'lib/pulp/connection/base.rb', line 35

def base_unparsed_delete(cmd,item=nil,params=nil)
  base.connection[s(parse_item_cmd(item,cmd))].delete(merge_params(params)).body
end

.base_unparsed_get(cmd, item = nil, params = nil) ⇒ Object



31
32
33
# File 'lib/pulp/connection/base.rb', line 31

def base_unparsed_get(cmd,item=nil,params=nil)
  base.connection[s(parse_item_cmd(item,cmd))].get(merge_params(params)).body
end

.base_unparsed_post(cmd, item = nil, params = nil) ⇒ Object



39
40
41
# File 'lib/pulp/connection/base.rb', line 39

def base_unparsed_post(cmd,item=nil,params=nil)
  base.connection[s(parse_item_cmd(item,cmd))].post(params.nil? ? nil : params.to_json, :content_type => :json ).body
end

.base_unparsed_put(cmd, item = nil, params = nil, binary_data = false) ⇒ Object



43
44
45
46
47
48
49
50
51
52
# File 'lib/pulp/connection/base.rb', line 43

def base_unparsed_put(cmd,item=nil,params=nil,binary_data=false)
  if binary_data
    p = params
    ct = 'application/stream'
  else
    p = params.nil? ? nil : params.to_json
    ct = :json
  end
  base.connection[s(parse_item_cmd(item,cmd))].put(p, :content_type => ct).body
end

.identifierObject



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

def identifier
  @identifier ||= name.demodulize.downcase
end

.merge_params(params) ⇒ Object



85
86
87
# File 'lib/pulp/connection/base.rb', line 85

def merge_params(params)
  params.nil? ? {} : { :params => params }
end

.parse_item_cmd(item, cmd) ⇒ Object



81
82
83
# File 'lib/pulp/connection/base.rb', line 81

def parse_item_cmd(item,cmd)
  "#{"/#{item}" unless item.nil?}#{(cmd =~ /^\//) ? cmd : "/#{cmd}"}"
end

.plain_baseObject



77
78
79
# File 'lib/pulp/connection/base.rb', line 77

def plain_base
  Pulp::Connection::Handler.instance_for('', hostname, username, password, (https.nil? ? true : https))
end

.plain_get(cmd, params = nil) ⇒ Object



54
55
56
# File 'lib/pulp/connection/base.rb', line 54

def plain_get(cmd, params=nil)
  plain_base.parsed{|conn| conn[s(cmd.sub(/^#{Regexp.escape(plain_base.api_path)}\//,''))].get(merge_params(params)) }
end

.plain_unparsed_get(cmd, params = nil) ⇒ Object



27
28
29
# File 'lib/pulp/connection/base.rb', line 27

def plain_unparsed_get(cmd, params=nil)
  plain_base.connection[s(cmd.sub(/^#{Regexp.escape(plain_base.api_path)}\//,''))].get(merge_params(params)).body
end

.resetObject



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

def reset
  Pulp::Connection::Handler.reset_instance(self.identifier)
end

.s(uri) ⇒ Object

sanitize uri if uri is already escaped, we don’t do anything, otherwise we escape it.



91
92
93
# File 'lib/pulp/connection/base.rb', line 91

def s(uri)
  (URI.decode(uri) != uri) ? uri : URI.escape(uri)
end

Instance Method Details

#set_fields(field_data) ⇒ Object



12
13
14
# File 'lib/pulp/connection/base.rb', line 12

def set_fields(field_data)
  @fields = field_data
end