Module: Pickpoint
- Defined in:
- lib/pickpoint.rb,
lib/pickpoint/auth.rb,
lib/pickpoint/http.rb,
lib/pickpoint/mint.rb,
lib/pickpoint/client.rb,
lib/pickpoint/config.rb,
lib/pickpoint/errors.rb,
lib/pickpoint/address.rb,
lib/pickpoint/devices.rb,
lib/pickpoint/routing.rb,
lib/pickpoint/version.rb,
lib/pickpoint/geocoding.rb,
lib/pickpoint/transport.rb
Overview
Official Ruby SDK for the Pickpoint public HTTP API.
Defined Under Namespace
Modules: Auth, Transport Classes: APIError, AddressService, AuthError, Client, ClientAuth, Config, ConflictError, Device, DeviceCommandResult, DeviceInput, DeviceListQuery, DeviceListResult, DevicesService, Error, GeocodingService, Http, InvalidConfigError, NotFoundError, RoutingService, TokenPair
Constant Summary collapse
- DEFAULT_BASE_URL =
"https://api.pickpoint.io"- DEFAULT_MAX_RETRIES =
3- DEFAULT_RETRY_BASE =
seconds
1.0- MIN_RETRY_BASE =
0.2- DEFAULT_TIMEOUT =
30.0- MAX_CONCURRENCY =
20- DEFAULT_CONCURRENCY =
20- CLIENT_AUTH_REFRESH_AT =
0.5- VERSION =
File.read(File.("../../VERSION", __dir__)).strip
Class Method Summary collapse
-
.mint_client_tokens(cfg, scopes: nil, ttl_sec: nil) ⇒ Object
Mint a client-token pair with a secret API key (server-side).
Class Method Details
.mint_client_tokens(cfg, scopes: nil, ttl_sec: nil) ⇒ Object
Mint a client-token pair with a secret API key (server-side).
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/pickpoint/mint.rb', line 25 def mint_client_tokens(cfg, scopes: nil, ttl_sec: nil) raise InvalidConfigError, "mint_client_tokens requires api_key" if cfg.api_key.nil? || cfg.api_key.empty? base = Transport.trim_slash(cfg.base_url || DEFAULT_BASE_URL) timeout = cfg.timeout && cfg.timeout.positive? ? cfg.timeout : DEFAULT_TIMEOUT http = Http.new(timeout: timeout, adapter: cfg.http_adapter) payload = { "scopes" => scopes || [] } payload["ttlSec"] = ttl_sec if ttl_sec && ttl_sec.positive? begin status, raw = http.request( "POST", "#{base}/v2/client-tokens", headers: { "Accept" => "application/json", "Content-Type" => "application/json", "x-api-key" => cfg.api_key }, body: JSON.generate(payload) ) rescue StandardError => e raise APIError.new(code: "NETWORK", message: "mint client tokens network error: #{e}") end unless status >= 200 && status < 300 raise APIError.new( status: status, code: "CLIENT_ERROR", message: "mint client tokens failed (#{status})", body: raw ) end TokenPair.from_hash(JSON.parse(raw)) end |