Class: Openas2::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/openas2/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username, password, host, port) ⇒ Configuration

Returns a new instance of Configuration.



5
6
7
8
9
# File 'lib/openas2/configuration.rb', line 5

def initialize(username, password, host, port)
  @command    = Openas2::Remote::Command.new(username, password)
  @host = host
  @port = port
end

Instance Attribute Details

#commandObject

Returns the value of attribute command.



3
4
5
# File 'lib/openas2/configuration.rb', line 3

def command
  @command
end

#connectionObject

Returns the value of attribute connection.



3
4
5
# File 'lib/openas2/configuration.rb', line 3

def connection
  @connection
end

#hostObject

Returns the value of attribute host.



3
4
5
# File 'lib/openas2/configuration.rb', line 3

def host
  @host
end

#passwordObject

Returns the value of attribute password.



3
4
5
# File 'lib/openas2/configuration.rb', line 3

def password
  @password
end

#portObject

Returns the value of attribute port.



3
4
5
# File 'lib/openas2/configuration.rb', line 3

def port
  @port
end

#usernameObject

Returns the value of attribute username.



3
4
5
# File 'lib/openas2/configuration.rb', line 3

def username
  @username
end

Instance Method Details

#add_partner(as2_id, email, name, x509_alias) ⇒ Object



36
37
38
39
# File 'lib/openas2/configuration.rb', line 36

def add_partner(as2_id, email, name, x509_alias)
  params = "as2_id=#{as2_id} email=#{email} name=#{name} x509_alias=#{x509_alias}"
  send("partner add #{params}")
end

#partner(name) ⇒ Object



24
25
26
27
28
# File 'lib/openas2/configuration.rb', line 24

def partner(name)
  partner = send("partner view #{name}")
  xml=Nokogiri::XML(partner)
  xml.xpath('//result').map &:text
end

#partnersObject



30
31
32
33
34
# File 'lib/openas2/configuration.rb', line 30

def partners
  list = send("partner list")
  xml=Nokogiri::XML(list)
  xml.xpath('//result').map &:text
end

#remove_partner(name) ⇒ Object



41
42
43
44
# File 'lib/openas2/configuration.rb', line 41

def remove_partner(name)
  params = "partner delete #{name}"
  send("partner delete #{params}")
end

#send(cmd) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/openas2/configuration.rb', line 11

def send(cmd)
  @connection = Openas2::Remote::Connection.new(@host, @port)
  @connection.connect
  cmd = @command.build cmd
  puts cmd
  @connection.puts(cmd)
  # also parse attributes into hash
  # Hash[*s.gsub(/{|}|\s/, '').split(",").map{|a|a.split('=')}.flatten]
  r = "<results>#{@connection.readlines.join}</results>"
  @connection.close
  r
end