Skip to content
This repository has been archived by the owner on Apr 24, 2019. It is now read-only.

Commit

Permalink
Use YoutubVideoClient to abstract away talking to youtube
Browse files Browse the repository at this point in the history
  • Loading branch information
edgenard committed May 13, 2018
1 parent 7c81e22 commit 7551b8d
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions refactoring_external_service/youtube_video_list.rb
Expand Up @@ -4,6 +4,27 @@ def videos
JSON.parse(video_list_json)
end
end

class YoutubeVideoClient

This comment has been minimized.

Copy link
@medwards1771

medwards1771 May 15, 2018

Contributor

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
Expand All @@ -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.