class GeostellarClient::User

Public Class Methods

create(attrs) click to toggle source
# File lib/geostellar_client/user.rb, line 26
def self.create(attrs)
  valid_attrs = User.new(attrs).attributes.reject { |k, v| v.nil? }
  options = {
    api_key: GeostellarClient.api_key,
    body: { user: valid_attrs },
  }

  response = HTTParty.post(api_url, options)

  if response.success?
    new(response.parsed_response)
  else
    message = response["errors"].join(', ')
    raise GeostellarClient::UserCreationError, message
  end
end
find(id) click to toggle source
# File lib/geostellar_client/user.rb, line 18
def self.find(id)
  response = HTTParty.get(
    find_url(id),
    { api_key: GeostellarClient.api_key }
  )
  new(JSON.parse(response.body))
end

Private Class Methods

api_url() click to toggle source
# File lib/geostellar_client/user.rb, line 49
def self.api_url
  "#{GeostellarClient::BASE_API_URL}users"
end
find_url(id) click to toggle source
# File lib/geostellar_client/user.rb, line 45
def self.find_url(id)
  "#{api_url}/#{id}"
end