Skip to content

Instantly share code, notes, and snippets.

@jerzyn
Created March 21, 2014 11:12
Show Gist options
  • Save jerzyn/9684001 to your computer and use it in GitHub Desktop.
Save jerzyn/9684001 to your computer and use it in GitHub Desktop.
Example of List Applications
def api_call_applications_list(domain, provider_key)
done = false
res = Array.new
page = 1
while !done
url = "https://#{domain}/admin/api/applications.xml?provider_key=#{provider_key}&page=#{page}&per_page=100"
page += 1
response = RestClient.get url
raise Exception.new("Wrong response code (#{response.code}) in request #{url}") if response.code!=200
document = Nokogiri::XML(response.to_str)
done = document.xpath("applications/@current_page").text == document.xpath("applications/@total_pages").text
document.xpath("//application").each do |item|
app = Hash.new
app["created_at"] = DateTime.parse(item.xpath("created_at").text)
app["plan_name"] = item.xpath("plan/name").text
app["service_id"] = item.xpath("plan/service_id").text
app["account_id"] = item.xpath("user_account_id").text
app["id"] = item.xpath("id").text
res << app
end
end
return res
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment