spotify web setup is done
This commit is contained in:
28
app/services/create_spotify_activity.rb
Normal file
28
app/services/create_spotify_activity.rb
Normal file
@@ -0,0 +1,28 @@
|
||||
class CreateSpotifyActivity
|
||||
attr_accessor :response, :user
|
||||
|
||||
def initialize(user, spotify_response)
|
||||
@response = spotify_response
|
||||
@user = user
|
||||
end
|
||||
|
||||
# rubocop:disable Metrics/AbcSize
|
||||
def perform
|
||||
response['items'].reverse.each do |play|
|
||||
activity = new_activity
|
||||
activity.item_ref = play['track']['id']
|
||||
artist_names = play['track']['artists'].map { |a| a['name'] }
|
||||
artists = artist_names.join(', ')
|
||||
title = "#{artists} - #{play['track']['name']}"
|
||||
activity.item_title = title
|
||||
activity.item_length = play['track']['duration'].to_s
|
||||
activity.started_at = DateTime.parse(play['played_at'])
|
||||
activity.save
|
||||
end
|
||||
end
|
||||
# rubocop:enable Metrics/AbcSize
|
||||
|
||||
def new_activity
|
||||
Activity.new(user: user, platform: 'spotify')
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user