Skip to content

Commit

Permalink
location at root of device response
Browse files Browse the repository at this point in the history
  • Loading branch information
timcowlishaw committed Feb 26, 2024
1 parent 4dcf3c2 commit 9b5dfed
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
25 changes: 14 additions & 11 deletions app/models/device.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,19 +187,22 @@ def soft_state
end
end

def formatted_location
{
ip: nil,
exposure: exposure,
elevation: elevation.try(:to_i) ,
latitude: latitude,
longitude: longitude,
geohash: geohash,
city: city,
country_code: country_code,
country: country_name
}
end

def formatted_data
s = {
location: {
ip: nil,
exposure: exposure,
elevation: elevation.try(:to_i) ,
latitude: latitude,
longitude: longitude,
geohash: geohash,
city: city,
country_code: country_code,
country: country_name
},
sensors: []
}

Expand Down
1 change: 1 addition & 0 deletions app/views/v0/devices/_device.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ else
json.merge! device_token: '[FILTERED]'
end

json.merge!(location: device.formatted_location)
json.merge!(hardware: device.hardware(authorized))

if with_owner && device.owner
Expand Down
2 changes: 1 addition & 1 deletion spec/requests/v0/devices_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
expect(json.length).to eq(2)
# expect(json[0]['name']).to eq(first.name)
# expect(json[1]['name']).to eq(second.name)
expect(json[0].keys).to eq(%w(id uuid name description state postprocessing system_tags user_tags is_private notify_low_battery notify_stopped_publishing last_reading_at created_at updated_at device_token hardware owner data))
expect(json[0].keys).to eq(%w(id uuid name description state postprocessing system_tags user_tags is_private notify_low_battery notify_stopped_publishing last_reading_at created_at updated_at device_token location hardware owner data))
end

describe "when not logged in" do
Expand Down

0 comments on commit 9b5dfed

Please sign in to comment.