class Dynamicloud::API::DynamicProvider
This class has two attributes CSK and ACI keys. This information is provided at moment the registration in Dynamicloud
. @author Eleazar Gomez @version 1.0.0 @since 8/25/15
Public Class Methods
# File lib/dynamic_api.rb, line 301 def initialize(credential) @credential = credential end
Public Instance Methods
Will create a RecordQuery
and sets to this provider @param mid model id to use to execute operations @return this Dynamicloud::API::RecordQuery
instance
# File lib/dynamic_api.rb, line 413 def create_query(mid) query = Dynamicloud::API::RecordQuery.new mid query.set_credentials @credential query end
Executes a delete using query as a selection @param query selection @param mid model id
# File lib/dynamic_api.rb, line 543 def delete(query, mid) selection = Dynamicloud::API::DynamicloudHelper.build_string(query.get_conditions, nil, nil, nil) url = Configuration::PROPERTIES.get_property :url url_get_records = Configuration::PROPERTIES.get_property :url_delete_selection url_get_records = url_get_records.gsub '{csk}', URI::encode(@credential[:csk]) url_get_records = url_get_records.gsub '{aci}', URI::encode(@credential[:aci]) url_get_records = url_get_records.gsub '{mid}', mid.to_s params = { :selection => selection } response = DynamicService::ServiceCaller.call_service url + url_get_records, params, 'post' json = JSON.parse(response) unless json['status'] == 200 raise json['message'] end end
This method will call a delete operation in DynamiCloud servers using model id and Record id @param mid model id @param rid record id
# File lib/dynamic_api.rb, line 393 def delete_record(mid, rid) url = Configuration::PROPERTIES.get_property :url url_get_records = Configuration::PROPERTIES.get_property :url_delete_record url_get_records = url_get_records.gsub '{csk}', URI::encode(@credential[:csk]) url_get_records = url_get_records.gsub '{aci}', URI::encode(@credential[:aci]) url_get_records = url_get_records.gsub '{mid}', mid.to_s url_get_records = url_get_records.gsub '{rid}', rid.to_s response = DynamicService::ServiceCaller.call_service url + url_get_records, {}, 'delete' json = JSON.parse(response) unless json['status'] == 200 raise json['message'] end end
Loads all model's fields according ModelID @param mid model id @return list of model's fields.
# File lib/dynamic_api.rb, line 477 def load_fields(mid) url = Configuration::PROPERTIES.get_property :url url_get_records = Configuration::PROPERTIES.get_property :url_get_fields url_get_records = url_get_records.gsub '{csk}', URI::encode(@credential[:csk]) url_get_records = url_get_records.gsub '{aci}', URI::encode(@credential[:aci]) url_get_records = url_get_records.gsub '{mid}', mid.to_s response = DynamicService::ServiceCaller.call_service url + url_get_records, {}, 'get' json = JSON.parse(response) unless json['status'] == 200 raise json['message'] end fields = [] fs = json['fields'] fs.each do |key, jf| field = Dynamicloud::API::Model::RecordField.new field.id = jf['id'].to_i field.identifier = jf['identifier'] field.label = jf['label'] field.comment = jf['comment'] field.uniqueness = jf['uniqueness'] field.required = jf['required'] field.type = Dynamicloud::API::Model::RecordFieldType.get_field_type jf['field_type'].to_i field.items = Dynamicloud::API::DynamicloudHelper.build_items jf['items'] field.mid = mid.to_i fields.push field end fields end
Gets model record information from DynamiCloud servers. @param mid model id in DynamiClod servers @return RecordModel object
# File lib/dynamic_api.rb, line 423 def load_model(mid) url = Configuration::PROPERTIES.get_property :url url_get_records = Configuration::PROPERTIES.get_property :url_get_model_info url_get_records = url_get_records.gsub '{csk}', URI::encode(@credential[:csk]) url_get_records = url_get_records.gsub '{aci}', URI::encode(@credential[:aci]) url_get_records = url_get_records.gsub '{mid}', mid.to_s response = DynamicService::ServiceCaller.call_service url + url_get_records, {}, 'get' json = JSON.parse(response) unless json['status'] == 200 raise json['message'] end model = Dynamicloud::API::Model::RecordModel.new mid model.name = json['name'] model.description = json['description'] model end
Loads all models related to CSK and ACI keys in Dynamicloud
servers @return list of models
# File lib/dynamic_api.rb, line 447 def load_models url = Configuration::PROPERTIES.get_property :url url_get_records = Configuration::PROPERTIES.get_property :url_get_models url_get_records = url_get_records.gsub '{csk}', URI::encode(@credential[:csk]) url_get_records = url_get_records.gsub '{aci}', URI::encode(@credential[:aci]) response = DynamicService::ServiceCaller.call_service url + url_get_records, {}, 'get' json = JSON.parse(response) unless json['status'] == 200 raise json['message'] end models = [] array = json['models'] array.each do |item| model = Dynamicloud::API::Model::RecordModel.new item['id'].to_i model.name = item['name'] model.description = item['description'] models.push model end models end
This method will load a record using rid and will instantiate a hash with attributes bound to Model's fields. @param rid record id @param mid model id @return a hash with record information
# File lib/dynamic_api.rb, line 309 def load_record(rid, mid) url = Configuration::PROPERTIES.get_property :url url_get_records = Configuration::PROPERTIES.get_property :url_get_record_info url_get_records = url_get_records.gsub '{csk}', URI::encode(@credential[:csk]) url_get_records = url_get_records.gsub '{aci}', URI::encode(@credential[:aci]) url_get_records = url_get_records.gsub '{mid}', mid.to_s url_get_records = url_get_records.gsub '{rid}', rid.to_s response = DynamicService::ServiceCaller.call_service url + url_get_records, {}, 'get' json = JSON.parse(response) record = json['record'] unless record raise 'Record key doesn\'t present in response from Dynamicloud server.' end Dynamicloud::API::DynamicloudHelper.normalize_record record end
This method will call a save operation in DynamiCloud servers using model and BoundInstance object @param mid model id @param data all data needed to save a record in model (mid)
# File lib/dynamic_api.rb, line 365 def save_record(mid, data) url = Configuration::PROPERTIES.get_property :url url_get_records = Configuration::PROPERTIES.get_property :url_save_record url_get_records = url_get_records.gsub '{csk}', URI::encode(@credential[:csk]) url_get_records = url_get_records.gsub '{aci}', URI::encode(@credential[:aci]) url_get_records = url_get_records.gsub '{mid}', mid.to_s params = { :fields => Dynamicloud::API::DynamicloudHelper.build_fields_json(data) } response = DynamicService::ServiceCaller.call_service url + url_get_records, params, 'post' json = JSON.parse(response) unless json['status'] == 200 raise json['message'] end data['rid'] = json['rid'] data end
Executes an update using query as a selection and data with values Dynamicloud
will normalize the key pair values. That is, will be used field identifiers only. @param data data that will be sent to Dynamicloud
servers @param query selection
# File lib/dynamic_api.rb, line 516 def update(query, data = {}) selection = Dynamicloud::API::DynamicloudHelper.build_string(query.get_conditions, nil, nil, nil) fields = '{"updates": ' + Dynamicloud::API::DynamicloudHelper.build_fields_json(data) + '}' url = Configuration::PROPERTIES.get_property :url url_get_records = Configuration::PROPERTIES.get_property :url_update_selection url_get_records = url_get_records.gsub '{csk}', URI::encode(@credential[:csk]) url_get_records = url_get_records.gsub '{aci}', URI::encode(@credential[:aci]) url_get_records = url_get_records.gsub '{mid}', query.get_model_id.to_s params = { :fields => fields, :selection => selection } response = DynamicService::ServiceCaller.call_service url + url_get_records, params, 'post' json = JSON.parse(response) unless json['status'] == 200 raise json['message'] end end
This method will call an update operation in Dynamicloud
servers using model and data object @param mid model id @param data this hash should contain a key rid (RecordId) otherwise an error will be thrown
# File lib/dynamic_api.rb, line 334 def update_record(mid, data) rid = data['rid'] unless rid raise "rid attribute isn't present in hash data." end url = Configuration::PROPERTIES.get_property :url url_get_records = Configuration::PROPERTIES.get_property :url_update_record url_get_records = url_get_records.gsub '{csk}', URI::encode(@credential[:csk]) url_get_records = url_get_records.gsub '{aci}', URI::encode(@credential[:aci]) url_get_records = url_get_records.gsub '{mid}', mid.to_s url_get_records = url_get_records.gsub '{rid}', rid.to_s params = { :fields => Dynamicloud::API::DynamicloudHelper.build_fields_json(data) } response = DynamicService::ServiceCaller.call_service url + url_get_records, params, 'post' json = JSON.parse(response) unless json['status'] == 200 raise json['message'] end end