Class: Yourub::Client
- Inherits:
-
Object
- Object
- Yourub::Client
- Includes:
- MetaSearch
- Defined in:
- lib/yourub/client.rb
Instance Attribute Summary collapse
-
#videos ⇒ Object
readonly
Returns the value of attribute videos.
Instance Method Summary collapse
- #config ⇒ Object
- #countries ⇒ Object
-
#execute!(api_method:, parameters:) ⇒ Object
Compatibility shim used by Yourub::REST::Request.
- #flush_video_categories_cache! ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
The Yourub::Client is a subclass of the Google::APIClient.
- #list_video_categories(region_code: nil, hl: nil) ⇒ Object
Methods included from MetaSearch
Methods included from REST::Videos
Methods included from REST::Categories
Methods included from REST::Search
Constructor Details
#initialize(options = {}) ⇒ Client
The Yourub::Client is a subclass of the Google::APIClient.
In order to initialize the client, you have either to provide a configuration file 'config/yourub.yml' in your main application folder or to pass an hash in the initialization. If you don't provide all the values, default values will be used.The only mandatory value is the developer_key
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/yourub/client.rb', line 32 def initialize( = {}) unless .empty? Yourub::Config.override_config_file() end @service = Google::Apis::YoutubeV3::YouTubeService.new @service.key = config.developer_key @service..application_name = config.application_name @service..application_version = config.application_version @video_categories_cache = {} end |
Instance Attribute Details
#videos ⇒ Object (readonly)
Returns the value of attribute videos.
8 9 10 |
# File 'lib/yourub/client.rb', line 8 def videos @videos end |
Instance Method Details
#countries ⇒ Object
44 45 46 |
# File 'lib/yourub/client.rb', line 44 def countries Yourub::Validator.available_countries end |
#execute!(api_method:, parameters:) ⇒ Object
Compatibility shim used by Yourub::REST::Request
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/yourub/client.rb', line 67 def execute!(api_method:, parameters:) case api_method when :search_list part = parameters.delete(:part) || parameters.delete('part') || 'snippet' opts = normalize_search_params(parameters) data = @service.list_searches(part, **opts) OpenStruct.new(data: data, status: 200) when :videos_list part = parameters.delete(:part) || parameters.delete('part') || 'snippet' opts = normalize_videos_params(parameters) data = @service.list_videos(part, **opts) OpenStruct.new(data: data, status: 200) when :video_categories_list part = parameters.delete(:part) || parameters.delete('part') || 'snippet' opts = normalize_categories_params(parameters) data = @service.list_video_categories(part, **opts) OpenStruct.new(data: data, status: 200) else raise ArgumentError, "Unsupported api_method #{api_method.inspect}" end end |
#flush_video_categories_cache! ⇒ Object
62 63 64 |
# File 'lib/yourub/client.rb', line 62 def flush_video_categories_cache! @video_categories_cache.clear end |
#list_video_categories(region_code: nil, hl: nil) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/yourub/client.rb', line 48 def list_video_categories(region_code: nil, hl: nil) key = video_categories_cache_key(region_code, hl) return @video_categories_cache[key] if @video_categories_cache.key?(key) part = "snippet" kwargs = {} unless region_code.nil? || region_code.to_s.strip.empty? kwargs[:region_code] = region_code.to_s.strip.upcase end kwargs[:hl] = hl.to_s.strip if hl && !hl.to_s.strip.empty? @video_categories_cache[key] = @service.list_video_categories(part, **kwargs) end |