app/models/maestrano/connector/rails/concerns/entity.rb in maestrano-connector-rails-0.2.17 vs app/models/maestrano/connector/rails/concerns/entity.rb in maestrano-connector-rails-0.2.18

- old
+ new

@@ -66,10 +66,14 @@ end # ---------------------------------------------- # Connec! methods # ---------------------------------------------- def normalized_connec_entity_name + normalize_connec_entity_name(connec_entity_name) + end + + def normalize_connec_entity_name(connec_entity_name) if singleton? connec_entity_name.downcase else connec_entity_name.downcase.pluralize end @@ -131,14 +135,14 @@ external_entity = mapped_external_entity_with_idmap[:entity] idmap = mapped_external_entity_with_idmap[:idmap] begin if idmap.connec_id.blank? - connec_entity = create_connec_entity(connec_client, external_entity, connec_entity_name, organization) + connec_entity = create_connec_entity(connec_client, external_entity, normalize_connec_entity_name(connec_entity_name), organization) idmap.update_attributes(connec_id: connec_entity['id'], connec_entity: connec_entity_name.downcase, last_push_to_connec: Time.now, message: nil) else - connec_entity = update_connec_entity(connec_client, external_entity, idmap.connec_id, connec_entity_name, organization) + connec_entity = update_connec_entity(connec_client, external_entity, idmap.connec_id, normalize_connec_entity_name(connec_entity_name), organization) idmap.update_attributes(last_push_to_connec: Time.now, message: nil) end rescue => e # Store Connec! error if any idmap.update_attributes(message: e.message) @@ -146,21 +150,21 @@ end end def create_connec_entity(connec_client, mapped_external_entity, connec_entity_name, organization) Maestrano::Connector::Rails::ConnectorLogger.log('info', organization, "Sending create #{connec_entity_name}: #{mapped_external_entity} to Connec!") - response = connec_client.post("/#{normalized_connec_entity_name}", { "#{normalized_connec_entity_name}".to_sym => mapped_external_entity }) + response = connec_client.post("/#{connec_entity_name}", { "#{connec_entity_name}".to_sym => mapped_external_entity }) response = JSON.parse(response.body) raise "Connec!: #{response['errors']['title']}" if response['errors'] && response['errors']['title'] - response["#{normalized_connec_entity_name}"] + response["#{connec_entity_name}"] end def update_connec_entity(connec_client, mapped_external_entity, connec_id, connec_entity_name, organization) Maestrano::Connector::Rails::ConnectorLogger.log('info', organization, "Sending update #{connec_entity_name}: #{mapped_external_entity} to Connec!") - response = connec_client.put("/#{normalized_connec_entity_name}/#{connec_id}", { "#{normalized_connec_entity_name}".to_sym => mapped_external_entity }) + response = connec_client.put("/#{connec_entity_name}/#{connec_id}", { "#{connec_entity_name}".to_sym => mapped_external_entity }) response = JSON.parse(response.body) raise "Connec!: #{response['errors']['title']}" if response['errors'] && response['errors']['title'] - response["#{normalized_connec_entity_name}"] + response["#{connec_entity_name}"] end def map_to_external_with_idmap(entity, organization) idmap = find_idmap({connec_id: entity['id'], organization_id: organization.id}) \ No newline at end of file