Class: DmtdVbmappData::Client
- Inherits:
-
Object
- Object
- DmtdVbmappData::Client
- 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
-
#client ⇒ Client
readonly
The associated client.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#date_of_birth ⇒ Object
readonly
Returns the value of attribute date_of_birth.
-
#first_name ⇒ Object
readonly
Returns the value of attribute first_name.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#language ⇒ Object
readonly
Returns the value of attribute language.
-
#last_name ⇒ Object
readonly
Returns the value of attribute last_name.
-
#organization_id ⇒ Object
readonly
Returns the value of attribute organization_id.
-
#server_response_code ⇒ Object
readonly
Returns the value of attribute server_response_code.
-
#settings ⇒ Object
readonly
Returns the value of attribute settings.
-
#updated_at ⇒ Object
readonly
Returns the value of attribute updated_at.
Class Method Summary collapse
-
.retrieve_clients(opts = {}) ⇒ Array<Client> | Integer
Retrieves all existing clients from the VB-MAPP Data Server.
Instance Method Summary collapse
- #guide ⇒ Guide
- #iep_report(&resolver) ⇒ AssessmentReport
-
#initialize(opts) ⇒ Client
constructor
Creates a new client on the VB-MAPP Data Server.
-
#is_valid_for_create? ⇒ true | false
True if the receiver is parametrized correctly for creation on the server.
- #vbmapp ⇒ Protocol
Constructor Details
#initialize(opts) ⇒ Client
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).
This operation blocks until it receives a response from the VB-MAPP Data Server.
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.
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
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
#client ⇒ Client (readonly)
Returns the associated client.
|
# File 'lib/dmtd_vbmapp_data/client.rb', line 11
|
#code ⇒ Object (readonly)
Returns the value of attribute code.
24 25 26 |
# File 'lib/dmtd_vbmapp_data/client.rb', line 24 def code @code end |
#created_at ⇒ Object (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_birth ⇒ Object (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_name ⇒ Object (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 |
#id ⇒ Object (readonly)
Returns the value of attribute id.
16 17 18 |
# File 'lib/dmtd_vbmapp_data/client.rb', line 16 def id @id end |
#language ⇒ Object (readonly)
Returns the value of attribute language.
56 57 58 |
# File 'lib/dmtd_vbmapp_data/client.rb', line 56 def language @language end |
#last_name ⇒ Object (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_id ⇒ Object (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_code ⇒ Object (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 |
#settings ⇒ Object (readonly)
Returns the value of attribute settings.
40 41 42 |
# File 'lib/dmtd_vbmapp_data/client.rb', line 40 def settings @settings end |
#updated_at ⇒ Object (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
This operation blocks until it receives a response from the VB-MAPP Data Server.
Retrieves all existing clients from the VB-MAPP Data Server
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
#guide ⇒ Guide
This method does not block
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
This method does not block
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.
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 |