Class: CrisalidOdooClient::Client

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

Constant Summary collapse

DEFAULT_TIMEOUT =
60

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(odoo_url:, odoo_db:, odoo_user:, odoo_pass:, odoo_uid: nil, timeout: DEFAULT_TIMEOUT) ⇒ Client

Returns a new instance of Client.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/crisalid_odoo_client/client.rb', line 14

def initialize(odoo_url:, odoo_db:, odoo_user:, odoo_pass:, odoo_uid: nil, timeout: DEFAULT_TIMEOUT)
  @odoo_url, @odoo_db, @timeout = odoo_url, odoo_db, timeout

  if @uid.nil?
    @odoo_user, @odoo_pass = odoo_user, odoo_pass
    @uid = connect
  end

  if @uid != false
    @models = XMLRPC::Client.new2("#{@odoo_url}/xmlrpc/2/object", nil, @timeout).proxy
    @query ||= CrisalidOdooClient::Query.new(self)
    # Client connected
  else
    # Client not connected
  end
end

Instance Attribute Details

#odoo_dbObject (readonly)

Returns the value of attribute odoo_db.



8
9
10
# File 'lib/crisalid_odoo_client/client.rb', line 8

def odoo_db
  @odoo_db
end

#odoo_passObject (readonly)

Returns the value of attribute odoo_pass.



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

def odoo_pass
  @odoo_pass
end

#odoo_urlObject (readonly)

Returns the value of attribute odoo_url.



7
8
9
# File 'lib/crisalid_odoo_client/client.rb', line 7

def odoo_url
  @odoo_url
end

#odoo_userObject (readonly)

Returns the value of attribute odoo_user.



9
10
11
# File 'lib/crisalid_odoo_client/client.rb', line 9

def odoo_user
  @odoo_user
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



12
13
14
# File 'lib/crisalid_odoo_client/client.rb', line 12

def timeout
  @timeout
end

Instance Method Details

#connected?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/crisalid_odoo_client/client.rb', line 51

def connected?
  return (uid || false) != false
end

#employeeObject



47
48
49
# File 'lib/crisalid_odoo_client/client.rb', line 47

def employee
  @employee ||= CrisalidOdooClient::Resource::Employee.new(self)
end

#modelsObject



35
36
37
# File 'lib/crisalid_odoo_client/client.rb', line 35

def models
  @models
end

#productObject



43
44
45
# File 'lib/crisalid_odoo_client/client.rb', line 43

def product
  @product ||= CrisalidOdooClient::Resource::Product.new(self)
end

#queryObject



39
40
41
# File 'lib/crisalid_odoo_client/client.rb', line 39

def query
  @query
end

#uidObject



31
32
33
# File 'lib/crisalid_odoo_client/client.rb', line 31

def uid
  @uid
end