Class: CommaAPI::API
- Inherits:
-
Object
- Object
- CommaAPI::API
- Defined in:
- lib/comma_api.rb
Constant Summary
Constants included from Config
Config::API_HOST, Config::DONGLE_ID_DEFAULT
Class Method Summary collapse
- .args ⇒ Object
- .defaultArgs ⇒ Object
- .device(id:) ⇒ Object
-
.device404Error ⇒ Object
errors.
- .deviceDefault ⇒ Object
- .deviceDefaultLocation ⇒ Object
- .deviceDefaultSegments ⇒ Object
- .deviceDefaultStats ⇒ Object
- .deviceLocation(id:) ⇒ Object
-
.devices ⇒ Object
devices.
- .deviceSegments(id:) ⇒ Object
- .devicesStat(id:) ⇒ Object
- .deviceStats(id:) ⇒ Object
- .deviceStatsId(id:) ⇒ Object
-
.get(method_name) ⇒ Object
helper.
-
.me ⇒ Object
user.
- .opAuth ⇒ Object
-
.route(route_name:) ⇒ Object
routes.
- .routeFiles(route_name:) ⇒ Object
-
.segments ⇒ Object
segments.
Methods included from HTTP
Class Method Details
.args ⇒ Object
87 88 89 |
# File 'lib/comma_api.rb', line 87 def args defaultArgs # alias (alias :args :defaultArgs) end |
.defaultArgs ⇒ Object
91 92 93 94 |
# File 'lib/comma_api.rb', line 91 def defaultArgs one_week = 604800 "?from=#{(Time.now - one_week - 1).to_i}" end |
.device(id:) ⇒ Object
21 22 23 |
# File 'lib/comma_api.rb', line 21 def device(id:) get "/v1.1/devices/#{id}/" end |
.device404Error ⇒ Object
errors
114 115 116 |
# File 'lib/comma_api.rb', line 114 def device404Error { error: 'Error: DONGLE_ID_DEFAULT is missing - this method cannot be executed, you need to specify a dongle id' }.to_json end |
.deviceDefault ⇒ Object
34 35 36 37 |
# File 'lib/comma_api.rb', line 34 def deviceDefault return device404Error unless DONGLE_ID_DEFAULT device id: DONGLE_ID_DEFAULT end |
.deviceDefaultLocation ⇒ Object
29 30 31 32 |
# File 'lib/comma_api.rb', line 29 def deviceDefaultLocation return device404Error unless DONGLE_ID_DEFAULT deviceLocation id: DONGLE_ID_DEFAULT end |
.deviceDefaultSegments ⇒ Object
82 83 84 85 |
# File 'lib/comma_api.rb', line 82 def deviceDefaultSegments return device404Error unless DONGLE_ID_DEFAULT deviceSegments id: DONGLE_ID_DEFAULT end |
.deviceDefaultStats ⇒ Object
39 40 41 42 |
# File 'lib/comma_api.rb', line 39 def deviceDefaultStats return device404Error unless DONGLE_ID_DEFAULT deviceStats id: DONGLE_ID_DEFAULT end |
.deviceLocation(id:) ⇒ Object
25 26 27 |
# File 'lib/comma_api.rb', line 25 def deviceLocation(id:) get "/v1/devices/#{id}/location" end |
.devices ⇒ Object
devices
17 18 19 |
# File 'lib/comma_api.rb', line 17 def devices get "/v1/me/devices/" end |
.deviceSegments(id:) ⇒ Object
77 78 79 80 |
# File 'lib/comma_api.rb', line 77 def deviceSegments(id:) return device404Error unless DONGLE_ID_DEFAULT get "/v1/devices/#{id}/segments#{args}" end |
.devicesStat(id:) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/comma_api.rb', line 48 def devicesStat(id:) devices = get "/v1/devices" # TODO: loop through all devices, return all stats and a total devices.map { |device| get "/v1/devices/#{device.f("dongle_id")}/stats#{args}" } end |
.deviceStats(id:) ⇒ Object
44 45 46 |
# File 'lib/comma_api.rb', line 44 def deviceStats(id:) get "/v1/devices/#{id}/stats" end |
.deviceStatsId(id:) ⇒ Object
56 57 58 |
# File 'lib/comma_api.rb', line 56 def deviceStatsId(id:) get "/v1/devices/#{id}/stats#{args}" end |
.get(method_name) ⇒ Object
helper
103 104 105 106 107 108 109 |
# File 'lib/comma_api.rb', line 103 def get(method_name) # note: trailing slash gets added here puts "requesting: #{method_name}" url = "#{API_HOST}#{method_name}" puts url request url: url end |
.me ⇒ Object
user
11 12 13 |
# File 'lib/comma_api.rb', line 11 def me get "/v1/me/" end |
.opAuth ⇒ Object
96 97 98 |
# File 'lib/comma_api.rb', line 96 def opAuth "https://api.commadotai.com/v2/pilotauth/" end |
.route(route_name:) ⇒ Object
routes
62 63 64 |
# File 'lib/comma_api.rb', line 62 def route(route_name:) get "/v1/route/#{route_name}/" end |
.routeFiles(route_name:) ⇒ Object
66 67 68 |
# File 'lib/comma_api.rb', line 66 def routeFiles(route_name:) get "/v1/route/#{route_name}/files" end |
.segments ⇒ Object
segments
72 73 74 75 |
# File 'lib/comma_api.rb', line 72 def segments return device404Error unless DONGLE_ID_DEFAULT get "/v1/devices/#{DONGLE_ID_DEFAULT}/segments#{args}" end |