Skip to content

Instantly share code, notes, and snippets.

View jerzyn's full-sized avatar

Andrzej jerzyn

View GitHub Profile
<?xml version="1.0" encoding="UTF-8"?>
<event>
<type>application</type>
<action>updated</action>
<object>
THE APPLICATION OBJECT AS WOULD BE RETURNED BY A GET ON THE ACCOUNT MANAGEMENT
API
</object>
</event>
@jerzyn
jerzyn / api-configuration-account-plans-controll.liquid
Last active August 29, 2015 13:57
Controll Content Based on Account Plans
{% for feature in current_user.account.bought_account_plan.system_name %}
...
{% endfor %}
@jerzyn
jerzyn / example_list_of_applications.rb
Created March 21, 2014 11:12
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
@jerzyn
jerzyn / example_filter_applications.rb
Created March 21, 2014 11:14
Example Filter Applications
def filter_applications(domain, provider_key, plan_name, num_of_days)
res = api_call_applications_list(domain, provider_key)
res.each do |item|
res.delete(item) if item["plan_name"] != plan_name
res.delete(item) if item["created_at"] > (DateTime.now - num_of_days)
end
return res
end
@jerzyn
jerzyn / example_fetch_stats.rb
Created March 21, 2014 11:15
Example Fetch Stats
def api_call_application_usage(domain, provider_key, application_id, metric, from, to, granularity)
url = "https://#{domain}/stats/applications/#{application_id}/usage.xml?provider_key=#{provider_key}&metric_name=#{metric}&since=#{from}&until=#{to}&granularity=#{granularity}"
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)
return document.xpath("//usage/data/values").text.split(",")
@jerzyn
jerzyn / example_account_info.rb
Created March 21, 2014 11:16
Example Account Info
def api_call_account_read(domain, provider_key, account_id)
url = "https://#{domain}/admin/api/accounts/#{account_id}.xml?provider_key=#{provider_key}"
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)
account = Hash.new
account["email"] = document.xpath("//users/user/email").text
@jerzyn
jerzyn / diff-curl-authrep
Created March 21, 2014 15:07
Authrep call
curl -v -X GET "http://su1.3scale.net/transactions/authrep.xml?provider_key=PROVIDER_KEY&app_id=APP_ID&app_key=APP_KEY&usage[words-write]=1"
@jerzyn
jerzyn / diff-response.xml
Created March 21, 2014 15:08
Authrep call XML response
<status>
<authorized>false</authorized>
...
@jerzyn
jerzyn / diff-call-authrep-usage
Created March 21, 2014 15:09
Authrep call reporting usage
curl -v -X GET "http://su1.3scale.net/transactions/authrep.xml?provider_key=PROVIDER_KEY&app_id=APP_ID&app_key=APP_KEY&usage[words]=1"
@jerzyn
jerzyn / diff-authrep-plan-response.xml
Created March 21, 2014 15:10
Authrep call reporting usage XML response
<authorized>true</authorized>
<plan>Sandbox</plan>
...