Project

rjawbone

0.0
No commit activity in last 3 years
No release in over 3 years
A Ruby API wrapper for the Jawbone API.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.11
>= 0
>= 0
~> 10.0
~> 3.4
~> 3.0
~> 1.24

Runtime

>= 0
 Project Readme

Rjawbone

Homepage
homepage
Author
Taylor Daugherty
Documentation
Ruby Gems

Gem Version Build Status Code Climate Test Coverage Inline docs Dependency Status

Installation

gem install rjawbone

Configuration

Rjawbone.configure do |config|
  config.client_id = ENV['JAWBONE_CLIENT']
  config.client_secret = ENV['JAWBONE_SECRET']
  config.redirect_uri = redirect_uri
  config.scope = %w(basic_read sleep_read move_read) # any scope you need here
end

For a rails project, you can put this in config/initializers/rjawbone.rb.

Authentication

This gem provides two helper methods for following the OAuth 2.0 flow.

# Returns a url for your configured jawbone application
Rjawbone::Oauth.authorization_url 

# Exchanges the authorization code for an access token
Rjawbone::Oauth.exchange_code(code)

After obtaining an access token, you will need to persist it.

Here you can read about the authorization flow.

Client

API calls are made by initializing a Rjawbone client object.

The ACCESS_TOKEN is retrieved from the Authentication step.

client = Rjawbone::Client.new(access_token: ACCESS_TOKEN, refresh_token: REFRESH)

# OR

client = Rjawbone::Client.new do |config|
  config.access_token = TOKEN
  config.refresh_token = REFRESH
end

After initializing the client object, you can retrieve any object allowed by your configured scope.

Resources

Lists

# Returns a Rjawbone::Model::List object
list = client.moves

# The list has a collection attribute, composed of Rjawbone::Model::Item objects
# The list object has methods that assist in retrieving information

# Pagination
list.next_page

# Enumerability
list.map {|move| move.xid }
list.select {|move| move.details.distance >= 5000}

Items

# The item object has all the fields from the raw API response
# When a "sleep" or "move" type, the Rjawbone::Model::Item can implement the #ticks method

list = client.moves
move = list.first

# Returns a Rjawbone::Model::List of objects of "ticks"
# The ticks associated with that move resource
ticks = move.ticks

# These ticks are a list, so include enumerablity and pagination methods
ticks.reject {|tick| tick.steps <= 50}
ticks = client.moves.map {|item| item.ticks}

Resources

Implemented endpoints:

  • moves
  • sleeps
  • heartrates

Rails

There is Rails helper for generating the authorization url. If you are in a rails view:

# jawbone_url generates the correct OAuth url.
<%= link_to "Login with Jawbone", jawbone_url %>

TODO

  • band_events
  • body_events
  • goals
  • meals
  • mood
  • settings
  • timezone
  • trends
  • friends