Class: DmtdVbmappData::Client

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

Overview

Provides for the creating and retrieving of client instances in the VB-MAPP Data Server.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Client

Note:

The #code may be specified as a key of the corresponding record in your database. This allows the client to be referred to later on via this key as opposed to the id generated by our system. Using this option means that your application data is not required to store a new id for the client, but can use your existing id (primary key).

Note:

This operation blocks until it receives a response from the VB-MAPP Data Server.

Note:

If #is_valid_for_create? returns false, then the instance will not be sent to the server, it is assumed to already be there. Otherwise it will be sent to the server.

Note:

Language is not stored on the server along with the client information and thus, it must be specified each time the instance is created if a language other than the default is needed.

Creates a new client on the VB-MAPP Data Server

Parameters:

  • opts (Hash)

    a customizable set of options

Options Hash (opts):

  • :date_of_birth (Date)

    The date of birth of the client as a ruby Date object (may be nil)

  • :gender (Integer)

    The gender of the client, either GENDER_MALE or GENDER_FEMALE (may be nil if #is_valid_for_create?)

  • :id (String)

    The vbmapp_data server’s identifier for this client (may be nil)

  • :organization_id (String)

    The organization identifier (may be nil, if so DmtdVbmappData.config will be used)

  • :code (String)

    A code that can be used to refer to the client; possibly a key in the customer’s database (may be nil)

  • :first_name (String)

    The first name of the client (may be nil)

  • :last_name (String)

    The last name of the client (may be nil)

  • :settings (String)

    A string value that can be associated with the client (may be nil)

  • :language (String)

    The language to use (i.e. ‘en’, ‘es’ or may be nil) @see #DmtdVbmappData.AVAILABLE_LANGUAGES



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/dmtd_vbmapp_data/client.rb', line 82

def initialize(opts)
  dob = opts.fetch(:date_of_birth, nil)
  @date_of_birth = dob ? (dob.is_a?(String) ? DateTime.parse(dob) : dob.to_date) : nil
  @gender = opts.fetch(:gender, nil) ? opts.fetch(:gender).to_i : nil

  id = opts.fetch(:id, nil)
  @id = id.nil? ? nil : id.to_i
  @organization_id = opts.fetch(:organization_id, DmtdVbmappData.config[:organization_id]).to_i
  @code = opts.fetch(:code, nil)
  @first_name = opts.fetch(:first_name, nil)
  @last_name = opts.fetch(:last_name, nil)
  @settings = opts.fetch(:settings, nil)
  @server_response_code = opts.fetch(:server_response_code, 200)
  @language = opts.fetch(:language, nil)

  date_now = DateTime.now.new_offset(0)

  created_at = opts.fetch(:created_at, date_now)
  @created_at = created_at.is_a?(String) ? DateTime.parse(created_at) : created_at

  updated_at = opts.fetch(:updated_at, date_now)
  @updated_at = updated_at.is_a?(String) ? DateTime.parse(updated_at) : updated_at

  create_server_client if is_valid_for_create?
end

Instance Attribute Details

#clientClient (readonly)

Returns the associated client.

Returns:

  • (Client)

    the associated client



# File 'lib/dmtd_vbmapp_data/client.rb', line 11

#codeObject (readonly)

Returns the value of attribute code.



24
25
26
# File 'lib/dmtd_vbmapp_data/client.rb', line 24

def code
  @code
end

#created_atObject (readonly)

Returns the value of attribute created_at.



44
45
46
# File 'lib/dmtd_vbmapp_data/client.rb', line 44

def created_at
  @created_at
end

#date_of_birthObject (readonly)

Returns the value of attribute date_of_birth.



28
29
30
# File 'lib/dmtd_vbmapp_data/client.rb', line 28

def date_of_birth
  @date_of_birth
end

#first_nameObject (readonly)

Returns the value of attribute first_name.



32
33
34
# File 'lib/dmtd_vbmapp_data/client.rb', line 32

def first_name
  @first_name
end

#idObject (readonly)

Returns the value of attribute id.



16
17
18
# File 'lib/dmtd_vbmapp_data/client.rb', line 16

def id
  @id
end

#languageObject (readonly)

Returns the value of attribute language.



56
57
58
# File 'lib/dmtd_vbmapp_data/client.rb', line 56

def language
  @language
end

#last_nameObject (readonly)

Returns the value of attribute last_name.



36
37
38
# File 'lib/dmtd_vbmapp_data/client.rb', line 36

def last_name
  @last_name
end

#organization_idObject (readonly)

Returns the value of attribute organization_id.



20
21
22
# File 'lib/dmtd_vbmapp_data/client.rb', line 20

def organization_id
  @organization_id
end

#server_response_codeObject (readonly)

Returns the value of attribute server_response_code.



52
53
54
# File 'lib/dmtd_vbmapp_data/client.rb', line 52

def server_response_code
  @server_response_code
end

#settingsObject (readonly)

Returns the value of attribute settings.



40
41
42
# File 'lib/dmtd_vbmapp_data/client.rb', line 40

def settings
  @settings
end

#updated_atObject (readonly)

Returns the value of attribute updated_at.



48
49
50
# File 'lib/dmtd_vbmapp_data/client.rb', line 48

def updated_at
  @updated_at
end

Class Method Details

.retrieve_clients(opts = {}) ⇒ Array<Client> | Integer

Note:

This operation blocks until it receives a response from the VB-MAPP Data Server.

Retrieves all existing clients from the VB-MAPP Data Server

Parameters:

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • :organization_id (String)

    The organization identifier (may be nil, if so DmtdVbmappData.config will be used)

  • :language (String)

    The language to use (i.e. ‘en’, ‘es’ or may be nil) @see #DmtdVbmappData.AVAILABLE_LANGUAGES

Returns:

  • (Array<Client> | Integer)

    http response code (integer) if an error was received



116
117
118
# File 'lib/dmtd_vbmapp_data/client.rb', line 116

def self.retrieve_clients(opts = {})
  retrieve_server_clients(opts)
end

Instance Method Details

#guideGuide

Note:

This method does not block

Returns:



123
124
125
# File 'lib/dmtd_vbmapp_data/client.rb', line 123

def guide
  Guide.new(client: self, language: language)
end

#iep_report(&resolver) ⇒ AssessmentReport

Note:

This method does not block

Returns:



137
138
139
# File 'lib/dmtd_vbmapp_data/client.rb', line 137

def iep_report(&resolver)
  AssessmentReport.new(client: self, language: language, &resolver).iep
end

#is_valid_for_create?true | false

Returns true if the receiver is parametrized correctly for creation on the server.

Returns:

  • (true | false)

    true if the receiver is parametrized correctly for creation on the server



142
143
144
# File 'lib/dmtd_vbmapp_data/client.rb', line 142

def is_valid_for_create?
  @id.nil? && !@date_of_birth.nil? && !@gender.nil? && !@organization_id.nil?
end

#vbmappProtocol

Note:

This method does not block

Returns:



130
131
132
# File 'lib/dmtd_vbmapp_data/client.rb', line 130

def vbmapp
  Protocol.new(client: self, language: language)
end