Class: MusicBox::Discogs
- Inherits:
-
Object
- Object
- MusicBox::Discogs
- Defined in:
- lib/musicbox/discogs.rb
Constant Summary collapse
- AppName =
'musicbox-discogs'
- ResultsPerPage =
100
Instance Method Summary collapse
- #discogs_do(command, *args) ⇒ Object
-
#initialize(catalog:) ⇒ Discogs
constructor
A new instance of Discogs.
- #update ⇒ Object
- #update_release(release) ⇒ Object
Constructor Details
Instance Method Details
#discogs_do(command, *args) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/musicbox/discogs.rb', line 43 def discogs_do(command, *args) sleep(1) ;;pp(command: command, args: args) result = @discogs.send(command, *args) raise Error, "Bad result: #{result.inspect}" if result.nil? || result. result end |
#update ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/musicbox/discogs.rb', line 14 def update @catalog.collection.destroy! page = 1 loop do result = discogs_do(:get_user_collection, @user, page: page, per_page: ResultsPerPage) result.releases.each do |release| begin update_release(release) rescue Error => e warn "Error: #{e}" end end page = result.pagination.page + 1 break if page > result.pagination.pages end end |
#update_release(release) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/musicbox/discogs.rb', line 31 def update_release(release) @catalog.collection.save_item(id: release.id, item: release) info = release.basic_information @catalog.releases.save_item_if_new(id: info.id) { discogs_do(:get_release, info.id) } if info.master_id && info.master_id > 0 @catalog.masters.save_item_if_new(id: info.master_id) { discogs_do(:get_master_release, info.master_id) } end info.artists.each do |artist| @catalog.artists.save_item_if_new(id: artist.id) { discogs_do(:get_artist, artist.id) } end end |