strava 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,33 @@
1
+ module Strava
2
+ class Stream
3
+ # Class to represent Strava Stream
4
+ # https://strava.github.io/api/v3/activities/
5
+
6
+ attr_reader :type, :data
7
+
8
+ def initialize(data)
9
+ # @response = data
10
+ @id = data["id"]
11
+
12
+ @type = data["type"] # => "latlng",
13
+ @data = data["data"] # => [...],
14
+ @series_type = data["series_type"] # => "distance",
15
+ @original_size = data["original_size"] # => 512,
16
+ @resolution = data["resolution"] # => "low"
17
+
18
+ self
19
+ end
20
+
21
+ def size
22
+ @data.size
23
+ end
24
+ def [](i)
25
+ @data[i]
26
+ end
27
+
28
+ end
29
+ end
30
+
31
+ __END__
32
+
33
+ ca = Strava::Athlete.current_athlete;
@@ -0,0 +1,62 @@
1
+ module Strava
2
+ class StreamSet
3
+ # Class to contain Strava Streams
4
+ # http://strava.github.io/api/v3/streams/
5
+
6
+ attr_reader :type, :data
7
+ def initialize(data = {})
8
+ @streams = {}
9
+ update(data)
10
+ end
11
+
12
+ def all
13
+ size = @streams.values.first.size
14
+ size.times.map do |i|
15
+ @streams.map do |type, stream|
16
+ [type, stream[i]]
17
+ end.to_h
18
+ end
19
+ end
20
+
21
+ def all2
22
+ size = @streams.values.first.size
23
+ size.times.map do |i|
24
+ @streams.map do |type, stream|
25
+ { type => stream[i] }
26
+ end.inject(:merge)
27
+ end
28
+ end
29
+
30
+ def empty?
31
+ @streams.empty?
32
+ end
33
+
34
+ def update(data, **opts)
35
+ @response = data
36
+
37
+ data.each do |stream_data|
38
+ stream = Stream.new(stream_data)
39
+ @streams[stream.type] = stream
40
+ end
41
+
42
+ self
43
+ end
44
+
45
+ def time; @streams['time']; end
46
+ def latlng; @streams['latlng']; end
47
+ def distance; @streams['distance']; end
48
+ def altitude; @streams['altitude']; end
49
+ def velocity_smooth; @streams['velocity_smooth']; end
50
+ def heartrate; @streams['heartrate']; end
51
+ def cadence; @streams['cadence']; end
52
+ def watts; @streams['watts']; end
53
+ def temp; @streams['temp']; end
54
+ def moving; @streams['moving']; end
55
+ def grade_smooth; @streams['grade_smooth']; end
56
+
57
+ end
58
+ end
59
+
60
+ __END__
61
+
62
+ ca = Strava::Athlete.current_athlete;
@@ -0,0 +1,38 @@
1
+ module Strava
2
+ # Provides data on Strava API limits and usage.
3
+ #
4
+ # Usage:
5
+ #
6
+ # ca = Strava::Athlete.current_athlete
7
+ # usage = ca.client.usage
8
+ # usage.recent_usage # => 254
9
+ # usage.daily_usage # => 12536
10
+ # usage.recent_pct # => 0.423
11
+ # usage.daily_pct # => 0.417
12
+ #
13
+ # @see https://strava.github.io/api/#rate-limiting Strava Docs - Rate Limiting
14
+ class Usage
15
+ attr_reader :recent_limit, :daily_limit, :recent_usage, :daily_usage
16
+
17
+ def initialize(limit_str, usage_str)
18
+ @recent_limit, @daily_limit = limit_str.to_s.split(',').map(&:to_i)
19
+ @recent_usage, @daily_usage = usage_str.to_s.split(',').map(&:to_i)
20
+ end
21
+
22
+ # Percentage of recent limit used.
23
+ #
24
+ # @return [Float] Between 0.0 and 1.0
25
+ def recent_pct
26
+ @recent_usage.fdiv(@recent_limit)
27
+ end
28
+
29
+ # Percentage of daily limit used.
30
+ #
31
+ # @return [Float] Between 0.0 and 1.0
32
+ def daily_pct
33
+ @daily_usage.fdiv(@daily_limit)
34
+ end
35
+
36
+ end
37
+ end
38
+
@@ -0,0 +1,4 @@
1
+ module Strava
2
+ VERSION = "0.1.0"
3
+ STRAVA_API_DATE = 'April 10th, 2017' # latest supported update to Strava API
4
+ end
data/strava.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'strava/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "strava"
8
+ spec.version = Strava::VERSION
9
+ spec.authors = ["Paul Hoffer"]
10
+ spec.email = ["git@paulhoffer.com"]
11
+
12
+ spec.summary = %q{Friendly client for Strava's V3 API.}
13
+ spec.description = %q{Client for Strava's V3 API, with a friendly object oriented approach to Strava resources.}
14
+ spec.homepage = "https://github.com/phoffer/strava"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.14"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "minitest", "~> 5.0"
27
+
28
+ spec.add_dependency "httparty", ">= 0.14.0"
29
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: strava
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Paul Hoffer
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-07-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: httparty
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 0.14.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 0.14.0
69
+ description: Client for Strava's V3 API, with a friendly object oriented approach
70
+ to Strava resources.
71
+ email:
72
+ - git@paulhoffer.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".travis.yml"
79
+ - ".yardopts"
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - lib/strava.rb
87
+ - lib/strava/activity.rb
88
+ - lib/strava/adapters/httparty_adapter.rb
89
+ - lib/strava/athlete.rb
90
+ - lib/strava/base.rb
91
+ - lib/strava/client.rb
92
+ - lib/strava/club.rb
93
+ - lib/strava/club_announcement.rb
94
+ - lib/strava/comment.rb
95
+ - lib/strava/error.rb
96
+ - lib/strava/gear.rb
97
+ - lib/strava/group_event.rb
98
+ - lib/strava/lap.rb
99
+ - lib/strava/leaderboard.rb
100
+ - lib/strava/leaderboard_entry.rb
101
+ - lib/strava/photo.rb
102
+ - lib/strava/route.rb
103
+ - lib/strava/running_race.rb
104
+ - lib/strava/segment.rb
105
+ - lib/strava/segment_effort.rb
106
+ - lib/strava/stream.rb
107
+ - lib/strava/stream_set.rb
108
+ - lib/strava/usage.rb
109
+ - lib/strava/version.rb
110
+ - strava.gemspec
111
+ homepage: https://github.com/phoffer/strava
112
+ licenses:
113
+ - MIT
114
+ metadata: {}
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubyforge_project:
131
+ rubygems_version: 2.6.11
132
+ signing_key:
133
+ specification_version: 4
134
+ summary: Friendly client for Strava's V3 API.
135
+ test_files: []