Class: Openlive::User

Inherits:
Base
  • Object
show all
Defined in:
lib/openlive/user.rb

Instance Attribute Summary

Attributes inherited from Base

#api_data, #response

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

connection, #connection, handle_response, #initialize, #method_missing, #oauth, oauth, #refresh

Constructor Details

This class inherits a constructor from Openlive::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Openlive::Base

Class Method Details

.create(attributes) ⇒ User

Create a new user on Openlive

Parameters:

  • attributes (Hash)

    A hash of attributes to set

Options Hash (attributes):

  • :username (String)
  • :email (String)
  • :password (String)

    Optional, will be automatically generated

Returns:

  • (User)

    the created user object

Raises:

  • (APIError)

    Will raise an error on unsuccessful response



53
54
55
56
57
58
59
# File 'lib/openlive/user.rb', line 53

def create(attributes)
  response = Request.post("users", attributes)

  handle_response(response, error_class: APIError) do |response|
    new(response.body, response: response)
  end
end

.find(id) ⇒ User

Find and return a user record

Parameters:

  • id (String)

Returns:

Raises:

  • (APIError)

    Will raise an error on unsuccessful response



24
25
26
27
28
29
30
# File 'lib/openlive/user.rb', line 24

def find(id)
  response = Request.get("users/#{id}")

  handle_response(response, error_class: APIError) do |response|
    new(response.body, response: response)
  end
end

.find_by_email(email) ⇒ User

Find and return a user by email address

Parameters:

  • email (String)

Returns:

Raises:

  • (APIError)

    Will raise an error on unsuccessful response



37
38
39
40
41
42
43
# File 'lib/openlive/user.rb', line 37

def find_by_email(email)
  response = Request.get("users", email: email)

  handle_response(response, error_class: APIError) do |response|
    new(response.body, response: response)
  end
end

Instance Method Details

#artistsArray<Openlive::Artist>

Convenience method for returning artists associated with user

Returns:



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/openlive/user.rb', line 6

def artists
  unless api_data['artists'].nil?
    if api_data['artists'].empty?
      []
    else
      @artists ||= api_data['artists'].map do |attributes|
        Artist.new(attributes)
      end
    end
  end
end