app/models/maestrano/connector/rails/concerns/entity.rb in maestrano-connector-rails-0.0.1 vs app/models/maestrano/connector/rails/concerns/entity.rb in maestrano-connector-rails-0.2.0
- old
+ new
@@ -33,18 +33,21 @@
entities = []
# Fetch first page
if last_synchronization.blank? || opts[:full_sync]
+ Maestrano::Connector::Rails::ConnectorLogger.log('debug', organization, "entity=#{self.connec_entity_name}, fetching all data")
response = client.get("/#{self.connec_entity_name.downcase.pluralize}")
else
+ Maestrano::Connector::Rails::ConnectorLogger.log('debug', organization, "entity=#{self.connec_entity_name}, fetching data since #{last_synchronization.updated_at.iso8601}")
query_param = URI.encode("$filter=updated_at gt '#{last_synchronization.updated_at.iso8601}'")
response = client.get("/#{self.connec_entity_name.downcase.pluralize}?#{query_param}")
end
raise "No data received from Connec! when trying to fetch #{self.connec_entity_name.pluralize}" unless response
response_hash = JSON.parse(response.body)
+ Maestrano::Connector::Rails::ConnectorLogger.log('debug', organization, "received first page entity=#{self.connec_entity_name}, response=#{response.body}")
if response_hash["#{self.connec_entity_name.downcase.pluralize}"]
entities << response_hash["#{self.connec_entity_name.downcase.pluralize}"]
else
raise "Received unrecognized Connec! data when trying to fetch #{self.connec_entity_name.pluralize}"
end
@@ -54,9 +57,11 @@
# ugly way to convert https://api-connec/api/v2/group_id/organizations?next_page_params to /organizations?next_page_params
next_page = response_hash['pagination']['next'].gsub(/^(.*)\/#{self.connec_entity_name.downcase.pluralize}/, self.connec_entity_name.downcase.pluralize)
response = client.get(next_page)
raise "No data received from Connec! when trying to fetch subsequent page of #{self.connec_entity_name.pluralize}" unless response
+ Maestrano::Connector::Rails::ConnectorLogger.log('debug', organization, "received next page entity=#{self.connec_entity_name}, response=#{response.body}")
+
response_hash = JSON.parse(response.body)
if response_hash["#{self.connec_entity_name.downcase.pluralize}"]
entities << response_hash["#{self.connec_entity_name.downcase.pluralize}"]
else
raise "Received unrecognized Connec! data when trying to fetch subsequent page of #{self.connec_entity_name.pluralize}"
\ No newline at end of file