lib/intercom-rails/import.rb in intercom-rails-0.2.24 vs lib/intercom-rails/import.rb in intercom-rails-0.2.25
- old
+ new
@@ -26,11 +26,11 @@
@max_batch_size = [(options[:max_batch_size] || 100), 100].min
@status_enabled = !!options[:status_enabled]
if uri.scheme == 'https'
- http.use_ssl = true
+ http.use_ssl = true
http.ca_file = File.join(File.dirname(__FILE__), '../data/cacert.pem')
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
end
end
@@ -68,11 +68,11 @@
progress '.' * (number_in_batch - failures.count)
progress 'F' * failures.count
end
info "Successfully created #{self.total_sent - self.failed.count} users", :new_line => true
info "Failed to create #{self.failed.count} #{(self.failed.count == 1) ? 'user' : 'users'}, this is likely due to bad data" unless failed.count.zero?
-
+
self
end
def total_failed
self.failed.count
@@ -117,27 +117,27 @@
IntercomRails.config.user.model.call
else
User
end
rescue NameError
- # Rails lazy loads constants, so this is how we check
+ # Rails lazy loads constants, so this is how we check
nil
end
def send_users(users)
- request = Net::HTTP::Post.new(uri.request_uri)
+ request = Net::HTTP::Post.new(uri.request_uri)
request.basic_auth(IntercomRails.config.app_id, IntercomRails.config.api_key)
request["Content-Type"] = "application/json"
- request.body = users
+ request.body = users
response = perform_request(request)
JSON.parse(response.body)
end
MAX_REQUEST_ATTEMPTS = 3
def perform_request(request, attempts = 0, error = {})
if (attempts > 0) && (attempts < MAX_REQUEST_ATTEMPTS)
- sleep(0.5)
+ sleep(0.5)
elsif error.present?
raise error[:exception] if error[:exception]
raise exception_for_failed_response(error[:failed_response])
end