Coder Social home page Coder Social logo

nike_v2's Introduction

NikeV2

Build Status

Learn more about the Nike+ API at https://developer.nike.com/.

Installation

gem install nike_v2

Comming Soon

Once Nike releases the OAuth api this gem will include the ability to fetch the access token too

Examples

In order to utilize the Nike+ API in its current state, you'll need to do the following:

require 'nike_v2'

# Initialize a person
person = NikeV2::Person.new(access_token: 'a1b2c3d4')
# Fetch persons summary
person.summary
# Fetch a persons activities
person.activities
# Load more data for an activity
activity = person.activities.first
activity.fetch_data
# Fetch GPS Data for an activity
activity.gps_data

The activities api allows you to directly pass arguements to the Nike+ api. It also allows you to prefetch the metrics for each activity returned

#fetch 99 activities
person.activities(:count => 99)
#prefetch the metrics for activities
person.activities(:build_metrics => true)

We also smart load the metrics for activities now so you don't have to explicity load them

person.activities.total_fuel #fetches the metrics if they aren't already loaded
 => 394

As of version 0.3.0 you can cache calls to the Nike+ V2 api. We use the ApiCache (https://github.com/mloughran/api_cache) gem for this and all options in cache directive are passed to the api_cache config. Setting config.cache false disables the cache

# config/initializers/nike_v2.rb
NikeV2.configure do |config|
  config.cache = {
    :cache => 3600
  }
end

Possible options:

{
  :cache => 600,    # 10 minutes  After this time fetch new data
  :valid => 86400,  # 1 day       Maximum time to use old data
                    #             :forever is a valid option
  :period => 60,    # 1 minute    Maximum frequency to call API
  :timeout => 5     # 5 seconds   API response timeout
  :fail =>          # Value returned instead of exception on failure
}

Making it Better

  • Fork the project.
  • Make your feature addition or bug fix in a new topic branch within your repo.
  • Add specs for any new or modified functionality.
  • Commit and push your changes to Github
  • Send a pull request

Inspiration

I used Kevin Thompson's NikeApi gem as inspiration. Find it here: https://github.com/kevinthompson/nike_api

Copyright

Copyright (c) 2013 SmashTank Apps, LLC.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

nike_v2's People

Contributors

gleuch avatar parthbarot-botreeconsulting avatar tkrajcar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

nike_v2's Issues

User Activities - "Wrong argument" error thrown on 'fetch_more' method, line 30

Problem:

While fetching user activities using person.activities.fetch_more method, following error is thrown,

ArgumentError: wrong number of arguments(0 for 1)
  from /home/temp_user/.rvm/gems/ruby-1.9.3-p194/gems/nike_v2-0.1.2/lib/nike_v2/activities.rb:30:in `delete'
  from /home/temp_user/.rvm/gems/ruby-1.9.3-p194/gems/nike_v2-0.1.2/lib/nike_v2/activities.rb:30:in `fetch_more'
  from (irb):17
  from /home/temp_user/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.11/lib/rails/commands/console.rb:47:in `start'
  from /home/temp_user/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.11/lib/rails/commands/console.rb:8:in `start'
  from /home/temp_user/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.11/lib/rails/commands.rb:41:in `<top (required)>'
  from script/rails:6:in `require'
  from script/rails:6:in `<main>'

Solution:

  • Changing [] with () for syntax error in .delete method call, line 30. This introduces the following error,
NoMethodError: undefined method `paging=' for #<NikeV2::Activities:0x9f16d60>
  from /home/temp_user/parth/projects/support/nike_v2/lib/nike_v2/activities.rb:30:in `fetch_more'
  from (irb):2
  from /home/temp_user/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.11/lib/rails/commands/console.rb:47:in `start'
  from /home/temp_user/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.11/lib/rails/commands/console.rb:8:in `start'
  from /home/temp_user/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.11/lib/rails/commands.rb:41:in `<top (required)>'
  from script/rails:6:in `require'
  from script/rails:6:in `<main>'

  • Changing self.paging= to @paging, because no setter method present. Or Instead, We could also change this in resource.rb, to define new setter method for each attribute.

Nike OAuth

Do you think nike will ever release their oauth so you can make api calls on behalf of users? I can't seem to find anything but this api has been out for years.

Invalid Access Token

I managed to grab the access token for my account through the test console, but it doesn't seem to recognize it when I paste it into the code. Any help?

person = NikeV2::Person.new(access_token: 'xxx')

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.