Module: AccountExtras::InstanceMethods

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

Instance Method Summary collapse

Instance Method Details

#connectionObject



36
37
38
# File 'lib/app/lib/account_extras.rb', line 36

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

#create_in_tjbObject



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

Returns:

  • (Boolean)


40
41
42
# File 'lib/app/lib/account_extras.rb', line 40

def prospect_or_customer?
  %w(Prospect Customer).include?(self.)
end

#tjb_xmlObject



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.
  }.to_xml(:root => 'account')
end

#update_in_tjbObject



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