Created
March 21, 2014 11:12
-
-
Save jerzyn/9684001 to your computer and use it in GitHub Desktop.
Example of List Applications
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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