Module: AccountExtras::InstanceMethods
- Defined in:
- lib/app/lib/account_extras.rb
Instance Method Summary collapse
- #connection ⇒ Object
- #create_in_tjb ⇒ Object
- #prospect_or_customer? ⇒ Boolean
- #tjb_xml ⇒ Object
- #update_in_tjb ⇒ Object
Instance Method Details
#connection ⇒ Object
36 37 38 |
# File 'lib/app/lib/account_extras.rb', line 36 def connection ActiveResource::Connection.new(JobboersenIntegration.jobboersen_uri) end |
#create_in_tjb ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/app/lib/account_extras.rb', line 15 def create_in_tjb response = connection.post( "/administration/accounts.xml?auth_token=#{self.user.tjb_auth_token}", tjb_xml) attributes = Hash.from_xml(response.body)['account'] self.update_attributes :tjb_id => attributes['_id'], :do_not_update => true rescue nil end |
#prospect_or_customer? ⇒ Boolean
40 41 42 |
# File 'lib/app/lib/account_extras.rb', line 40 def prospect_or_customer? %w(Prospect Customer).include?(self.account_type) end |
#tjb_xml ⇒ Object
44 45 46 47 48 49 |
# File 'lib/app/lib/account_extras.rb', line 44 def tjb_xml { :name => self.name, :street => self.billing_street, :locality => self.billing_locality, :region => self.billing_region, :postal_code => self.billing_postal_code, :country => self.billing_country, :account_type => self.account_type }.to_xml(:root => 'account') end |
#update_in_tjb ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/app/lib/account_extras.rb', line 24 def update_in_tjb if self.tjb_id connection.put( "/administration/accounts/#{self.tjb_id}.xml?auth_token=#{self.user.tjb_auth_token}", tjb_xml) else create_in_tjb end rescue nil end |