Before I start the “proper solution,” it would be nice to check if this makes sense. For this purpose, I would write a small, rudimentary application that checks only a few things.
The goal is to sync expected data from Strava and display it in a proper way. The application should be able to run locally and show data only related to me.
If the proof of concept works, then I will start everything from scratch.
For a PoC, it does not make sense to use a database. Instead, I am going to start with a simple JSON file containing the necessary data.
[
{
"name": "Canondale Topstone",
"started_at": "09.03.2023"
},
{
"name": "Pedals - Shimano PD-M540",
"started_at": "09.05.2023"
},
{
"name": "Chain #2 - KMC X10",
"started_at": "16.05.2023"
},
{
"name": "Shimano PD-M540",
"started_at": "09.05.2023"
},
{
"name": "Shimano PD-M540",
"started_at": "09.05.2023"
},
{
"name": "Chain #1 - KMC X10",
"started_at": "09.03.2023",
"finished_at": "16.05.2023"
}
]
I will provide more details in the next episodes. However, at the moment, I need an endpoint to serve the frontend.
get "/" do
send_file File.join("frontend", "index.html")
end
get details about bike and component with distance from strava
get "/activites" do
file_path = "bike_data.json"
file = File.read(file_path)
data = JSON.parse(file)
status 200
content_type "application/json"
transformed_data = transform_data(data)
JSON.generate(transformed_data)
end
I need authorise strava
get "/authorise" do
client = ::Strava::OAuth::Client.new(
client_id: ENV["STRAVA_CLIENT_ID"],
client_secret: ENV["STRAVA_CLIENT_SECRET"]
)
redirect_url = client.authorize_url(
redirect_uri: ENV["STRAVA_REDIRECT_URI"],
approval_prompt: "force",
response_type: "code",
scope: "activity:read_all",
state: "magic"
)
redirect redirect_url
end
and prepare endpoint for callback
get "/authorise" do
client = ::Strava::OAuth::Client.new(
client_id: ENV["STRAVA_CLIENT_ID"],
client_secret: ENV["STRAVA_CLIENT_SECRET"]
)
redirect_url = client.authorize_url(
redirect_uri: ENV["STRAVA_REDIRECT_URI"],
approval_prompt: "force",
response_type: "code",
scope: "activity:read_all",
state: "magic"
)
redirect redirect_url
end
As I don’t have a database, tokens are also stored in the file.
The whole file looks like that (https://github.com/tobiaszwaszak/track-gear/blob/fe1853b7b30e357c2097c697ce048d9d49ed295f/app.rb)
For frontend purposes, I created another file (https://github.com/tobiaszwaszak/track-gear/blob/fe1853b7b30e357c2097c697ce048d9d49ed295f/frontend/index.html)
Next steps
It looks like my local PoC works. And I’m able to continue. The whole commit is there (https://github.com/tobiaszwaszak/track-gear/commit/fe1853b7b30e357c2097c697ce048d9d49ed295f)
I am open to feedback and welcome any questions you may have. My email is listed on this website.