Skip to content

Commit

Permalink
feat: add activity methods
Browse files Browse the repository at this point in the history
  • Loading branch information
rfoel committed Dec 1, 2020
1 parent c2c9cab commit af09c56
Show file tree
Hide file tree
Showing 48 changed files with 855 additions and 36 deletions.
23 changes: 23 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
"type": "git",
"url": "git+https://github.com/rfoel/strava.git"
},
"keywords": [],
"keywords": [
"strava",
"api",
"client",
"node"
],
"author": "Rafael Franco <rafaelfr@outlook.com>",
"license": "MIT",
"bugs": {
Expand All @@ -33,6 +38,7 @@
"@semantic-release/github": "^7.1.1",
"@semantic-release/npm": "^7.0.6",
"@semantic-release/release-notes-generator": "^9.0.1",
"@types/node-fetch": "^2.5.7",
"jest": "^26.6.3",
"microbundle": "^0.12.4",
"nock": "^13.0.5",
Expand Down
39 changes: 39 additions & 0 deletions src/enums/activityType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
export enum ActivityType {
AlpineSki = 'AlpineSki',
BackcountrySki = 'BackcountrySki',
Canoeing = 'Canoeing',
Crossfit = 'Crossfit',
EBikeRide = 'EBikeRide',
Elliptical = 'Elliptical',
Golf = 'Golf',
Handcycle = 'Handcycle',
Hike = 'Hike',
IceSkate = 'IceSkate',
InlineSkate = 'InlineSkate',
Kayaking = 'Kayaking',
Kitesurf = 'Kitesurf',
NordicSki = 'NordicSki',
Ride = 'Ride',
RockClimbing = 'RockClimbing',
RollerSki = 'RollerSki',
Rowing = 'Rowing',
Run = 'Run',
Sail = 'Sail',
Skateboard = 'Skateboard',
Snowboard = 'Snowboard',
Snowshoe = 'Snowshoe',
Soccer = 'Soccer',
StairStepper = 'StairStepper',
StandUpPaddling = 'StandUpPaddling',
Surfing = 'Surfing',
Swim = 'Swim',
Velomobile = 'Velomobile',
VirtualRide = 'VirtualRide',
VirtualRun = 'VirtualRun',
Walk = 'Walk',
WeightTraining = 'WeightTraining',
Wheelchair = 'Wheelchair',
Windsurf = 'Windsurf',
Workout = 'Workout',
Yoga = 'Yoga',
}
4 changes: 4 additions & 0 deletions src/enums/activityZoneType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum ActivityZoneType {
Heartrate = 'heartrate',
Power = 'power',
}
5 changes: 5 additions & 0 deletions src/enums/followerStatus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export enum FollowerStatus {
Pending = 'pending',
Accepted = 'accepted',
Blocked = 'blocked',
}
8 changes: 8 additions & 0 deletions src/enums/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export * from './activityType'
export * from './activityZoneType'
export * from './followerStatus'
export * from './resourceState'
export * from './sex'
export * from './sportType'
export * from './streamKeys'
export * from './unitSystem'
5 changes: 5 additions & 0 deletions src/enums/resourceState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export enum ResourceState {
Meta = 1,
Summary = 2,
Detail = 3,
}
4 changes: 4 additions & 0 deletions src/enums/sex.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum Sex {
Female = 'F',
Male = 'M',
}
6 changes: 6 additions & 0 deletions src/enums/sportType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export enum SportType {
Cycling = 'cycling',
Running = 'running',
Triathlon = 'triathlon',
Other = 'other',
}
13 changes: 13 additions & 0 deletions src/enums/streamKeys.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export enum StreamKeys {
Time = 'time',
Distance = 'distance',
LatLng = 'latlng',
Altitude = 'altitude',
VelocitySmooth = 'velocity_smooth',
Heartrate = 'heartrate',
Cadence = 'cadence',
Watts = 'watts',
Temp = 'temp',
Moving = 'moving',
GradeSmooth = 'grade_smooth',
}
4 changes: 4 additions & 0 deletions src/enums/unitSystem.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum UnitSystem {
Feet = 'feet',
Meters = 'meters',
}
13 changes: 13 additions & 0 deletions src/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export class StravaError {
errors: any
message: string
status: number
statusText: string

constructor(error: Response, data: any) {
this.errors = data.errors
this.message = data.message
this.status = error.status
this.statusText = error.statusText
}
}
15 changes: 9 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { OAuth } from './oauth'
import { Request } from './request'
import { Activities } from './resources'
import { Config } from './types'

export default class Strava {
export class Strava {
private readonly request: Request
oauth: OAuth
activities: Activities

constructor(apiKey: string) {
this.request = new Request()
this.oauth = new OAuth(this.request)
constructor(config: Config) {
this.request = new Request(config)
this.activities = new Activities(this.request)
}
}

export default Strava
15 changes: 15 additions & 0 deletions src/models/activityStats.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { ActivityTotal } from '.'

export interface ActivityStats {
biggest_ride_distance: number
biggest_climb_elevation_gain: number
recent_ride_totals: ActivityTotal
recent_run_totals: ActivityTotal
recent_swim_totals: ActivityTotal
ytd_ride_totals: ActivityTotal
ytd_run_totals: ActivityTotal
ytd_swim_totals: ActivityTotal
all_ride_totals: ActivityTotal
all_run_totals: ActivityTotal
all_swim_totals: ActivityTotal
}
8 changes: 8 additions & 0 deletions src/models/activityTotal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export interface ActivityTotal {
count: number
distance: number
moving_time: number
elapsed_time: number
elevation_gain: number
achievement_count: number
}
13 changes: 13 additions & 0 deletions src/models/activityZone.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ActivityZoneType } from '../enums'

import { TimedZoneRange } from '.'

export interface ActivityZone {
score: number
distribution_buckets: TimedZoneRange[]
type: ActivityZoneType
sensor_based: boolean
points: number
custom_zones: boolean
max: number
}
9 changes: 9 additions & 0 deletions src/models/comment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { SummaryAthlete } from '.'

export interface Comment {
id: number
activity_id: number
text: string
athlete: SummaryAthlete
created_at: Date
}
58 changes: 58 additions & 0 deletions src/models/detailedActivity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { ActivityType } from '../enums'

import {
DetailedSegmentEffort,
Lap,
MetaAthlete,
PhotoSummary,
PolylineMap,
Split,
SummaryGear,
} from '.'

export interface DetailedActivity {
id: number
external_id: string
upload_id: number
athlete: MetaAthlete
name: string
distance: number
moving_time: number
elapsed_time: number
total_elevation_gain: number
elev_high: number
elev_low: number
type: ActivityType
start_date: Date
start_date_local: Date
timezone: string
start_latlng: number[]
end_latlng: number[]
achievement_count: number
kudos_count: number
comment_count: number
athlete_count: number
photo_count: number
total_photo_count: number
map: PolylineMap
trainer: boolean
commute: boolean
manual: boolean
private: boolean
flagged: boolean
workout_type: number
average_speed: number
max_speed: number
has_kudoed: boolean
description: string
photos: PhotoSummary
gear: SummaryGear
calories: number
segment_efforts: DetailedSegmentEffort[]
device_name: string
embed_token: string
splits_metric: Split
splits_standard: Split
laps: Lap[]
best_efforts: DetailedSegmentEffort[]
}
31 changes: 31 additions & 0 deletions src/models/detailedAthlete.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { FollowerStatus, ResourceState, UnitSystem } from '../enums'

import { SummaryClub, SummaryGear } from '.'

export interface DetailedAthlete {
id: number
resource_state: ResourceState
firstname: string
lastname: string
profile_medium: string
profile: string
city: string
state: string
country: string
sex: string
friend: FollowerStatus
follower: FollowerStatus
premium: boolean
created_at: Date
updated_at: Date
follower_count: number
friend_count: number
mutual_friend_count: number
measurement_preference: UnitSystem
email: string
ftp: number
weight: number
clubs: SummaryClub
bikes: SummaryGear
shoes: SummaryGear
}
13 changes: 13 additions & 0 deletions src/models/detailedGear.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ResourceState } from '../enums'

export interface DetailedGear {
id: string
resource_state: ResourceState
primary: boolean
name: string
distance: number
brand_name: string
model_name: string
frame_type: number
description: string
}
25 changes: 25 additions & 0 deletions src/models/detailedSegmentEffort.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { MetaActivity, MetaAthlete, SummarySegment } from '.'

export interface DetailedSegmentEffort {
id: number
elapsed_time: number
start_date: Date
start_date_local: Date
distance: number
is_kom: boolean
name: string
activity: MetaActivity
athlete: MetaAthlete
moving_time: number
start_index: number
end_index: number
average_cadence: number
average_watts: number
device_watts: boolean
average_heartrate: number
max_heartrate: number
segment: SummarySegment
kom_rank: number
pr_rank: number
hidden: boolean
}
6 changes: 6 additions & 0 deletions src/models/heartRateZoneRanges.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { ZoneRange } from '.'

export interface HeartRateZoneRanges {
custom_zones: boolean
zones: ZoneRange[]
}
Loading

0 comments on commit af09c56

Please sign in to comment.