Class: Vm::VimeoResource

Inherits:
Object
  • Object
show all
Includes:
Readable, Requestable, ServerTokens
Defined in:
lib/vm/vimeo_resource.rb

Overview

Provides read-only access to a Vimeo resource (a channel or a video).

Note that this class does not require the user to authenticate.

Examples:

Get the description of the video “Tongue” by R.E.M.:


resource = Vm::VimeoResource.new url: 'youtu.be/Kd5M17e7Wek'
resource.description # => "© 2006 WMG\nTongue (Video)"

Get the description of the R.E.M. channel:


resource = Vm::VimeoResource.new url: 'vimeo.com/remhq'
resource.description # => "R.E.M.'s Official Vimeo Channel"

Instance Method Summary collapse

Methods included from ServerTokens

#server_key, server_key=

Methods included from Readable

#description, #id, #kind, #thumbnail_url, #title

Methods included from Requestable

#request!

Constructor Details

#initialize(attrs = {}) ⇒ VimeoResource

Initialize a resource by URL

Parameters:

  • attrs (Hash) (defaults to: {})

Options Hash (attrs):

  • :url (String)

    The URL of the Vimeo channel or video


28
29
30
# File 'lib/vm/vimeo_resource.rb', line 28

def initialize(attrs = {})
  @url = attrs[:url]
end

Instance Method Details

#infoHash

Return the profile info of a Vimeo account/channel.

Returns:

  • (Hash)
    • :id [String] The ID that Vimeo uses to uniquely identify the channel.

    • :etag [String] The Etag of this resource.

    • :kind [String] The value will be vimeo#channel.

    • :snippet [Hash]

      • :title [String] The channel's title.

      • :description [String] The channel's description.

      • :publishedAt [String] The date and time that the channel was created. The value is specified in ISO 8601 (YYYY-MM-DDThh:mm:ss.sZ) format.

      • :thumbnails [Hash] + :default [Hash] Default thumbnail URL (88px x 88px) + :medium [Hash] Medium thumbnail URL (88px x 88px) + :high [Hash] High thumbnail URL (88px x 88px)

See Also:


48
49
50
51
52
53
54
# File 'lib/vm/vimeo_resource.rb', line 48

def info
  @info ||= request! method: :get,
    host: 'https://www.googleapis.com',
    path: "/vimeo/v3/#{info_path}",
    valid_if: -> resp, body {resp.code == '200' && body['items'].any?},
    extract: -> body {body['items'].first}
end