Author Archives: jalcerro

About jalcerro

ICT Consultant and Co-Founder FindAttach

Runkeeper API access with HTTParty

So you want to access the Runkeeper’s API with HTTParty Gem. Well, this article is for you.

This is how I did it. Hope it helps you.

1. Register you web application and get your Client ID and Secret form Runkeeper’s Partner Portal Web Site

https://runkeeper.com/partner

2. Generate your access token

To generate your access token, you have to run the following command in terminal window:
a. gem install launchy rack
b. Run bundle install
b. CLIENT_ID=“your Client ID” CLIENT_SECRET=“your Client Secret”
AUTHORIZATION_URL=“https://runkeeper.com/apps/authorize
ACCESS_TOKEN_URL=“https://runkeeper.com/apps/token” token_generator

—- note: this is a one line command —-

c. The command will open a browser window with Runkeeper’s website login
d. Return to your terminal windows and your token will be displayed if your login was successful

Check this website where I found the procedure: http://www.vinnycoyne.com/post/56247548995/send-jawbone-up-sleep-data-to-runkeeper

3. Add following line to add HTTParty gem in your Gemfile

gem ‘httparty’

From a terminal windows run the command: bundle install
This will install latest version of HTTParty Gem

4. I recommend you to check the following site for further information on HTTParty and Runkeeper’s API example calls

a. http://www.rubydoc.info/github/jnunemaker/httparty/HTTParty/ClassMethods
b. https://runkeeper.com/developer/healthgraph/example-api-calls#top

5. Modify your routes. Add a activity resource for this example. You can modify to suite your needs.

resources :activities

6. Create your controller with the following code:

class ActivitiesController < ApplicationController

def index
@user = Activity.grab_user
@activities = Activity.grab_activities
end

end

7. Create a environment variable with your token code

Add the following to your .bash_profile

export RUN_KEEPER_TOKEN=”xxxxxxxxxxxxxxxxxxxxxxxx”

replace “xxxxxxxxxxxxxxxxxxxxxxxx” with your token code

8. Create your model with the following code:

class Activity
include HTTParty

hostport = “api.runkeeper.com
base_uri “http://#{hostport}”
format :json

def self.grab_user
headers ‘Authorization’ => ‘Bearer ENV[“RUN_KEEPER_TOKEN”]’, ‘Accept’ =>     “application/vnd.com.runkeeper.User+json”
get(“/user”)
end

def self.grab_activities
headers ‘Authorization’ => ‘Bearer ENV[“RUN_KEEPER_TOKEN”]’, ‘Accept’ =>      “application/vnd.com.runkeeper.FitnessActivityFeed+json”
get(“/fitnessActivities”)[“items”]

end
end

9. Create your view file as follows (index.html.erb):

<table>
<thead>
<tr>
<th>Type</th>
<th>Start Time</th>
<th>Total Distance</th>
<th>Duration</th>
</tr>
</thead>
<tbody>
<% @activities.each do |activity| %>
<tr>
<td><%= activity[“type”] %></td>
<td><%= activity[“start_time”].to_s %></td>
<td><%= activity[“total_distance”].to_i / 1000 %> Kms</td>
<td><%= activity[“duration”] %></td>
</tr>
<% end %>
</tbody>
</table>

Enjoy!!

Keep in mind that for the HTTParty to work properly you have to change the headers depending on the resource you are accessing.

Please leave your comments.

Uber discloses data breach that may have affected 50,000 drivers

Gigaom

Uber suffered a data breach in 2014 that affected 50,000 Uber drivers across the U.S., the ride-sharing startup disclosed in a statement on Friday.

The company determined on September 17, 2014 that a third party could have accessed one of its databases. After Uber “changed the access protocols for the database” and looked into the situation, it learned through an investigation that someone apparently accessed one of its databases on May 13, 2014, wrote Katherine M Tassi, Uber’s managing counsel, privacy.

Supposedly, the information that may have been compromised included driver names and their driver license numbers, but the startup said that it is not aware of any “reports of actual misuse” of that data. The company said it will be contacting the drivers, issuing them memberships in identity-alert services and filing a lawsuit to obtain more information to learn who was the third party that accessed the database.

While…

View original post 179 more words

WordPress Security Best Practices (Linux)

Los sitios de WordPress son bastante populares y por lo tanto, sufren de ataques informáticos con regularidad. En el siguiente link puedes encontrar un artículo de Rackspace que te puede ayudar a mejorar la seguridad de tu sitio WordPress.

WordPress sites are very popular nowadays and suffer from constant hacking attempts. The following link can help you secure your WordPress site.

https://community.rackspace.com/products/f/25/t/4447.aspx