Module: UserExtras::InstanceMethods

Defined in:
lib/app/lib/user_extras.rb

Instance Method Summary collapse

Instance Method Details

#connectionObject



41
42
43
# File 'lib/app/lib/user_extras.rb', line 41

def connection
  ActiveResource::Connection.new(JobboersenIntegration.jobboersen_uri)
end

#create_in_tjbObject



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/app/lib/user_extras.rb', line 17

def create_in_tjb
  response = connection.post('/administration/administrators.xml',
    self.to_xml(:only => :email))
  if response.code == '200'
    attributes = Hash.from_xml(response.body)['administrator']
    self.update_attributes :tjb_id => attributes['_id'],
      :tjb_auth_token => attributes['authentication_token'], :do_not_update => true
  end
rescue
  nil
end

#update_in_tjbObject



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/app/lib/user_extras.rb', line 29

def update_in_tjb
  if self.tjb_id
    connection.put(
      "/administration/administrators/#{self.tjb_id}.xml?auth_token=#{self.tjb_auth_token}",
      self.to_xml(:only => :email))
  else
    create_in_tjb
  end
rescue
  nil
end