Skip to content

Instantly share code, notes, and snippets.

@mark-cooper
Created March 22, 2017 18:34
Show Gist options
  • Save mark-cooper/ae02ca0086427a246cbec85fe7708e37 to your computer and use it in GitHub Desktop.
Save mark-cooper/ae02ca0086427a246cbec85fe7708e37 to your computer and use it in GitHub Desktop.
Check Archon returns all classifications
require 'httparty'
require 'json'
require 'set'
def ok_status?(code)
code.to_s =~ /^2/
end
BASE_URL ="http://localhost/"
$batch_start = 1
$status_code = 200
$count = 0
$ids = Set.new
# got session stuff via chrome rest client
while ok_status? $status_code
response = HTTParty.get(BASE_URL, {
query: { p: "core/classifications", batch_start: $batch_start.to_s },
headers: {
'Authorization' => 'Basic c2E6Z01iWG9NbHVlczBlb1Y5aHZId214ckNVTXB1dEl2',
'Cookie' => 'archon=0iiqc7qhsdo9jo10t3e25imv73',
'session' => '0iiqc7qhsdo9jo10t3e25imv73',
}
})
$status_code = response.code.to_i
if ok_status? $status_code
begin
payload = JSON.parse(response.body)
if payload.is_a? Array
$count += payload.count
payload.each { |p| $ids << p["ID"] }
elsif payload.is_a? Hash
$count += payload.keys.count
payload.each { |id, p| $ids << p["ID"] }
else
raise "Unknown payload: #{payload.to_s}"
end
$batch_start += 100
rescue Exception => ex
puts ex.message
break
end
else
puts response.inspect
end
end
puts "Record count: #{$count.to_s}"
# 2929 = this is correct
puts "ID count: #{$ids.count.to_s}"
# 2929 = this is correct
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment