diff --git a/.rvmrc b/.rvmrc deleted file mode 100644 index 4019812..0000000 --- a/.rvmrc +++ /dev/null @@ -1,7 +0,0 @@ - -if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \ - && -s "${rvm_path:-$HOME/.rvm}/environments/ruby-1.9.2-p0@health_graph" ]] ; then - \. "${rvm_path:-$HOME/.rvm}/environments/ruby-1.9.2-p0@health_graph" -else - rvm --create "ruby-1.9.2-p0@health_graph" -fi diff --git a/Gemfile b/Gemfile index 09bdd33..847f7f7 100644 --- a/Gemfile +++ b/Gemfile @@ -3,10 +3,10 @@ source "http://rubygems.org" # Example: # gem "activesupport", ">= 2.3.5" -gem "oauth2", "= 0.5.1" +gem "oauth2", "= 0.5.2" gem "faraday", "= 0.7.4" gem "faraday_middleware", "= 0.7.0" -gem "hashie", "= 1.1.0" +gem "hashie", "= 1.2" # Add dependencies to develop your gem here. # Include everything needed to run rake, tests, features, etc. diff --git a/Gemfile.lock b/Gemfile.lock index bd32e8a..c1b0aad 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -10,16 +10,16 @@ GEM faraday_middleware (0.7.0) faraday (~> 0.7.3) git (1.2.5) - hashie (1.1.0) + hashie (1.2.0) jeweler (1.6.4) bundler (~> 1.0) git (>= 1.2.5) rake - multi_json (1.0.3) + multi_json (1.0.4) multipart-post (1.1.3) - oauth2 (0.5.1) - faraday (~> 0.7.4) - multi_json (~> 1.0.3) + oauth2 (0.5.2) + faraday (~> 0.7) + multi_json (~> 1.0) rack (1.3.4) rake (0.9.2) rcov (0.9.10) @@ -35,9 +35,9 @@ DEPENDENCIES bundler (~> 1.0.0) faraday (= 0.7.4) faraday_middleware (= 0.7.0) - hashie (= 1.1.0) + hashie (= 1.2) jeweler (~> 1.6.4) - oauth2 (= 0.5.1) + oauth2 (= 0.5.2) rcov shoulda webmock (= 1.7.4) diff --git a/Rakefile b/Rakefile index aa02cda..b13872b 100644 --- a/Rakefile +++ b/Rakefile @@ -22,10 +22,10 @@ Jeweler::Tasks.new do |gem| gem.email = "kenny@kennyma.me" gem.authors = ["Kenny Ma"] # dependencies defined in Gemfile - gem.add_dependency 'oauth2', '= 0.5.1' + gem.add_dependency 'oauth2', '= 0.5.2' gem.add_dependency 'faraday', '= 0.7.4' gem.add_dependency 'faraday_middleware', '= 0.7.0' - gem.add_dependency 'hashie', '= 1.1.0' + gem.add_dependency 'hashie', '= 1.2' gem.add_dependency 'webmock', '= 1.7.6' end Jeweler::RubygemsDotOrgTasks.new diff --git a/health_graph.gemspec b/health_graph.gemspec index 3e20eb2..dad61f7 100644 --- a/health_graph.gemspec +++ b/health_graph.gemspec @@ -4,33 +4,34 @@ # -*- encoding: utf-8 -*- Gem::Specification.new do |s| - s.name = %q{health_graph} + s.name = "health_graph" s.version = "0.5.1" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Kenny Ma"] - s.date = %q{2011-10-10} - s.description = %q{This is a wrapper for RunKeeper Health Graph RESTful API.} - s.email = %q{kenny@kennyma.me} + s.date = "2012-02-17" + s.description = "This is a wrapper for RunKeeper Health Graph RESTful API." + s.email = "kenny@kennyma.me" s.extra_rdoc_files = [ "LICENSE.txt", "README.rdoc" ] s.files = [ ".document", - ".rvmrc", "Gemfile", "Gemfile.lock", "LICENSE.txt", "README.rdoc", "Rakefile", "VERSION", + "health_graph.gemspec", "lib/health_graph.rb", "lib/health_graph/api.rb", "lib/health_graph/authentication.rb", "lib/health_graph/configuration.rb", "lib/health_graph/model.rb", "lib/health_graph/models/fitness_activities_feed.rb", + "lib/health_graph/models/new_fitness_activity.rb", "lib/health_graph/models/profile.rb", "lib/health_graph/models/sleep_feed.rb", "lib/health_graph/models/user.rb", @@ -54,61 +55,60 @@ Gem::Specification.new do |s| "test/helper.rb", "test/test_health_graph.rb" ] - s.homepage = %q{http://github.com/kennyma/health_graph} + s.homepage = "http://github.com/kennyma/health_graph" s.licenses = ["MIT"] s.require_paths = ["lib"] - s.rubygems_version = %q{1.3.7} - s.summary = %q{Ruby gem for RunKeeper Health Graph API} + s.rubygems_version = "1.8.13" + s.summary = "Ruby gem for RunKeeper Health Graph API" if s.respond_to? :specification_version then - current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION s.specification_version = 3 if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then - s.add_runtime_dependency(%q, ["= 0.5.1"]) + s.add_runtime_dependency(%q, ["= 0.5.2"]) s.add_runtime_dependency(%q, ["= 0.7.4"]) s.add_runtime_dependency(%q, ["= 0.7.0"]) - s.add_runtime_dependency(%q, ["= 1.1.0"]) + s.add_runtime_dependency(%q, ["= 1.2"]) s.add_development_dependency(%q, [">= 0"]) s.add_development_dependency(%q, ["= 1.7.4"]) s.add_development_dependency(%q, ["~> 1.0.0"]) s.add_development_dependency(%q, ["~> 1.6.4"]) s.add_development_dependency(%q, [">= 0"]) - s.add_runtime_dependency(%q, ["= 0.5.1"]) + s.add_runtime_dependency(%q, ["= 0.5.2"]) s.add_runtime_dependency(%q, ["= 0.7.4"]) s.add_runtime_dependency(%q, ["= 0.7.0"]) - s.add_runtime_dependency(%q, ["= 1.1.0"]) + s.add_runtime_dependency(%q, ["= 1.2"]) s.add_runtime_dependency(%q, ["= 1.7.6"]) else - s.add_dependency(%q, ["= 0.5.1"]) + s.add_dependency(%q, ["= 0.5.2"]) s.add_dependency(%q, ["= 0.7.4"]) s.add_dependency(%q, ["= 0.7.0"]) - s.add_dependency(%q, ["= 1.1.0"]) + s.add_dependency(%q, ["= 1.2"]) s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, ["= 1.7.4"]) s.add_dependency(%q, ["~> 1.0.0"]) s.add_dependency(%q, ["~> 1.6.4"]) s.add_dependency(%q, [">= 0"]) - s.add_dependency(%q, ["= 0.5.1"]) + s.add_dependency(%q, ["= 0.5.2"]) s.add_dependency(%q, ["= 0.7.4"]) s.add_dependency(%q, ["= 0.7.0"]) - s.add_dependency(%q, ["= 1.1.0"]) + s.add_dependency(%q, ["= 1.2"]) s.add_dependency(%q, ["= 1.7.6"]) end else - s.add_dependency(%q, ["= 0.5.1"]) + s.add_dependency(%q, ["= 0.5.2"]) s.add_dependency(%q, ["= 0.7.4"]) s.add_dependency(%q, ["= 0.7.0"]) - s.add_dependency(%q, ["= 1.1.0"]) + s.add_dependency(%q, ["= 1.2"]) s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, ["= 1.7.4"]) s.add_dependency(%q, ["~> 1.0.0"]) s.add_dependency(%q, ["~> 1.6.4"]) s.add_dependency(%q, [">= 0"]) - s.add_dependency(%q, ["= 0.5.1"]) + s.add_dependency(%q, ["= 0.5.2"]) s.add_dependency(%q, ["= 0.7.4"]) s.add_dependency(%q, ["= 0.7.0"]) - s.add_dependency(%q, ["= 1.1.0"]) + s.add_dependency(%q, ["= 1.2"]) s.add_dependency(%q, ["= 1.7.6"]) end end diff --git a/lib/health_graph.rb b/lib/health_graph.rb index 4753c2d..f7ac099 100644 --- a/lib/health_graph.rb +++ b/lib/health_graph.rb @@ -9,6 +9,7 @@ require 'health_graph/models/weight_feed' require 'health_graph/models/sleep_feed' require 'health_graph/models/fitness_activities_feed' +require 'health_graph/models/new_fitness_activity' module HealthGraph extend Configuration diff --git a/lib/health_graph/api.rb b/lib/health_graph/api.rb index 89b17c6..8a4210d 100644 --- a/lib/health_graph/api.rb +++ b/lib/health_graph/api.rb @@ -21,28 +21,30 @@ def delete(path, accept_header, params = {}) private def request(method, accept_header, path, params) - response = connection.send(method) do |request| + response = connection(method).send(method) do |request| request.headers['Authorization'] = "Bearer #{access_token}" - request.headers['Accept'] = accept_header case method.to_sym when :get, :delete + request.headers['Accept'] = accept_header request.url(path, params) when :put, :post + request.headers['Content-Type'] = accept_header request.path = path - request.body = params unless params.empty? + request.body = params.to_json unless params.empty? end end response.body end - def connection + def connection method merged_options = HealthGraph.faraday_options.merge({ :url => HealthGraph.endpoint }) - + Faraday.new(merged_options) do |builder| builder.use Faraday::Request::UrlEncoded + builder.use Faraday::Request::JSON if method == :post builder.use Faraday::Response::Mashify builder.use Faraday::Response::ParseJson builder.adapter(HealthGraph.adapter) diff --git a/lib/health_graph/configuration.rb b/lib/health_graph/configuration.rb index 437cedb..1f5991c 100644 --- a/lib/health_graph/configuration.rb +++ b/lib/health_graph/configuration.rb @@ -13,16 +13,17 @@ module Configuration DEFAULT_CLIENT_ID = nil DEFAULT_CLIENT_SECRET = nil - DEFAULT_AUTHORIZATION_URL = "http://runkeeper.com/apps/authorize".freeze - DEFAULT_ACCESS_TOKEN_URL = "http://runkeeper.com/apps/token".freeze + DEFAULT_AUTHORIZATION_URL = "https://runkeeper.com/apps/authorize".freeze + DEFAULT_ACCESS_TOKEN_URL = "https://runkeeper.com/apps/token".freeze DEFAULT_AUTHORIZATION_REDIRECT_URL = nil - DEFAULT_ENDPOINT = "http://api.runkeeper.com".freeze + DEFAULT_ENDPOINT = "https://api.runkeeper.com".freeze DEFAULT_ADAPTER = :net_http DEFAULT_FARADAY_OPTIONS = {}.freeze DEFAULT_ACCEPT_HEADERS = { :user => "application/vnd.com.runkeeper.User+json", :fitness_activity_feed => "application/vnd.com.runkeeper.FitnessActivityFeed+json", :fitness_activity => "application/vnd.com.runkeeper.FitnessActivity+json", + :new_fitness_activity => "application/vnd.com.runkeeper.NewFitnessActivity+json", :strength_training_activity_feed => "application/vnd.com.runkeeper.StrengthTrainingActivityFeed+json", :strength_training_activity => "application/vnd.com.runkeeper.StrengthTrainingActivity+json", :background_activity_feed => "application/vnd.com.runkeeper.BackgroundActivityFeed+json", @@ -38,8 +39,7 @@ module Configuration :diabetes_feed => "application/vnd.com.runkeeper.DiabetesFeed+json", :diatetes_measurement => "application/vnd.com.runkeeper.DiabetesMeasurement+json", :records => "application/vnd.com.runkeeper.Records+json", - :profile => "application/vnd.com.runkeeper.Profile+json", - :new_activity => "application/vnd.com.runkeeper.NewFitnessActivity+json" + :profile => "application/vnd.com.runkeeper.Profile+json" }.freeze attr_accessor *VALID_OPTIONS_KEYS diff --git a/lib/health_graph/model.rb b/lib/health_graph/model.rb index e267f0e..80d5848 100644 --- a/lib/health_graph/model.rb +++ b/lib/health_graph/model.rb @@ -30,7 +30,7 @@ def populate_from_hash!(hash) set_attr_method = "#{key}=" unless value.nil? if respond_to?(set_attr_method) - self.__send__(set_attr_method, value) + self.__send__(set_attr_method, value) end end end diff --git a/lib/health_graph/models/fitness_activities_feed.rb b/lib/health_graph/models/fitness_activities_feed.rb index 426891d..d4bf7d2 100644 --- a/lib/health_graph/models/fitness_activities_feed.rb +++ b/lib/health_graph/models/fitness_activities_feed.rb @@ -17,7 +17,7 @@ def initialize(hash) def initialize(access_token, path) self.access_token = access_token @body = get path, HealthGraph.accept_headers[:fitness_activity_feed] - populate_from_hash! @body + populate_from_hash! @body end end end \ No newline at end of file diff --git a/lib/health_graph/models/new_fitness_activity.rb b/lib/health_graph/models/new_fitness_activity.rb new file mode 100644 index 0000000..160678b --- /dev/null +++ b/lib/health_graph/models/new_fitness_activity.rb @@ -0,0 +1,11 @@ +module HealthGraph + class NewFitnessActivity + include Model + + def initialize access_token, params + self.access_token = access_token + @body = post "/fitnessActivities", HealthGraph.accept_headers[:new_fitness_activity], params + populate_from_hash! @body + end + end +end \ No newline at end of file diff --git a/lib/health_graph/models/user.rb b/lib/health_graph/models/user.rb index c7f6f88..3d01f7e 100644 --- a/lib/health_graph/models/user.rb +++ b/lib/health_graph/models/user.rb @@ -25,5 +25,9 @@ def sleep def fitness_activities HealthGraph::FitnessActivitiesFeed.new self.access_token, @body["fitness_activities"] end + + def new_fitness_activity(params) + HealthGraph::NewFitnessActivity.new self.access_token, params + end end end \ No newline at end of file