Class: Dm::DailyMotionAccount

Inherits:
Object
  • Object
show all
Includes:
Authenticable, Readable
Defined in:
lib/dm/google_account.rb,
lib/dm/youtube_account.rb

Overview

Provides read & write access to a DailyMotion account (also known as Channel).

Examples:

Like the video “Tongue” by R.E.M. as a specific DailyMotion account:

* Set up two pages: one with a link to authenticate, one to redirect to
* In the first page, add a link to the authentication page:

    Dm::DailyMotionAccount.oauth_url(redirect_url)

* The user authenticates and lands on the second page, with an extra +code+ query parameter
* Use the authorization code to initialize the DailyMotionAccount and like the video:

    account = Dm::DailyMotionAccount.new code: code, redirect_url: redirect_url
    account.perform! :like, :video, 'Kd5M17e7Wek' # => likes the video

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Readable

#description, #kind, #thumbnail_url, #title

Methods included from Authenticable

#credentials, #initialize

Methods included from Requestable

#request!

Methods included from ClientTokens

#client_id, client_id=, #client_secret, client_secret=

Class Method Details

.attribute(name) ⇒ Object

Define a method to return each attribute of the profile separately.



51
52
53
# File 'lib/dm/google_account.rb', line 51

def self.attribute(name)
  define_method(name) { info[name] }
end

.oauth_scopesObject

Set the scopes to grant access to DailyMotion account



70
71
72
# File 'lib/dm/google_account.rb', line 70

def self.oauth_scopes
  %w(profile email)
end

Instance Method Details

#emailObject

Return the email attribute of the DailyMotion Account.



56
# File 'lib/dm/google_account.rb', line 56

attribute :email

#family_nameObject

Return the family_name attribute of the DailyMotion Account.



60
# File 'lib/dm/google_account.rb', line 60

attribute :family_name

#genderObject

Return the gender attribute of the DailyMotion Account.



63
# File 'lib/dm/google_account.rb', line 63

attribute :gender

#given_nameObject

Return the given_name attribute of the DailyMotion Account.



59
# File 'lib/dm/google_account.rb', line 59

attribute :given_name

#hdObject

Return the hd attribute of the DailyMotion Account.



65
# File 'lib/dm/google_account.rb', line 65

attribute :hd

#idObject

Return the id attribute of the DailyMotion Account.



55
# File 'lib/dm/google_account.rb', line 55

attribute :id

#infoHash

Return the profile info of a DailyMotion account/channel.

Returns:

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

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

    • :kind [String] The value will be dailymotion#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:



37
38
39
40
41
42
43
# File 'lib/dm/google_account.rb', line 37

def info
  @info ||= request! method: :get,
    auth: credentials[:access_token],
    host: 'https://www.googleapis.com',
    path: '/oauth2/v2/userinfo',
    valid_if: -> response, body {response.code == '200'}
end

Return the link attribute of the DailyMotion Account.



61
# File 'lib/dm/google_account.rb', line 61

attribute :link

#localeObject

Return the locale attribute of the DailyMotion Account.



64
# File 'lib/dm/google_account.rb', line 64

attribute :locale

#nameObject

Return the name attribute of the DailyMotion Account.



58
# File 'lib/dm/google_account.rb', line 58

attribute :name

#perform!(activity, target_kind, target_id) ⇒ Object

Promote a DailyMotion target resource on this DailyMotion Channel Note that liking a video does not also subscribe to a channel



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/dm/youtube_account.rb', line 49

def perform!(activity, target_kind, target_id)
  params = {}.tap do |params|
    params[:method] = :post
    params[:auth] = credentials[:access_token]
    params[:host] = 'https://www.googleapis.com'

    case [activity.to_sym, target_kind.to_sym]
    when [:like, :video]
      params[:path] = "/dailymotion/v3/videos/rate?rating=like&id=#{target_id}"
      params[:valid_if] = -> response, body {response.code == '204'}
    when [:subscribe_to, :channel]
      params[:json] = true
      params[:path] = '/dailymotion/v3/subscriptions?part=snippet'
      params[:body] = {snippet: {resourceId: {channelId: target_id}}}
      params[:valid_if] = -> response, body {response.code == '200'}
    else
      raise RequestError, "#{activity} invalid for #{target_kind} #{target_id}"
    end
  end
  request! params
end

#pictureObject

Return the picture attribute of the DailyMotion Account.



62
# File 'lib/dm/google_account.rb', line 62

attribute :picture

#verified_emailObject

Return the verified_email attribute of the DailyMotion Account.



57
# File 'lib/dm/google_account.rb', line 57

attribute :verified_email