Class: Rocksky::Client
- Inherits:
-
Object
- Object
- Rocksky::Client
- Defined in:
- lib/rocksky/client.rb
Overview
Constant Summary collapse
- DEFAULT_BASE_URL =
"https://api.rocksky.app".freeze
Instance Attribute Summary collapse
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#open_timeout ⇒ Object
readonly
Returns the value of attribute open_timeout.
-
#read_timeout ⇒ Object
readonly
Returns the value of attribute read_timeout.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
-
#user_agent ⇒ Object
readonly
Returns the value of attribute user_agent.
Instance Method Summary collapse
-
#actor ⇒ Object
—- Resource accessors ————————————————.
- #album ⇒ Object
- #apikey ⇒ Object
- #artist ⇒ Object
- #charts ⇒ Object
- #feed ⇒ Object
- #graph ⇒ Object
-
#initialize(base_url: nil, token: nil, headers: {}, user_agent: "rocksky-ruby/#{Rocksky::VERSION}", open_timeout: HTTP::DEFAULT_OPEN_TIMEOUT, read_timeout: HTTP::DEFAULT_READ_TIMEOUT) ⇒ Client
constructor
A new instance of Client.
- #inspect ⇒ Object
- #like ⇒ Object
- #mirror ⇒ Object
- #player ⇒ Object
- #playlist ⇒ Object
- #procedure(nsid, params: {}, body: nil) ⇒ Object
-
#query(nsid, **params) ⇒ Object
—- Raw XRPC access —————————————————.
- #scrobble ⇒ Object
- #shout ⇒ Object
- #song ⇒ Object
- #spotify ⇒ Object
- #stats ⇒ Object
-
#with_token(new_token) ⇒ Object
Return a derived client that uses the given token (everything else copied).
Constructor Details
#initialize(base_url: nil, token: nil, headers: {}, user_agent: "rocksky-ruby/#{Rocksky::VERSION}", open_timeout: HTTP::DEFAULT_OPEN_TIMEOUT, read_timeout: HTTP::DEFAULT_READ_TIMEOUT) ⇒ Client
Returns a new instance of Client.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/rocksky/client.rb', line 15 def initialize( base_url: nil, token: nil, headers: {}, user_agent: "rocksky-ruby/#{Rocksky::VERSION}", open_timeout: HTTP::DEFAULT_OPEN_TIMEOUT, read_timeout: HTTP::DEFAULT_READ_TIMEOUT ) @base_url = normalize_base_url(base_url || ENV["ROCKSKY_BASE_URL"] || DEFAULT_BASE_URL) @token = token || ENV["ROCKSKY_TOKEN"] @headers = headers.dup @user_agent = user_agent @open_timeout = open_timeout @read_timeout = read_timeout @http = HTTP.new(self) end |
Instance Attribute Details
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
12 13 14 |
# File 'lib/rocksky/client.rb', line 12 def base_url @base_url end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
12 13 14 |
# File 'lib/rocksky/client.rb', line 12 def headers @headers end |
#open_timeout ⇒ Object (readonly)
Returns the value of attribute open_timeout.
12 13 14 |
# File 'lib/rocksky/client.rb', line 12 def open_timeout @open_timeout end |
#read_timeout ⇒ Object (readonly)
Returns the value of attribute read_timeout.
12 13 14 |
# File 'lib/rocksky/client.rb', line 12 def read_timeout @read_timeout end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
12 13 14 |
# File 'lib/rocksky/client.rb', line 12 def token @token end |
#user_agent ⇒ Object (readonly)
Returns the value of attribute user_agent.
12 13 14 |
# File 'lib/rocksky/client.rb', line 12 def user_agent @user_agent end |
Instance Method Details
#actor ⇒ Object
—- Resource accessors ————————————————
57 |
# File 'lib/rocksky/client.rb', line 57 def actor; @actor ||= Resources::Actor.new(@http); end |
#album ⇒ Object
58 |
# File 'lib/rocksky/client.rb', line 58 def album; @album ||= Resources::Album.new(@http); end |
#apikey ⇒ Object
59 |
# File 'lib/rocksky/client.rb', line 59 def apikey; @apikey ||= Resources::Apikey.new(@http); end |
#artist ⇒ Object
60 |
# File 'lib/rocksky/client.rb', line 60 def artist; @artist ||= Resources::Artist.new(@http); end |
#charts ⇒ Object
61 |
# File 'lib/rocksky/client.rb', line 61 def charts; @charts ||= Resources::Charts.new(@http); end |
#feed ⇒ Object
62 |
# File 'lib/rocksky/client.rb', line 62 def feed; @feed ||= Resources::Feed.new(@http); end |
#graph ⇒ Object
63 |
# File 'lib/rocksky/client.rb', line 63 def graph; @graph ||= Resources::Graph.new(@http); end |
#inspect ⇒ Object
74 75 76 |
# File 'lib/rocksky/client.rb', line 74 def inspect "#<Rocksky::Client base_url=#{base_url.inspect} token=#{token ? "[FILTERED]" : nil.inspect}>" end |
#like ⇒ Object
64 |
# File 'lib/rocksky/client.rb', line 64 def like; @like ||= Resources::Like.new(@http); end |
#mirror ⇒ Object
65 |
# File 'lib/rocksky/client.rb', line 65 def mirror; @mirror ||= Resources::Mirror.new(@http); end |
#player ⇒ Object
66 |
# File 'lib/rocksky/client.rb', line 66 def player; @player ||= Resources::Player.new(@http); end |
#playlist ⇒ Object
67 |
# File 'lib/rocksky/client.rb', line 67 def playlist; @playlist ||= Resources::Playlist.new(@http); end |
#procedure(nsid, params: {}, body: nil) ⇒ Object
51 52 53 |
# File 'lib/rocksky/client.rb', line 51 def procedure(nsid, params: {}, body: nil) @http.procedure(nsid, params, body) end |
#query(nsid, **params) ⇒ Object
—- Raw XRPC access —————————————————
47 48 49 |
# File 'lib/rocksky/client.rb', line 47 def query(nsid, **params) @http.query(nsid, params) end |
#scrobble ⇒ Object
68 |
# File 'lib/rocksky/client.rb', line 68 def scrobble; @scrobble ||= Resources::Scrobble.new(@http); end |
#shout ⇒ Object
69 |
# File 'lib/rocksky/client.rb', line 69 def shout; @shout ||= Resources::Shout.new(@http); end |
#song ⇒ Object
70 |
# File 'lib/rocksky/client.rb', line 70 def song; @song ||= Resources::Song.new(@http); end |
#spotify ⇒ Object
71 |
# File 'lib/rocksky/client.rb', line 71 def spotify; @spotify ||= Resources::Spotify.new(@http); end |
#stats ⇒ Object
72 |
# File 'lib/rocksky/client.rb', line 72 def stats; @stats ||= Resources::Stats.new(@http); end |
#with_token(new_token) ⇒ Object
Return a derived client that uses the given token (everything else copied). Handy for sharing one client across users in a request-scoped server.
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rocksky/client.rb', line 34 def with_token(new_token) self.class.new( base_url: base_url, token: new_token, headers: headers, user_agent: user_agent, open_timeout: open_timeout, read_timeout: read_timeout ) end |