Backend Integration - Ruby / Sinatra
Sinatra keeps the proxy thin and explicit - each route is one function that delegates to PickPoint. Uses only standard library HTTP to keep dependencies minimal.
1
Install gems
gem install sinatra puma net-http dotenv2
Geocoding endpoints
# .env
PICKPOINT_KEY=your_key_here# app.rb
require 'sinatra'
require 'net/http'
require 'json'
require 'dotenv/load'
KEY = ENV.fetch('PICKPOINT_KEY')
BASE = URI('https://api.pickpoint.io/v2')
def pickpoint(path, params: {})
uri = URI.join(BASE.to_s + '/', path)
uri.query = URI.encode_www_form(params.compact) unless params.empty?
req = Net::HTTP::Get.new(uri)
req['X-Api-Key'] = KEY
Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(req) }
end
def pickpoint_post(path, body)
uri = URI.join(BASE.to_s + '/', path)
req = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json', 'X-Api-Key' => KEY)
req.body = body.to_json
Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(req) }
end
# ── Geocoding ─────────────────────────────────────────────────────────────
get '/geo/forward' do
content_type :json
r = pickpoint('geocode/forward', params: {
q: params[:q], limit: params[:limit], countrycodes: params[:countrycodes],
viewbox: params[:viewbox], language: params[:language]
})
status r.code.to_i; r.body
end
get '/geo/reverse' do
content_type :json
r = pickpoint('geocode/reverse', params: {
lat: params[:lat], lon: params[:lon], zoom: params[:zoom]
})
status r.code.to_i; r.body
end
get '/geo/search' do
content_type :json
r = pickpoint('address/search', params: {
q: params[:q], limit: params[:limit], viewbox: params[:viewbox]
})
status r.code.to_i; r.body
end3
Routing endpoints
# ── Routing ───────────────────────────────────────────────────────────────
post '/route' do
content_type :json
body = JSON.parse(request.body.read)
r = pickpoint_post('route', body)
status r.code.to_i; r.body
end
post '/route/optimized' do
content_type :json
body = JSON.parse(request.body.read)
r = pickpoint_post('route/optimized', body)
status r.code.to_i; r.body
end4
Device tracking - REST
# ── Device Tracking - REST ────────────────────────────────────────────────
get '/devices' do
content_type :json
r = pickpoint('devices')
status r.code.to_i; r.body
end
get '/devices/:uid/tracks' do |uid|
content_type :json
r = pickpoint("devices/#{uid}/tracks", params: {
from: params[:from], to: params[:to]
})
status r.code.to_i; r.body
endRun with bundle exec ruby app.rb. For the WebSocket subscriber relay, use the websocket-driver gem or integrate with Action Cable in Rails.