Created
March 2, 2021 12:35
-
-
Save jmarsh24/577a879cde541da4bac7288fbc5d8e9c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Video::AcrCloudImport::Parse | |
attr_reader :acr_response_code, | |
:spotify_album_id, | |
:spotify_album_name, | |
:spotify_album_name, | |
:spotify_artist, | |
:spotify_artist_1, | |
:spotify_artist_2, | |
:spotift_artist_name, | |
:spotift_artist_name_1, | |
:spotift_artist_name_2, | |
:spotify_album_id, | |
:spotify_album_name, | |
:spotify_track_id, | |
:spotify_track_name, | |
:spotify_track_name, | |
:youtube_song_id, | |
:isrc | |
class << self | |
def import(response) | |
new(response).import | |
end | |
end | |
def initialize(response) | |
@response = response | |
end | |
def import | |
byebug | |
response_params(parsed_response) | |
end | |
private | |
def parsed_response | |
JSON.parse(@response).extend Hashie::Extensions::DeepFind | |
end | |
def response_params(parsed_response) | |
@acr_response_code = parsed_response.dig("status", "code") | |
@spotify_album_id = parsed_response.deep_find("spotify")["album"]["id"] | |
@spotify_album_name = parsed_response.deep_find("spotify")["album"]["name"] | |
@spotify_album_name = RSpotify::Album.find(@spotify_album_id).name unless @spotify_album_id.nil? | |
@spotify_artist_id = parsed_response.deep_find("spotify")["artists"][0]["id"] | |
@spotify_artist_id_1 = parsed_response.deep_find("spotify")["artists"][1]["id"] | |
@spotify_artist_id_2 = parsed_response.deep_find("spotify")["artists"][2]["id"] | |
@spotify_artist_name = RSpotify::Artist.find(@spotify_artist_id).name | |
@spotify_artist_name_1 = RSpotify::Artist.find(@spotify_artist_id_1).name | |
@spotify_artist_name_2 = RSpotify::Artist.find(@spotify_artist_id_2).name | |
@spotify_album_id = parsed_response.deep_find("spotify")["album"]["id"][0] | |
@spotify_album_name = RSpotify::Album.find(@spotify_album_id).name | |
@spotify_track_id = parsed_response.deep_find("spotify")["track"]["id"] | |
@spotify_track_name = RSpotify::Track.find(@spotify_track_id).name | |
@spotify_track_name = parsed_response.deep_find("spotify")["track"]["name"] | |
@youtube_song_id = parsed_response.deep_find("youtube")["vid"] | |
@isrc = parsed_response.deep_find("external_ids")["isrc"] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment