Class: SkyJam::Library

Inherits:
Object
  • Object
show all
Defined in:
lib/skyjam/library.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Library

Returns a new instance of Library.



44
45
46
# File 'lib/skyjam/library.rb', line 44

def initialize(path)
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



42
43
44
# File 'lib/skyjam/library.rb', line 42

def path
  @path
end

Class Method Details

.auth(path = nil) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/skyjam/library.rb', line 4

def auth(path = nil)
  config = auth_config(path) || default_auth_config

  client = Client.new
  client.oauth2_setup
  client.uploader_auth

  FileUtils.mkdir_p(File.dirname(config))
  client.oauth2_persist(config)
end

.connect(path) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/skyjam/library.rb', line 15

def connect(path)
  library = new(path)

  config = default_auth_config if File.exist?(default_auth_config)
  config = auth_config(path) if File.exist?(auth_config(path))

  fail Client::Error, 'no auth' if config.nil?

  library.instance_eval do
    @client = Client.new
    @client.oauth2_restore(config)
  end

  library
end

Instance Method Details

#tracksObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/skyjam/library.rb', line 48

def tracks
  return @tracks unless @tracks.nil?

  @tracks = []
  continuation_token = nil

  loop do
    list = client.listtracks(continuation_token: continuation_token)

    continuation_token = list[:continuation_token]

    list[:track_info].each do |info|
      track = SkyJam::Track.new(info)
      library = self
      track.instance_eval { @library = library }

      @tracks << track
    end

    break if continuation_token == ''
  end

  @tracks
end