Class: MethodCrm::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/method_crm.rb

Instance Method Summary collapse

Constructor Details

#initialize(company, username, password) ⇒ Client

Returns a new instance of Client.



10
11
12
# File 'lib/method_crm.rb', line 10

def initialize(company, username, password)
  @auth = {strCompanyAccount: company, strLogin: username, strPassword:  password, strSessionID: nil}
end

Instance Method Details

#field_list(table, options = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/method_crm.rb', line 24

def field_list(table, options={}) 
  results = perform_opperation('FieldList', {'strTable' => table})
  case options[:output].to_s
  when 'detailed'
    results
  else
    results.map { |table| table[:field_name] }
  end
end

#get_record(table, options = {}) ⇒ Object



40
41
42
43
44
# File 'lib/method_crm.rb', line 40

def get_record(table, options={})
  records = get_records(table, options)
  raise MethodCrmClientError, 'Query returned more than one record' if records.length > 1
  records.first
end

#get_records(table, options = {}) ⇒ Object



34
35
36
37
38
# File 'lib/method_crm.rb', line 34

def get_records(table, options={})
  options[:fields] ||= field_list(table).join(',')
  data = @auth.merge({strTable: table, strFields: options[:fields], strWhereClause: options[:where], strGroupByClause: nil, strHaving: nil, strOrderBy: nil})
  perform_opperation('Select_XML', data)
end

#table_list(options = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/method_crm.rb', line 14

def table_list(options={})
  results = perform_opperation('TableList')
  case options[:output].to_s
  when 'detailed'
    results
  else
    results.map { |table| table[:table_name] }
  end
end