Method: PlaylyfeClient::Connection#initialize

Defined in:
lib/playlyfe_client/connection.rb

#initialize(options = {}) ⇒ Connection

Returns a new instance of Connection.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/playlyfe_client/connection.rb', line 23

def initialize(options = {})
  if options[:type].nil?
    err = PlaylyfeClient::ConnectionError.new("")
    err.name = 'init_failed'
    err.message = "You must pass in a type whether 'client' for client credentials flow or 'code' for auth code flow"
    raise err
  end
  @version = options[:version] ||= 'v2'
  @type = options[:type]
  @id = options[:client_id]
  @secret = options[:client_secret]
  @store = options[:store]
  @load = options[:load]
  @redirect_uri = options[:redirect_uri]
  if @store.nil?
    @store = lambda { |token| puts 'Storing Token' }
  end
  if @type == 'client'
    get_access_token()
  else
    if options[:redirect_uri].nil?
      err = PlaylyfeClient::ConnectionError.new("")
      err.name = 'init_failed'
      err.message = 'You must pass in a redirect_uri for the auth code flow'
      raise err
    end
  end
end