Module: ContactExtras::InstanceMethods
- Defined in:
- lib/app/lib/contact_extras.rb
Instance Method Summary collapse
- #connection ⇒ Object
- #create_in_tjb ⇒ Object
- #generate_password ⇒ Object
- #has_account? ⇒ Boolean
- #tjb_xml ⇒ Object
- #update_in_tjb ⇒ Object
Instance Method Details
#connection ⇒ Object
37 38 39 |
# File 'lib/app/lib/contact_extras.rb', line 37 def connection ActiveResource::Connection.new(JobboersenIntegration.jobboersen_uri) end |
#create_in_tjb ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/app/lib/contact_extras.rb', line 16 def create_in_tjb response = connection.post( "/administration/users.xml?auth_token=#{self.user.tjb_auth_token}", tjb_xml) attributes = Hash.from_xml(response.body)['user'] self.update_attributes :tjb_id => attributes['_id'], :do_not_update => true rescue nil end |
#generate_password ⇒ Object
48 49 50 |
# File 'lib/app/lib/contact_extras.rb', line 48 def generate_password Array.new(10/2) { rand(256) }.pack('C*').unpack('H*').first end |
#has_account? ⇒ Boolean
52 53 54 |
# File 'lib/app/lib/contact_extras.rb', line 52 def has_account? !account.blank? end |
#tjb_xml ⇒ Object
41 42 43 44 45 46 |
# File 'lib/app/lib/contact_extras.rb', line 41 def tjb_xml password = generate_password { :first_name => self.first_name, :last_name => self.last_name, :email => self.email, :password => password, :password_confirmation => password, :account_id => self.account.tjb_id }.to_xml(:root => 'contact') end |
#update_in_tjb ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/app/lib/contact_extras.rb', line 25 def update_in_tjb if self.tjb_id connection.put( "/administration/users/#{self.tjb_id}.xml?auth_token=#{self.user.tjb_auth_token}", tjb_xml) else create_in_tjb end rescue nil end |