4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'app/controllers/terminal_pings_controller.rb', line 4
def create
begin
profile = @terminal.terminal_profile
ping_data = params[:terminal_ping]
remote_timestamp = ping_data[:providers_updated_at].blank? ? nil : DateTime.parse(ping_data[:providers_updated_at])
local_timestamp = nil
profile.cached_providers_lock.lock { local_timestamp = profile.actual_timestamp }
@terminal.ping!(TerminalPing.new ping_data)
response = {
:time => DateTime.now,
:address => @terminal.address,
:profile => {
:support_phone => profile.support_phone,
:logo => profile.logo.url,
:modified_at => profile.updated_at
},
:orders => @terminal.terminal_orders.unsent.as_json(:only => [:id, :keyword, :args, :created_at]),
:update_providers => remote_timestamp.blank? || local_timestamp.to_i > remote_timestamp.to_i, :last_session_started_at => @terminal.last_session_started_at
}
render :json => response
rescue ActiveRecord::RecordInvalid
render :text => nil, :status => 400
end
end
|