openf1-ruby 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 01513030c5ac4786387f7658a656918027433f46406ef3c0d06ee689fd17f160
4
+ data.tar.gz: 0a6a3a51a67cad6eab01b6b4bb55ba2afea72ea963617b80a5a13b8a4bb1bf1d
5
+ SHA512:
6
+ metadata.gz: 935e2fe6be3714e05280c399436903ab45502088dc735c22bf1ea44d6d95148ff1eb811ca3aa1068845b5bf6d3a7fa140fd6783bff1ff2fcfa22ed65cb818698
7
+ data.tar.gz: 7b3a7c1a8fb9c9f129acde474cb895f226939518eba369c9243fba877c5bef8f1faa51f0c49b9412c50ec6715438ca1b43c1644bd87a691af3b542f26fcb138f
data/.rubocop.yml ADDED
@@ -0,0 +1,11 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.1
3
+
4
+ Style/StringLiterals:
5
+ EnforcedStyle: double_quotes
6
+
7
+ Style/StringLiteralsInInterpolation:
8
+ EnforcedStyle: double_quotes
9
+
10
+ Style/Documentation:
11
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # Changelog
2
+
3
+ ## [0.1.0] - 2025-02
4
+
5
+ * Initial release
6
+ * Basic API client implementation
7
+ * Support for all OpenF1 API endpoints
data/README.md ADDED
@@ -0,0 +1,86 @@
1
+ # Openf1::Ruby
2
+
3
+ A simple Ruby client for the [OpenF1 API](https://openf1.org/), providing access to Formula 1 timing data, telemetry, and race information.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem "openf1-ruby"
11
+ ```
12
+
13
+ If bundler is not being used to manage dependencies, install the gem by executing:
14
+
15
+ ```bash
16
+ gem install openf1-ruby
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ### Basic Setup
22
+
23
+ Create a client to interact with the OpenF1 API:
24
+
25
+ ```ruby
26
+ client = Openf1::Client.new
27
+ ```
28
+
29
+ ### Available Endpoints
30
+
31
+ The client provides access to all OpenF1 API endpoints:
32
+
33
+ ```ruby
34
+ client.car_data # Car telemetry data
35
+ client.drivers # Driver information
36
+ client.intervals # Timing intervals
37
+ client.laps # Lap timing data
38
+ client.location # Track location data
39
+ client.meetings # Race meeting information
40
+ client.pit # Pit stop data
41
+ client.position # Car position data
42
+ client.race_control # Race control messages
43
+ client.sessions # Session information
44
+ client.stints # Stint data
45
+ client.team_radio # Team radio messages
46
+ client.weather # Weather data
47
+ ```
48
+
49
+ ### Making Requests
50
+
51
+ All endpoint methods accept optional parameters as a hash:
52
+
53
+ ```ruby
54
+ # Get all drivers
55
+ client.drivers
56
+
57
+ # Get drivers for a specific session
58
+ client.drivers(session_key: "12345")
59
+
60
+ # Get sessions for a specific year
61
+ client.sessions(year: 2024)
62
+
63
+ # Get Sprint Sessions for a specific year
64
+ client.sessions({year: 2024, session_name: "Sprint"})
65
+ ```
66
+
67
+ ### Response Format
68
+
69
+ All responses are returned as OpenStruct objects with data accessible through the `data` attribute:
70
+
71
+ ```ruby
72
+ response = client.drivers
73
+ response.data.each do |driver|
74
+ puts "#{driver.full_name} (#{driver.driver_number})"
75
+ end
76
+ ```
77
+
78
+ ## Development
79
+
80
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
81
+
82
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
83
+
84
+ ## Contributing
85
+
86
+ Bug reports and pull requests are welcome on GitHub at https://github.com/gregdodd/openf1-ruby.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "minitest/test_task"
5
+
6
+ Minitest::TestTask.create
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[test rubocop]
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "faraday"
4
+
5
+ module Openf1
6
+ class Client
7
+ attr_accessor :api_key
8
+
9
+ BASE_URL = "https://api.openf1.org/v1"
10
+
11
+ def initialize(api_key: nil)
12
+ @api_key = api_key
13
+ end
14
+
15
+ def car_data(params = {})
16
+ CarData.new(get_request("car-data", params))
17
+ end
18
+
19
+ def drivers(params = {})
20
+ Drivers.new(get_request("drivers", params))
21
+ end
22
+
23
+ def intervals(params = {})
24
+ Intervals.new(get_request("intervals", params))
25
+ end
26
+
27
+ def laps(params = {})
28
+ Laps.new(get_request("laps", params))
29
+ end
30
+
31
+ def location(params = {})
32
+ Location.new(get_request("location", params))
33
+ end
34
+
35
+ def meetings(params = {})
36
+ Meetings.new(get_request("meetings", params))
37
+ end
38
+
39
+ def pit(params = {})
40
+ Pit.new(get_request("pit", params))
41
+ end
42
+
43
+ def position(params = {})
44
+ Position.new(get_request("position", params))
45
+ end
46
+
47
+ def race_control(params = {})
48
+ RaceControl.new(get_request("race-control", params))
49
+ end
50
+
51
+ def sessions(params = {})
52
+ Sessions.new(get_request("sessions", params))
53
+ end
54
+
55
+ def stints(params = {})
56
+ Stints.new(get_request("stints", params))
57
+ end
58
+
59
+ def team_radio(params = {})
60
+ TeamRadio.new(get_request("team-radio", params))
61
+ end
62
+
63
+ def weather(params = {})
64
+ Weather.new(get_request("weather", params))
65
+ end
66
+
67
+ private
68
+
69
+ def get_request(endpoint, params = {})
70
+ response = connection.get("#{BASE_URL}/#{endpoint}", params)
71
+ JSON.parse(response.body)
72
+ rescue Faraday::Error => e
73
+ raise Openf1::Error, "API request failed: #{e.message}"
74
+ rescue JSON::ParserError => e
75
+ raise Openf1::Error, "Failed to parse API response: #{e.message}"
76
+ end
77
+
78
+ def connection
79
+ @connection ||= Faraday.new(BASE_URL) do |conn|
80
+ conn.headers["Authorization"] = "Bearer #{api_key}" if api_key
81
+ conn.headers["Content-Type"] = "application/json"
82
+ conn.adapter Faraday.default_adapter
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Openf1
4
+ class Error < StandardError; end
5
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "ostruct"
4
+
5
+ module Openf1
6
+ class Object < OpenStruct
7
+ def initialize(attributes)
8
+ raise ArgumentError, "Response cannot be nil" if attributes.nil?
9
+
10
+ # Response is always an array so nest under data:
11
+ super(data: to_ostruct(attributes))
12
+ end
13
+
14
+ def to_ostruct(obj)
15
+ if obj.is_a?(Hash)
16
+ OpenStruct.new(obj.transform_values { |val| to_ostruct(val) })
17
+ elsif obj.is_a?(Array)
18
+ obj.map { |o| to_ostruct(o) }
19
+ else
20
+ obj
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Openf1
4
+ class CarData < Object
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Openf1
4
+ class Drivers < Object
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Openf1
4
+ class Intervals < Object
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Openf1
4
+ class Laps < Object
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Openf1
4
+ class Location < Object
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Openf1
4
+ class Meetings < Object
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Openf1
4
+ class Pit < Object
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Openf1
4
+ class Position < Object
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Openf1
4
+ class RaceControl < Object
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Openf1
4
+ class Sessions < Object
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Openf1
4
+ class Stints < Object
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Openf1
4
+ class TeamRadio < Object
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Openf1
4
+ class Weather < Object
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Openf1
4
+ VERSION = "0.1.0"
5
+ end
data/lib/openf1.rb ADDED
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "openf1/version"
4
+ require_relative "openf1/error"
5
+ require_relative "openf1/client"
6
+
7
+ module Openf1
8
+ autoload :Object, "openf1/object"
9
+ autoload :Sessions, "openf1/objects/sessions"
10
+ autoload :CarData, "openf1/objects/car_data"
11
+ autoload :Drivers, "openf1/objects/drivers"
12
+ autoload :Intervals, "openf1/objects/intervals"
13
+ autoload :Laps, "openf1/objects/laps"
14
+ autoload :Location, "openf1/objects/location"
15
+ autoload :Meetings, "openf1/objects/meetings"
16
+ autoload :Pit, "openf1/objects/pit"
17
+ autoload :Position, "openf1/objects/position"
18
+ autoload :RaceControl, "openf1/objects/race_control"
19
+ autoload :Stints, "openf1/objects/stints"
20
+ autoload :TeamRadio, "openf1/objects/team_radio"
21
+ autoload :Weather, "openf1/objects/weather"
22
+ end
@@ -0,0 +1,6 @@
1
+ module Openf1
2
+ module Ruby
3
+ VERSION: String
4
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: openf1-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Greg Dodd
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 2025-02-22 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: faraday
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '2.0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '2.0'
26
+ description: A Ruby wrapper for the OpenF1 API providing access to Formula 1 timing
27
+ data
28
+ email:
29
+ - greg.dodd@shopify.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".rubocop.yml"
35
+ - CHANGELOG.md
36
+ - README.md
37
+ - Rakefile
38
+ - lib/openf1.rb
39
+ - lib/openf1/client.rb
40
+ - lib/openf1/error.rb
41
+ - lib/openf1/object.rb
42
+ - lib/openf1/objects/car_data.rb
43
+ - lib/openf1/objects/drivers.rb
44
+ - lib/openf1/objects/intervals.rb
45
+ - lib/openf1/objects/laps.rb
46
+ - lib/openf1/objects/location.rb
47
+ - lib/openf1/objects/meetings.rb
48
+ - lib/openf1/objects/pit.rb
49
+ - lib/openf1/objects/position.rb
50
+ - lib/openf1/objects/race_control.rb
51
+ - lib/openf1/objects/sessions.rb
52
+ - lib/openf1/objects/stints.rb
53
+ - lib/openf1/objects/team_radio.rb
54
+ - lib/openf1/objects/weather.rb
55
+ - lib/openf1/version.rb
56
+ - sig/openf1/ruby.rbs
57
+ homepage: https://github.com/gregdodd/openf1-ruby
58
+ licenses:
59
+ - MIT
60
+ metadata:
61
+ homepage_uri: https://github.com/gregdodd/openf1-ruby
62
+ source_code_uri: https://github.com/gregdodd/openf1-ruby
63
+ changelog_uri: https://github.com/gregdodd/openf1-ruby/blob/main/CHANGELOG.md
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: 3.1.0
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubygems_version: 3.6.3
79
+ specification_version: 4
80
+ summary: Ruby client for the OpenF1 API
81
+ test_files: []