Class: Strava::App

Inherits:
Object
  • Object
show all
Includes:
EasyAppHelper
Defined in:
lib/strava/app.rb

Constant Summary collapse

NAME =
'Strava Dashboard'
DESCRIPTION =
'Fetchs data from strava to report what you have done'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeApp

Returns a new instance of App.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/strava/app.rb', line 15

def initialize
  config.config_file_base_name = Strava::BASE_NAME
  config.describes_application app_name: NAME,
                               app_version: Strava::VERSION,
                               app_description: DESCRIPTION

  config.add_command_line_section('Strava options') do |slop|
    slop.on :strava_access_token, 'Strava access token', argument: true, as: String
    slop.on :activity, 'Display this activity type only (Run, Ride, Swim)', argument: true
    slop.on :graph, 'Display a graph instead of a table', argument: false
    slop.on :scope, 'Display limited scoped activities (public or private)', argument: true
    slop.on :publicize, 'Make private activities public', argument: false
  end

  if config[:help]
    puts config.command_line_help
    exit 0
  end

  if config[:activity]
    @types = [config[:activity]]
  else
    @types = %w(Run Ride Swim)
  end
  @graph = config[:graph]
  @scope = config[:scope]
  @cache_key = config[:cache_key] || "activities"
  @publicize = config[:publicize]
  @simulate  = config[:simulate]
  @activities = []
end

Instance Attribute Details

#activitiesObject

Returns the value of attribute activities.



13
14
15
# File 'lib/strava/app.rb', line 13

def activities
  @activities
end

#clientObject

Returns the value of attribute client.



13
14
15
# File 'lib/strava/app.rb', line 13

def client
  @client
end

#graphObject

Returns the value of attribute graph.



13
14
15
# File 'lib/strava/app.rb', line 13

def graph
  @graph
end

#publicizeObject

Returns the value of attribute publicize.



13
14
15
# File 'lib/strava/app.rb', line 13

def publicize
  @publicize
end

#simulateObject

Returns the value of attribute simulate.



13
14
15
# File 'lib/strava/app.rb', line 13

def simulate
  @simulate
end

#typesObject

Returns the value of attribute types.



13
14
15
# File 'lib/strava/app.rb', line 13

def types
  @types
end

Instance Method Details

#configure_api_clientObject



47
48
49
# File 'lib/strava/app.rb', line 47

def configure_api_client
  @client = Strava::Api::V3::Client.new(access_token: config[:strava_access_token])
end

#runObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/strava/app.rb', line 51

def run
  configure_api_client

  fetch_activities_data

  for type in types

    if publicize
      publicize_activities(type)
    elsif graph
      output_screen = build_graph_speed(type)
    else
      output_screen = build_table(type)
    end

    if output_screen.nil?
      puts "No activity found. Go out and start #{type}ing!"
    else
      puts output_screen
    end
    puts "\n"
  end
end