Class: Spotify::API::User

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

Constant Summary collapse

USERS_URL =

API endpoint for users.

"#{BASE_URL}users"

Constants inherited from Base

Base::BASE_URL, Base::FROM_TOKEN, Base::MAX_RETRIES, Base::SEARCH_URL

Instance Attribute Summary

Attributes inherited from Base

#params, #request, #response, #retries, #timeout, #url

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#define_response, #get, #initialize, #make_request, #prepare_request, #run_with_timeout, #set_response

Constructor Details

This class inherits a constructor from Spotify::API::Base

Class Method Details

.search_by_id(args = {}) ⇒ Public::User

Gets an user.

Parameters:

  • args (Hash) (defaults to: {})

    the search arguments.

  • [Fixnum] (Hash)

    a customizable set of options

Returns:

  • (Public::User)

    the extracted user.



20
21
22
23
24
25
# File 'lib/spotify/api/user.rb', line 20

def self.search_by_id(args = {})
  service_params = args.slice(:timeout, :retries)
  args           = args.slice(:id)

  self.new(service_params).search_by_id(args)
end

Instance Method Details

#bodyHash

Parses the response to JSON to get more flexible.

Returns:

  • (Hash)

    the parsed response.



49
50
51
52
53
# File 'lib/spotify/api/user.rb', line 49

def body
  @response = JSON.parse(response)
rescue
  Spotify::Models::Error.parser_error
end

#search_by_id(args = {}) ⇒ Public::User

Gets a track.

Parameters:

  • args (Hash) (defaults to: {})

    the search arguments.

  • [String] (Hash)

    a customizable set of options

Returns:

  • (Public::User)

    the extracted user.



36
37
38
39
40
41
42
# File 'lib/spotify/api/user.rb', line 36

def search_by_id(args = {})
  get(USERS_URL + '/' + args[:id].to_s)

  define_response do
    Spotify::Models::Simplified::User.new(response)
  end
end