Sigimera API - Test Client Fork me on GitHub

Sigimera API - Test Client

This application is an example client that demonstrates the use of the Sigimera REST API. Please feel free to fork this Sinatra App on GitHub and adapt it to your needs.

Getting Started

1. Step
Exploit this website: Last Crises
2. Step
Clone (and/or fork) the source code on GitHub.
3. Step
Develop your own app on the base of the Sigimera REST API.

Source Code Outline

The following code snippets describe the important parts of this example code. The other things are only needed to keep this website running and to improve the style.

Crises Controller

get '/red_alerts' do
    @crises = JSON(get_crises)
    erb :crises_list
end

Crises API Call

private
def get_crises(page = 1, type = nil, alert_level = nil)
    url = "http://api.sigimera.org/v1/crises?auth_token=#{settings.auth_token}&page=#{page}&output=short"
    unless type.nil?
        url += "&type=#{type}"
    end

    unless type.nil?
        url += "&type=#{type}"
    end

    unless alert_level.nil?
        url += "&level=#{alert_level}"
    end

    crises_endpoint = open(url)
    crises = crises_endpoint.read
    crises_endpoint.close
    crises
end

Visualization with erb

<h1>Last <%= @crises.size %> crises</h1>

<table class="table table-striped">
    <thead>
        <tr>
            <th>Title</th>
            <th>Subject</th>
            <th width="195px">Countries</th>
        </tr>
    </thead>
    <tbody>
        <% @crises.each do |crisis| %>
            <tr>
                <td>
                    <a href="http://www.sigimera.org/crises/<%=crisis['_id']%>" target="_blank" alt="Single Crisis">
                        <%= crisis['dc_title'] %>
                    </a>
                </td>
                <td><%= crisis['dc_subject'] %></td>
                <td><%= crisis['gn_parentCountry'] %></td>
            </tr>
        <% end %>
    </tbody>
</table>