strava-cli 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0d795febc4b2b8ba8c192ffd1011d7c3d10090ae
4
- data.tar.gz: e62ff619b626dd2de5275ae79ad0a2060e86b1ed
3
+ metadata.gz: 6b91beaa1f5816931d2c4fd42031fa9cdd15577b
4
+ data.tar.gz: 674d99f373e57f3560ea6f0741feec13c11d5a72
5
5
  SHA512:
6
- metadata.gz: 5b10992a18ffdcfa8deda09e5e38b5b4628073f8193504fdc7dd13227667d3d1bc79d4468fbc462c2d59b0f2d47ae28a62b0b13c6f18915d26f82a010893c3df
7
- data.tar.gz: 9f84c2b6147871938fa2ae154a2788f262b8c56a95ea30ee47ce0d0e163b57a4ff00c75a1007fe6a05e9af929886f02aad640b27410043b36fcb26a1c138b1cf
6
+ metadata.gz: 1d7ddb1356926a8b6c143c2b9092a6efeae23f2dee759d3accb4ba1f2d865941eba58641e36fa15a37a677387959167655fbfa339ae8bad5a070d74d9e2cb907
7
+ data.tar.gz: 8375598e1b3a3682d03ae449ce025dc7cfe62c177da46fcfa6e78980e8b3c0bac5b4f8242c145ddda59e59e3adf1a891e066cd9270cfd04dca6a0dc906c65d0c
data/lib/strava.rb CHANGED
@@ -4,6 +4,11 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
4
4
  require 'hashie'
5
5
  class Hash; include Hashie::Extensions::MethodAccess; end
6
6
 
7
+ module Strava
8
+ BASE_NAME = 'strava'.freeze
9
+ end
10
+
11
+ require 'strava/cache'
7
12
  require 'strava/version'
8
13
  require 'strava/activity'
9
14
  require 'strava/app'
data/lib/strava/app.rb CHANGED
@@ -2,13 +2,6 @@ require 'easy_app_helper'
2
2
  require 'terminal-table'
3
3
  require 'ascii_charts'
4
4
  require 'strava/api/v3'
5
- require 'vcr'
6
-
7
- # Configure HTTP records
8
- VCR.configure do |config|
9
- config.cassette_library_dir = "#{File.expand_path('~')}/.strava"
10
- config.hook_into :webmock
11
- end
12
5
 
13
6
  module Strava
14
7
  class App
@@ -17,10 +10,10 @@ module Strava
17
10
  NAME = 'Strava Dashboard'
18
11
  DESCRIPTION = 'Fetchs data from strava to report what you have done'
19
12
 
20
- attr_accessor :client, :types, :graph, :activities
13
+ attr_accessor :client, :types, :graph, :activities, :publicize, :simulate
21
14
 
22
15
  def initialize
23
- config.config_file_base_name = 'strava'
16
+ config.config_file_base_name = Strava::BASE_NAME
24
17
  config.describes_application app_name: NAME,
25
18
  app_version: Strava::VERSION,
26
19
  app_description: DESCRIPTION
@@ -29,6 +22,8 @@ module Strava
29
22
  slop.on :strava_access_token, 'Strava access token', argument: true, as: String
30
23
  slop.on :activity, 'Display this activity type only (Run, Ride, Swim)', argument: true
31
24
  slop.on :graph, 'Display a graph instead of a table', argument: false
25
+ slop.on :scope, 'Display limited scoped activities (public or private)', argument: true
26
+ slop.on :publicize, 'Make private activities public', argument: false
32
27
  end
33
28
 
34
29
  if config[:help]
@@ -42,6 +37,10 @@ module Strava
42
37
  @types = %w(Run Ride Swim)
43
38
  end
44
39
  @graph = config[:graph]
40
+ @scope = config[:scope]
41
+ @cache_key = config[:cache_key] || "activities"
42
+ @publicize = config[:publicize]
43
+ @simulate = config[:simulate]
45
44
  @activities = []
46
45
  end
47
46
 
@@ -56,7 +55,9 @@ module Strava
56
55
 
57
56
  for type in types
58
57
 
59
- if graph
58
+ if publicize
59
+ publicize_activities(type)
60
+ elsif graph
60
61
  output_screen = build_graph_speed(type)
61
62
  else
62
63
  output_screen = build_table(type)
@@ -140,18 +141,33 @@ module Strava
140
141
  end
141
142
 
142
143
  def fetch_activities_data
143
- VCR.use_cassette("activities", record: :new_episodes) do
144
+ VCR.use_cassette(@cache_key, record: :new_episodes) do
144
145
  page = 0
145
146
  per_page = 100
147
+
146
148
  while activities.count == page*per_page
147
149
  page +=1
148
- @activities += client.list_athlete_activities(per_page: per_page,page: page)
150
+ @activities += client.list_athlete_activities(per_page: per_page, page: page)
149
151
  end
150
152
  end
151
153
  end
152
154
 
153
155
  def select_activities(type)
154
- activities.select { |activity| activity.type == type }
156
+ activities.select do |activity|
157
+ activity.type == type &&
158
+ @scope.nil? || (!activity.private ^ (@scope == 'private'))
159
+ end
160
+ end
161
+
162
+ def publicize_activities(type)
163
+ filtered_activities = select_activities(type)
164
+ $stdout.puts "You are about to make #{filtered_activities.count} public. Are you sure? (y/n)"
165
+ if $stdin.gets.strip == 'y' && !simulate
166
+ filtered_activities.each do |activity|
167
+ client.update_an_activity(activity.id, private: false)
168
+ end
169
+ $stdout.puts "#{filtered_activities.count} activities were made public! /o/"
170
+ end
155
171
  end
156
172
  end
157
173
  end
@@ -0,0 +1,11 @@
1
+ require 'vcr'
2
+
3
+ # Configure HTTP cache
4
+ VCR.configure do |config|
5
+ config.cassette_library_dir = "#{File.expand_path('~')}/.#{Strava::BASE_NAME}"
6
+ config.hook_into :webmock
7
+ config.ignore_request do |request|
8
+ request.method != :get
9
+ end
10
+
11
+ end
@@ -1,3 +1,3 @@
1
1
  module Strava
2
- VERSION = '0.0.2'.freeze
2
+ VERSION = '0.0.3'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: strava-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Bonaud
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-29 00:00:00.000000000 Z
11
+ date: 2017-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: easy_app_helper
@@ -318,6 +318,7 @@ files:
318
318
  - lib/strava.rb
319
319
  - lib/strava/activity.rb
320
320
  - lib/strava/app.rb
321
+ - lib/strava/cache.rb
321
322
  - lib/strava/version.rb
322
323
  - strava.gemspec
323
324
  homepage: https://rubygems.org/gems/strava-cli
@@ -340,7 +341,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
340
341
  version: '0'
341
342
  requirements: []
342
343
  rubyforge_project:
343
- rubygems_version: 2.6.8
344
+ rubygems_version: 2.6.13
344
345
  signing_key:
345
346
  specification_version: 4
346
347
  summary: Generate strava dashboards.