class SPOT::ApiService

Attributes

feed_id[R]
feed_password[R]

Public Class Methods

new(feed_id:, feed_password: nil) click to toggle source
# File lib/spot-gps/api_service.rb, line 6
def initialize(feed_id:, feed_password: nil)
  @feed_id = feed_id
  @feed_password = feed_password

  connection_options = {
    request: {
      timeout: SPOT.read_timeout,
      open_timeout: SPOT.open_timeout
    }
  }

  @connection = Faraday.new(base_uri, connection_options)
end

Public Instance Methods

get(path:, params: {}) click to toggle source

Make a GET request to the SPOT API

# File lib/spot-gps/api_service.rb, line 21
def get(path:, params: {})
  params ||= {}

  if feed_password && !feed_password.empty?
    params = params.merge(feedPassword: feed_password)
  end

  response = make_request(:get, path, params)

  SPOT::ApiResponse.new(response)
end

Private Instance Methods

base_uri() click to toggle source
# File lib/spot-gps/api_service.rb, line 46
def base_uri
  URI.join(SPOT.endpoint, feed_id + '/')
end
headers() click to toggle source
# File lib/spot-gps/api_service.rb, line 50
def headers
  { 'Accept' => "application/json" }
end
make_request(method, path, params = {}) click to toggle source
# File lib/spot-gps/api_service.rb, line 37
def make_request(method, path, params = {})
  @connection.send(method.to_sym) do |request|
    request.url path
    request.body = @request_body
    request.params = params
    request.headers = headers
  end
end