Permalink
Browse files

Use YoutubVideoClient to abstract away talking to youtube

  • Loading branch information...
edgenard committed May 13, 2018
1 parent 7c81e22 commit 7551b8d7ce5275fe506a8a5540bbbe1cceb47c57
Showing with 22 additions and 16 deletions.
  1. +22 −16 refactoring_external_service/youtube_video_list.rb
@@ -4,6 +4,27 @@ def videos
JSON.parse(video_list_json)
end
end

class YoutubeVideoClient

This comment has been minimized.

@medwards1771

medwards1771 May 15, 2018

Collaborator

Ok, cool, class for YouTube here

def video_stats(youtube_ids)
client = GoogleAuthorizer.new(
token_key: 'api-youtube',
application_name: 'Gateway Youtube Example',
application_version: '0.1'
).api_client

youtube = client.discovered_api('youtube', 'v3')
request = {
api_method: youtube.videos.list,
parameters: {
id: youtube_ids.join(","),
part: 'snippet, contentDetails, statistics',
}
}

response = JSON.parse(client.execute!(request).body)
end
end

class VideoService
attr_reader :video_repo
@@ -28,21 +49,6 @@ def video_list
private

def get_youtube_stats_on_videos(youtube_ids)
client = GoogleAuthorizer.new(
token_key: 'api-youtube',
application_name: 'Gateway Youtube Example',
application_version: '0.1'
).api_client
# NOTE: External Service
youtube = client.discovered_api('youtube', 'v3')
request = {
api_method: youtube.videos.list,# NOTE: External Service
parameters: {
id: youtube_ids.join(","),
part: 'snippet, contentDetails, statistics',
}
}
# NOTE: External Service
response = JSON.parse(client.execute!(request).body)
YoutubeVideoClient.new.video_stats(youtube_ids)
end
end

0 comments on commit 7551b8d

Please sign in to comment.