class SBF::Client::UserEndpoint

Public Instance Methods

change_password(profile_id, password) click to toggle source

Changes the password of the user associated with the given profile_id

@raise [SBFClientError]

# File lib/stbaldricks/endpoints/user.rb, line 61
def change_password(profile_id, password)
  raise SBF::Client::Error, 'User not logged in' if SBF::Client::Configuration.user_token.nil?

  response = SBF::Client::Api::Request.post_request(
    "/#{SBF::Client::Api::VERSION}/security/change_password",
    profile_id: profile_id,
    password: password
  )

  unless ok?(response)
    parsed_response = JSON.parse(response.body).symbolize!
    error = SBF::Client::ErrorEntity.new(parsed_response)
  end
  SBF::Client::Configuration.user_token = nil

  SBF::Client::LOG.info { "SBF::Client - Change Password for user with profile_id: #{profile_id}" }
  SBF::Client::Api::Response.new(http_code: response.code, data: nil, error: error)
end
disconnect_facebook(profile_id) click to toggle source

Removes the Facebook user of the given profile_id

@raise [SBFClientError]

# File lib/stbaldricks/endpoints/user.rb, line 83
def disconnect_facebook(profile_id)
  raise SBF::Client::Error, 'User not logged in' if SBF::Client::Configuration.user_token.nil?

  response = SBF::Client::Api::Request.post_request(
    "/#{SBF::Client::Api::VERSION}/user/disconnect_facebook",
    profile_id: profile_id
  )

  SBF::Client::Configuration.user_token = nil

  unless ok?(response)
    parsed_response = JSON.parse(response.body).symbolize!
    error = SBF::Client::ErrorEntity.new(parsed_response)
  end

  SBF::Client::LOG.info { "SBF::Client - Disconnecting Facebook user with profile_id: #{profile_id}" }
  SBF::Client::Api::Response.new(http_code: response.code, data: nil, error: error)
end
list_entities_user_has_permission(permission_id, event_years) click to toggle source

Returns array of entity hash info for the entities logged in user has access to for requested permission.

@raise [SBFClientError]

# File lib/stbaldricks/endpoints/user.rb, line 36
def list_entities_user_has_permission(permission_id, event_years)
  raise SBF::Client::Error, 'User not logged in' if  SBF::Client::Configuration.user_token.nil?

  event_years = [event_years] if event_years.is_a? Integer

  response = SBF::Client::Api::Request.post_request(
    "/#{SBF::Client::Api::VERSION}/security/list_entities_user_has_permission",
    permission_id: permission_id,
    event_years: event_years
  )
  parsed_response = JSON.parse(response.body).symbolize!

  if ok?(response)
    data = parsed_response
  else
    error = SBF::Client::ErrorEntity.new(parsed_response)
  end

  SBF::Client::LOG.info { "SBF::Client - User List Entities User Has Permission: #{permission_id}, #{event_years}, Entities: #{data}" }
  SBF::Client::Api::Response.new(http_code: response.code, data: data, error: error)
end
login!(username, password) click to toggle source

Logs in a user and configures the client library to use user credentials for subsequent requests. Returns the access token for the user that should be held onto to configure the client library in future requests that are outside of this scope.

@param username [string] @param password [string] @return [string]

# File lib/stbaldricks/endpoints/user.rb, line 13
def login!(username, password)
  response = SBF::Client::Api::Request.post_request(
    "/#{SBF::Client::Api::VERSION}/security/login",
    username: username,
    password: password
  )
  parsed_response = JSON.parse(response.body).symbolize!

  if ok?(response)
    SBF::Client::Configuration.user_token = parsed_response[:token]
    data = parsed_response.merge(user: target_class.new(parsed_response[:user]))
  else
    SBF::Client::Configuration.user_token = nil
    error = SBF::Client::ErrorEntity.new(parsed_response)
  end

  SBF::Client::LOG.info { "SBF::Client - User Login: #{username}, Token: #{parsed_response[:token]}" }
  SBF::Client::Api::Response.new(http_code: response.code, data: data, error: error)
end