Skip to content

pixe.la API methods

Naoki Saruta edited this page Oct 18, 2018 · 5 revisions

These methods are written in application_controller.rb. They can be called in any controllers.

methods related to graph API

get_graph method

This method returns the serialized svg file of the activity graph of a current user.
If the activity graph of the user hasn't been created, this method calls create_graph method to create a graph and returns the one created by the method.

usage example

In a controller,

@result = get_graph

and in a view,

<%= @result.html_safe %>

Used in

controllers/users/registrations_controller.rb and views/devise/registrations/edit.html.erb.

create_graph method

If the activity graph of the user hasn't been created, this method create a graph of the user.

methods related to pixel API

A pixel is the smallest unit of pixe.la's graphs. A pixel represents user's activity of a day.

save_commitment(date) method

This method calls update_pixel method or create_pixel method depending on the situation.

create_pixel(date) method

This method creates a new pixel of the given date.

update_pixel(date, quantity) method

This method increments the quantity of the pixel of the given date.

get_pixel(date) method

This method read the quantity of the pixel of the given date.