class Cmsso::Member
Attributes
email[RW]
first_name[RW]
id[RW]
last_name[RW]
note[RW]
reference[RW]
roles[RW]
status[RW]
time_zone[RW]
Public Class Methods
create(headers)
click to toggle source
# File app/models/cmsso/member.rb, line 96 def self.create(headers) # get person reference from http header person_from_header = get_person_from_header(headers) return nil unless person_from_header # call service person = nil # set proxy as defined during configuration ENV['http_proxy'] = Cmsso.configuration.proxy request = build_request(person_from_header) puts request begin RestClient.put Cmsso.configuration.base_uri, request, :content_type => :json do |response,request,result| # parse reponse and return person object person = Member.new(JSON.parse(response)["response"]["persons"][0]) # check about invalid status unless person.status == 'valid' @@type, @@note = :role_or_person,person.note return nil end end # parsing error rescue JSON::ParserError => e @@type, @@note = :parse,"Error while parsing role service response" return nil # service specific rescue SocketError, Errno::ECONNREFUSED => e @@type, @@note = :service,"Error while calling role service: #{e.to_s}" return nil # unexpected exceptions rescue => e @@type, @@note = :unexpected,"Error while calling role service: #{e.to_s}" return nil end return person end
find(headers)
click to toggle source
# File app/models/cmsso/member.rb, line 53 def self.find(headers) # get person reference from http header person_from_header = get_person_from_header(headers) return nil unless person_from_header # call service person = nil # set proxy as defined during configuration ENV['http_proxy'] = Cmsso.configuration.proxy if ENV begin RestClient.post Cmsso.configuration.base_uri + "/role", build_request(person_from_header), :content_type => :json do |response,request,result| # parse reponse and return person object person = Member.new(JSON.parse(response)["response"]["persons"][0]) # check about invalid status unless person.status == 'valid' @@type, @@note = :role_or_person, person.note return nil end end # parsing error rescue JSON::ParserError => e @@type, @@note = :parse,"Error while parsing role service response" return nil # service specific rescue SocketError, Errno::ECONNREFUSED => e @@type, @@note = :service,"Error while calling role service: #{e.to_s}" return nil # unexpected exceptions rescue => e @@type, @@note = :unexpected,"Error while calling role service: #{e.to_s}" return nil end return person end
new(args={})
click to toggle source
# File app/models/cmsso/member.rb, line 18 def initialize(args={}) return nil unless args.class == Hash # convert keys to symbols new_args = ActiveSupport::HashWithIndifferentAccess.new(args) # assign and format @id = new_args[:person_id] @reference = new_args[:person_reference] @first_name = new_args[:first_name] @last_name = new_args[:last_name] @email = new_args[:email] @time_zone = new_args[:time_zone] @roles = [] @roles = new_args[:roles].map{ |item| item.downcase.to_sym } if new_args[:roles] @status = new_args[:status] @note = new_args[:note] end
note()
click to toggle source
# File app/models/cmsso/member.rb, line 49 def self.note @@note end
type()
click to toggle source
# File app/models/cmsso/member.rb, line 45 def self.type @@type end
Private Class Methods
build_request(person,module_key=Cmsso.configuration.module_key)
click to toggle source
# File app/models/cmsso/member.rb, line 167 def self.build_request(person,module_key=Cmsso.configuration.module_key) now = Time.now data = {} data[:header] = { id: SecureRandom.uuid, action: "Compound Management.Core.Person", version: "1.0.0", date: (now.strftime("%Y-%m-%d") + 'T' + now.strftime("%H:%M:%S.000%:z"))} data[:request] = { persons: [{person_reference: person.reference, first_name: person.first_name, last_name: person.last_name, email: person.email, time_zone: person.time_zone, module_key: module_key}]} data.to_json end
get_person_from_header(headers)
click to toggle source
# File app/models/cmsso/member.rb, line 145 def self.get_person_from_header(headers) person = Member.new if headers["HTTP_NIBR521"].nil? || headers["HTTP_NIBR521"].size == 0 @@type, @@note = :header, "Person could not be authenticated. Is Authentication System (Vordel) running fine?" return nil else person.reference = headers["HTTP_NIBR521"].downcase person.first_name = headers["HTTP_NIBRFIRST"] if headers["HTTP_NIBRLAST"].nil? || headers["HTTP_NIBRLAST"].size == 0 || headers["HTTP_NIBRLAST"] =~ /^null$/ person.last_name = person.reference else person.last_name = headers["HTTP_NIBRLAST"] end person.email = headers["HTTP_NIBREMAIL"].downcase if headers["HTTP_NIBREMAIL"] && headers["HTTP_NIBREMAIL"] !~ /^null$/i end return person end
Public Instance Methods
full_name()
click to toggle source
# File app/models/cmsso/member.rb, line 41 def full_name [self.last_name,self.first_name].join(" ") end
method_missing(method)
click to toggle source
# File app/models/cmsso/member.rb, line 37 def method_missing(method) @roles.include?(method[0..-2].to_sym) end