Skip to content

Commit

Permalink
Disable measurements for multiple session's endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
czorek committed Jul 6, 2017
1 parent 792413c commit a7deb09
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 28 deletions.
2 changes: 1 addition & 1 deletion app/controllers/api/measurement_sessions_controller.rb
Expand Up @@ -69,7 +69,7 @@ def create
def show
session = MobileSession.find(params[:id])

respond_with session, :sensor_id => params[:sensor_id], :methods => [:measurements, :notes]
respond_with session, :sensor_id => params[:sensor_id], :methods => [:notes], :stream_measurements => true
end

def export
Expand Down
11 changes: 0 additions & 11 deletions app/models/fixed_session.rb
Expand Up @@ -69,18 +69,7 @@ def as_json(opts=nil)

methods = opts[:methods] || [:notes, :calibration]
methods << :type
sensor_id = opts.delete(:sensor_id)

res = super(opts.merge(methods: methods))

map_of_streams = {}
strs = sensor_id ? streams.where(sensor_name: sensor_id) : streams.all
strs.each do |stream|
map_of_streams[stream.sensor_name] = stream.as_json
end

res.merge!(streams: map_of_streams)

res
end
end
5 changes: 3 additions & 2 deletions app/models/session.rb
Expand Up @@ -213,9 +213,10 @@ def as_json(opts=nil)

map_of_streams = {}
strs = sensor_id ? streams.where(sensor_name: sensor_id) : streams.all

strs.each do |stream|
if with_measurements
map_of_streams[stream.sensor_name] = stream.as_json(:methods => [:measurements])
if opts[:stream_measurements]
map_of_streams[stream.sensor_name] = stream.as_json(methods: [:measurements])
else
map_of_streams[stream.sensor_name] = stream.as_json
end
Expand Down
17 changes: 3 additions & 14 deletions doc/api.md
Expand Up @@ -4,6 +4,9 @@ Every response is returned in JSON format.

## GET /api/sessions

**Remember:** this call will not return measurements data for requested sessions. To do that, use the single session
endpoint below, i.e. `/api/sessions/:id`

### Parameters

| name | type | default value |
Expand All @@ -26,7 +29,6 @@ Every response is returned in JSON format.
| q[west] | number, -180..180 | |
| q[north] | number, -90..90 | |
| q[south] | number, -90..90 | |
| q[measurements]| true,false | false |

### Example URL

Expand Down Expand Up @@ -65,19 +67,6 @@ curl http://aircasting.org/api/sessions.json?page=0&page_size=50&q[measurements]
"threshold_very_low": 0,
"unit_name": "micrograms per cubic meter",
"unit_symbol": "µg/m³",
"measurements": [
{
"id": 56292378,
"latitude": "39.68352651",
"longitude": "-104.89157664",
"measured_value": 2.69,
"milliseconds": 31,
"stream_id": 26343,
"time": "2015-09-09T17:19:18Z",
"timezone_offset": 0,
"value": 2.69
}
],
"size": 1814
}
}
Expand Down

0 comments on commit a7deb09

Please sign in to comment.