ぼざクリタグ広場 https://hub.nizika.monster
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

35 lines
880 B

  1. module Youtube
  2. class SearchClient
  3. API_BASE = 'https://www.googleapis.com/youtube/v3'
  4. def initialize api_key: ENV.fetch('YOUTUBE_API_KEY')
  5. @api_key = api_key
  6. end
  7. def search_videos query:, published_after: nil, published_before: nil, page_token: nil
  8. response = connection.get('search', {
  9. part: 'snippet',
  10. q: query,
  11. type: 'video',
  12. order: 'date',
  13. maxResults: 50,
  14. regionCode: 'JP',
  15. relevanceLanguage: 'ja',
  16. publishedAfter: published_after&.iso8601,
  17. publishedBefore: published_before&.iso8601,
  18. pageToken: page_token,
  19. key: @api_key }.compact)
  20. JSON.parse(response.body)
  21. end
  22. private
  23. def connection
  24. @connection ||= Faraday.new(url: API_BASE) do |faraday|
  25. faraday.response :raise_error
  26. end
  27. end
  28. end
  29. end