Class: Samsara::VehiclesClient

Inherits:
Object
  • Object
show all
Defined in:
lib/samsara_api/vehicles/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_client:) ⇒ Samsara::VehiclesClient

Parameters:



44
45
46
47
48
49
# File 'lib/samsara_api/vehicles/client.rb', line 44

def initialize(request_client:)
  @request_client = request_client
  @immobilizer = Samsara::Vehicles::ImmobilizerClient.new(request_client: request_client)
  @locations = Samsara::Vehicles::LocationsClient.new(request_client: request_client)
  @stats = Samsara::Vehicles::StatsClient.new(request_client: request_client)
end

Instance Attribute Details

#immobilizerSamsara::Vehicles::ImmobilizerClient (readonly)



35
36
37
# File 'lib/samsara_api/vehicles/client.rb', line 35

def immobilizer
  @immobilizer
end

#locationsSamsara::Vehicles::LocationsClient (readonly)



37
38
39
# File 'lib/samsara_api/vehicles/client.rb', line 37

def locations
  @locations
end

#request_clientSamsara::RequestClient (readonly)



33
34
35
# File 'lib/samsara_api/vehicles/client.rb', line 33

def request_client
  @request_client
end

#statsSamsara::Vehicles::StatsClient (readonly)



39
40
41
# File 'lib/samsara_api/vehicles/client.rb', line 39

def stats
  @stats
end

Instance Method Details

#get(id:, request_options: nil) ⇒ Object

api.vehicles.get(id: “id”)



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/samsara_api/vehicles/client.rb', line 146

def get(id:, request_options: nil)
  response = @request_client.conn.get do | req |
  unless request_options&.timeout_in_seconds.nil?
req.options.timeout = request_options.timeout_in_seconds
  end
  unless request_options&.token.nil?
req.headers["Authorization"] = request_options.token
  end
  req.headers = { **(req.headers || {}), **@request_client.get_headers, **(request_options&.additional_headers || {}) }.compact
  unless request_options.nil? || request_options&.additional_query_parameters.nil?
req.params = { **(request_options&.additional_query_parameters || {}) }.compact
  end
  unless request_options.nil? || request_options&.additional_body_parameters.nil?
req.body = { **(request_options&.additional_body_parameters || {}) }.compact
  end
  req.url "#{@request_client.get_url(request_options: request_options)}/fleet/vehicles/#{id}"
end
  Samsara::Types::VehicleResponse.from_json(json_object: response.body)
end

#list(limit: nil, after: nil, parent_tag_ids: nil, tag_ids: nil, attribute_value_ids: nil, attributes: nil, updated_after_time: nil, created_after_time: nil, request_options: nil) ⇒ Object

api.vehicles.list



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/samsara_api/vehicles/client.rb', line 101

def list(limit: nil, after: nil, parent_tag_ids: nil, tag_ids: nil, attribute_value_ids: nil, attributes: nil, updated_after_time: nil, created_after_time: nil, request_options: nil)
  response = @request_client.conn.get do | req |
  unless request_options&.timeout_in_seconds.nil?
req.options.timeout = request_options.timeout_in_seconds
  end
  unless request_options&.token.nil?
req.headers["Authorization"] = request_options.token
  end
  req.headers = { **(req.headers || {}), **@request_client.get_headers, **(request_options&.additional_headers || {}) }.compact
  req.params = { **(request_options&.additional_query_parameters || {}), "limit": limit, "after": after, "parentTagIds": parent_tag_ids, "tagIds": tag_ids, "attributeValueIds": attribute_value_ids, "attributes": attributes, "updatedAfterTime": updated_after_time, "createdAfterTime": created_after_time }.compact
  unless request_options.nil? || request_options&.additional_body_parameters.nil?
req.body = { **(request_options&.additional_body_parameters || {}) }.compact
  end
  req.url "#{@request_client.get_url(request_options: request_options)}/fleet/vehicles"
end
  Samsara::Types::VehiclesListVehiclesResponseBody.from_json(json_object: response.body)
end

#update(id:, attributes: nil, aux_input_type_1: nil, aux_input_type_10: nil, aux_input_type_11: nil, aux_input_type_12: nil, aux_input_type_13: nil, aux_input_type_2: nil, aux_input_type_3: nil, aux_input_type_4: nil, aux_input_type_5: nil, aux_input_type_6: nil, aux_input_type_7: nil, aux_input_type_8: nil, aux_input_type_9: nil, engine_hours: nil, external_ids: nil, gateway_serial: nil, gross_vehicle_weight: nil, harsh_acceleration_setting_type: nil, license_plate: nil, name: nil, notes: nil, odometer_meters: nil, static_assigned_driver_id: nil, tag_ids: nil, vehicle_regulation_mode: nil, vehicle_type: nil, vin: nil, request_options: nil) ⇒ Object

api.vehicles.update(id: “id”)



403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
# File 'lib/samsara_api/vehicles/client.rb', line 403

def update(id:, attributes: nil, aux_input_type_1: nil, aux_input_type_10: nil, aux_input_type_11: nil, aux_input_type_12: nil, aux_input_type_13: nil, aux_input_type_2: nil, aux_input_type_3: nil, aux_input_type_4: nil, aux_input_type_5: nil, aux_input_type_6: nil, aux_input_type_7: nil, aux_input_type_8: nil, aux_input_type_9: nil, engine_hours: nil, external_ids: nil, gateway_serial: nil, gross_vehicle_weight: nil, harsh_acceleration_setting_type: nil, license_plate: nil, name: nil, notes: nil, odometer_meters: nil, static_assigned_driver_id: nil, tag_ids: nil, vehicle_regulation_mode: nil, vehicle_type: nil, vin: nil, request_options: nil)
  response = @request_client.conn.patch do | req |
  unless request_options&.timeout_in_seconds.nil?
req.options.timeout = request_options.timeout_in_seconds
  end
  unless request_options&.token.nil?
req.headers["Authorization"] = request_options.token
  end
  req.headers = { **(req.headers || {}), **@request_client.get_headers, **(request_options&.additional_headers || {}) }.compact
  unless request_options.nil? || request_options&.additional_query_parameters.nil?
req.params = { **(request_options&.additional_query_parameters || {}) }.compact
  end
  req.body = { **(request_options&.additional_body_parameters || {}), attributes: attributes, auxInputType1: aux_input_type_1, auxInputType10: aux_input_type_10, auxInputType11: aux_input_type_11, auxInputType12: aux_input_type_12, auxInputType13: aux_input_type_13, auxInputType2: aux_input_type_2, auxInputType3: aux_input_type_3, auxInputType4: aux_input_type_4, auxInputType5: aux_input_type_5, auxInputType6: aux_input_type_6, auxInputType7: aux_input_type_7, auxInputType8: aux_input_type_8, auxInputType9: aux_input_type_9, engineHours: engine_hours, externalIds: external_ids, gatewaySerial: gateway_serial, grossVehicleWeight: gross_vehicle_weight, harshAccelerationSettingType: harsh_acceleration_setting_type, licensePlate: license_plate, name: name, notes: notes, odometerMeters: odometer_meters, staticAssignedDriverId: static_assigned_driver_id, tagIds: tag_ids, vehicleRegulationMode: vehicle_regulation_mode, vehicleType: vehicle_type, vin: vin }.compact
  req.url "#{@request_client.get_url(request_options: request_options)}/fleet/vehicles/#{id}"
end
  Samsara::Types::VehicleResponse.from_json(json_object: response.body)
end