class Tidepool::Client

Attributes

headers[R]

Public Class Methods

login(username:, password:) click to toggle source
# File lib/tidepool/client.rb, line 5
def self.login(username:, password:)
  auth = { username: username, password: password }
  response = self.post("/auth/login", basic_auth: auth)
  if response.success?
    response
  else
    message = ErrorMessage.new(response).message
    raise HTTPError.new(response.code, message)
  end
end
new(session_token:) click to toggle source
# File lib/tidepool/client.rb, line 16
def initialize(session_token:)
  @headers = {
    "Content-Type": "application/json",
    "x-tidepool-session-token": session_token
  }
end

Public Instance Methods

data(user_id:, options: {}) click to toggle source
# File lib/tidepool/client.rb, line 27
def data(user_id:, options: {})
  get("/data/#{user_id}", options)
end
notes(user_id:, options: {}) click to toggle source
# File lib/tidepool/client.rb, line 31
def notes(user_id:, options: {})
  response = get("/message/notes/#{user_id}", options)
  response["messages"]
end
users(user_id:) click to toggle source
# File lib/tidepool/client.rb, line 23
def users(user_id:)
  get("/metadata/users/#{user_id}/users")
end

Private Instance Methods

get(url, options = {}) click to toggle source
# File lib/tidepool/client.rb, line 44
def get(url, options = {})
  options.merge!(headers: headers)
  response = self.class.get(url, options)
  if response.success?
    response
  else
    message = ErrorMessage.new(response).message
    raise HTTPError.new(response.code, message)
  end
end