Module: Opencrx::Account

Defined in:
lib/opencrx.rb

Defined Under Namespace

Classes: AccountRecord, Contact, Group, LegalEntity, UnspecifiedAccount

Constant Summary collapse

SUFFIX =
"/opencrx-rest-CRX/org.opencrx.kernel.account1/provider/CRX/segment/Standard/account"
KEY =
Regexp.new('^org.opencrx.kernel.account1.(.*)$')
RESULTSET =
'org.openmdx.kernel.ResultSet'

Class Method Summary collapse

Class Method Details

.build_record(hash) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
# File 'lib/opencrx.rb', line 87

def self.build_record(hash)
  puts "Expected a single key, got [#{hash.keys}]" unless hash.keys.length == 1
  key = hash.keys.first
  key.match(KEY)
  klass_name = $1
  if (klass = ActiveSupport::Inflector.safe_constantize("Opencrx::Account::#{klass_name}"))
    klass.new(hash)
  else
    puts "Dont understand record type [#{klass_name}]"
  end
end

.failure(response) ⇒ Object



99
100
101
102
103
104
# File 'lib/opencrx.rb', line 99

def self.failure(response)
  ap response.request
  ap response.response
  ap response.parsed_response
  nil
end

.get(id) ⇒ Object



52
53
54
55
56
# File 'lib/opencrx.rb', line 52

def self.get(id)
  response = session.get(SUFFIX + "/#{id}")
  #ap Nokogiri.XML(response.body)
  build_record(response)
end

.parse_resultset(hash) ⇒ Object



80
81
82
83
84
85
# File 'lib/opencrx.rb', line 80

def self.parse_resultset(hash)
  hash.map do |key, value|
    next if %w(href hasMore).include? key
    build_record(key => value)
  end.compact
end

.post(xml) ⇒ Object



68
69
70
# File 'lib/opencrx.rb', line 68

def self.post(xml)
  build_record session.post(SUFFIX, body: xml)
end

.put(url, xml) ⇒ Object



72
73
74
# File 'lib/opencrx.rb', line 72

def self.put(url, xml)
  build_record session.put(url, body: xml)
end

.query(params = {}) ⇒ Object



58
59
60
61
62
63
64
65
66
# File 'lib/opencrx.rb', line 58

def self.query(params = {})
  response = session.get(SUFFIX, query: params)
  key = response.keys.first
  if key == RESULTSET
    parse_resultset(response[key])
  else
    failure(response)
  end
end

.sessionObject



76
77
78
# File 'lib/opencrx.rb', line 76

def self.session
  Opencrx::session
end