mmf 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 91d04ca8a24c777447c47109eb71c29e6bc316d6
4
+ data.tar.gz: e9bdb5bbae64ad863dc676221755fa68ab66272a
5
+ SHA512:
6
+ metadata.gz: c3a1c12f413800950bedde603a15d49654befe0c6adb2229f7ecdb57086680dfde514b468b5d4f72ca0281cb9e338505946dd83f83fe6146ac32cf122b8e3527
7
+ data.tar.gz: 7599866ce9c031aa2f04609e3a17965c3292d54f5b97548b033a389c8d66298ec10a1ef21b63d380b09ed7c06ab72068d1da62cbb539b3225895dbdf81dac92c
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+
4
+ gem 'pry'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Alex Skryl
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,85 @@
1
+ # Mmf
2
+
3
+ A Ruby REST Client for the MapMyFitness API. [Here](http://skryl.org) is how I use it.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'mmf'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install mmf
18
+
19
+ ## Authentication Tokens
20
+
21
+ Mmf uses Oauth2 to authenticate with the MapMyFitness API. Please go [here](https://developer.mapmyapi.com)
22
+ to create a developer account and get your client keys. Then go [here](https://developer.mapmyapi.com/io-docs)
23
+ to generate an access token.
24
+
25
+ ## Usage
26
+
27
+ You can provide your credentials during initialization.
28
+
29
+ ```ruby
30
+ client = Mmf::Client.new do |config|
31
+ config.client_key = 'YOUR_CLIENT_KEY'
32
+ config.client_secret = 'YOUR_CLIENT_SECRET'
33
+ config.access_token = 'YOUR_ACCESS_TOKEN'
34
+ end
35
+ ```
36
+
37
+ To see which API calls are supported, run the following from irb.
38
+
39
+ ```ruby
40
+ client.api
41
+ ```
42
+
43
+ The output will show a mapping between method calls and API calls. See the [API docs](https://developer.mapmyapi.com/docs)
44
+ for details on each API call or use the MapMyFitness [I/O docs](https://developer.mapmyapi.com/io-docs) to play with the API
45
+ from your browser.
46
+
47
+ ```text
48
+ client.me => [get] v7.0/user/self/?params
49
+ client.workouts => [get] v7.0/workout/?params
50
+ client.add_workout => [post] v7.0/workout/?params
51
+ client.deactivate => [post] v7.0/user_deactivation/?params
52
+ client.user => [get] v7.0/user/:user_id/?params
53
+ client.user_create => [post] v7.0/user/?params
54
+ client.user_update => [put] v7.0/user/:user_id/?params
55
+ client.user_photo => [get] v7.0/user_profile_photo/:user_id/?params
56
+ client.user_stats => [get] v7.0/user_stats/:user_id/?params
57
+ client.workout => [get] v7.0/workout/:workout_id/?params
58
+ client.achievement => [get] v7.0/acievement/:achievement_id/?params
59
+ client.achievements => [get] v7.0/user_acievement/?params
60
+ ```
61
+
62
+ All client methods take an optional params hash which is used to build the
63
+ RESTful API endpoint URI.
64
+
65
+ ## Examples
66
+
67
+ Get all workouts for the authenticated user.
68
+
69
+ ```ruby
70
+ client.workouts(user: client.me['id'])
71
+ ```
72
+
73
+ Get a single workout with time-series data (distance/heartrate/speed) included.
74
+
75
+ ```ruby
76
+ client.workout(workout_id: 456955773, field_set: 'time_series')
77
+ ```
78
+
79
+ ## Contributing
80
+
81
+ 1. Fork it
82
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
83
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
84
+ 4. Push to the branch (`git push origin my-new-feature`)
85
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/lib/mmf.rb ADDED
@@ -0,0 +1,74 @@
1
+ require "mmf/version"
2
+ require 'oauth2'
3
+ require 'json'
4
+
5
+ class Mmf::Client
6
+ ROOT_URI = "https://oauth2-api.mapmyapi.com/"
7
+
8
+ VAR = /%\{(.*?)\}/
9
+ API_MAP = {
10
+ # user resources
11
+ me: { method: :get, endpoint: 'v7.0/user/self' },
12
+ workouts: { method: :get, endpoint: 'v7.0/workout' },
13
+ add_workout: { method: :post, endpoint: 'v7.0/workout' },
14
+ deactivate: { method: :post, endpoint: 'v7.0/user_deactivation', },
15
+
16
+ user: { method: :get, endpoint: 'v7.0/user/%{user_id}' },
17
+ user_create: { method: :post, endpoint: 'v7.0/user' },
18
+ user_update: { method: :put, endpoint: 'v7.0/user/%{user_id}' },
19
+ user_photo: { method: :get, endpoint: 'v7.0/user_profile_photo/%{user_id}' },
20
+ user_stats: { method: :get, endpoint: 'v7.0/user_stats/%{user_id}' },
21
+
22
+ workout: { method: :get, endpoint: 'v7.0/workout/%{workout_id}' },
23
+
24
+ achievement: { method: :get, endpoint: 'v7.0/acievement/%{achievement_id}' },
25
+ achievements: { method: :get, endpoint: 'v7.0/user_acievement' }
26
+ }
27
+
28
+ attr_accessor :client_key, :client_secret, :access_token
29
+
30
+ def initialize
31
+ @client_key, @client_secret, @access_token = ""
32
+ yield self
33
+ client = OAuth2::Client.new(client_key, client_secret)
34
+ @client = OAuth2::AccessToken.new(client, access_token)
35
+ end
36
+
37
+ API_MAP.keys.each do |name|
38
+ define_method(name) do |params = {}|
39
+ call(name, params)
40
+ end
41
+ end
42
+
43
+ def api
44
+ API_MAP.any? do |name, details|
45
+ vars = details[:endpoint].scan(VAR).flatten
46
+ context = Hash[vars.zip vars.map {|v| ":#{v}"}]
47
+ endpoint = interpolate(details[:endpoint], context)
48
+ puts "client.#{name}".ljust(20) + "=> [#{details[:method]}]".ljust(10) + "#{endpoint}/?params"
49
+ end
50
+ end
51
+
52
+ private
53
+
54
+ def call(name, params)
55
+ method = API_MAP[name][:method]
56
+ endpoint = interpolate(API_MAP[name][:endpoint], params)
57
+ request(method, endpoint, params)
58
+ end
59
+
60
+ def request(method, endpoint, params)
61
+ uri = "#{ROOT_URI}/#{endpoint}"
62
+ opts = { params: params, headers: {'Api-Key' => client_key} }
63
+ resp = @client.send(method, uri, opts)
64
+ JSON.parse(resp.body)
65
+ end
66
+
67
+ def interpolate(str, context)
68
+ vars = str.scan(VAR).flatten
69
+ vars.inject(str) do |str, var|
70
+ str.gsub("\%{#{var}}", (context[var.to_sym] || context[var.to_s]).to_s)
71
+ end
72
+ end
73
+
74
+ end
@@ -0,0 +1,3 @@
1
+ module Mmf
2
+ VERSION = "0.2.1"
3
+ end
data/mmf.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mmf/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mmf"
8
+ spec.version = Mmf::VERSION
9
+ spec.authors = ["Alex Skryl"]
10
+ spec.email = ["rut216@gmail.com"]
11
+ spec.description = %q{Ruby REST Client for the MapMyFitness API.}
12
+ spec.summary = %q{Ruby REST Client for the MapMyFitness API}
13
+ spec.homepage = "http://github.com/skryl/mmf"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "oauth2"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mmf
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ platform: ruby
6
+ authors:
7
+ - Alex Skryl
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: oauth2
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Ruby REST Client for the MapMyFitness API.
56
+ email:
57
+ - rut216@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/mmf.rb
68
+ - lib/mmf/version.rb
69
+ - mmf.gemspec
70
+ homepage: http://github.com/skryl/mmf
71
+ licenses:
72
+ - MIT
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 2.0.3
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: Ruby REST Client for the MapMyFitness API
94
+ test_files: []
95
+ has_rdoc: