Class: DailymotionGraphApi::Client
- Inherits:
-
Object
- Object
- DailymotionGraphApi::Client
- Defined in:
- lib/dailymotion-graph-api.rb
Instance Method Summary collapse
- #authorize_url(callback_url, scope_array = %w(manage_videos))) ⇒ Object
- #connexion ⇒ Object
- #create_video(arguments) ⇒ Object
- #get_access_token(code, callback_url) ⇒ Object
- #get_infos(user, additional_params = {}) ⇒ Object
- #get_upload_url ⇒ Object
-
#initialize(client_id, client_secret, access_token = nil, refresh_token = nil) ⇒ Client
constructor
A new instance of Client.
- #refresh_token ⇒ Object
- #tmp_upload(video_path) ⇒ Object
- #videos(user, fields = %w(id title created_time))) ⇒ Object
Constructor Details
#initialize(client_id, client_secret, access_token = nil, refresh_token = nil) ⇒ Client
7 8 9 10 11 12 |
# File 'lib/dailymotion-graph-api.rb', line 7 def initialize(client_id, client_secret, access_token = nil, refresh_token = nil) @client_id = client_id @client_secret = client_secret @access_token = access_token @refresh_token = refresh_token end |
Instance Method Details
#authorize_url(callback_url, scope_array = %w(manage_videos))) ⇒ Object
14 15 16 |
# File 'lib/dailymotion-graph-api.rb', line 14 def (callback_url, scope_array = %w(manage_videos)) "https://api.dailymotion.com/oauth/authorize?client_id=#{@client_id}&redirect_uri=#{callback_url}&response_type=code&scope=#{scope_array.join('+')}" end |
#connexion ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/dailymotion-graph-api.rb', line 18 def connexion @connexion ||= Faraday.new(:url => 'https://api.dailymotion.com', ssl: { verify: false }) do |faraday| faraday.request :url_encoded faraday.response :logger faraday.adapter Faraday.default_adapter end end |
#create_video(arguments) ⇒ Object
53 54 55 |
# File 'lib/dailymotion-graph-api.rb', line 53 def create_video(arguments) send_request('/me/videos', { verb: :post, body: arguments }) end |
#get_access_token(code, callback_url) ⇒ Object
31 32 33 |
# File 'lib/dailymotion-graph-api.rb', line 31 def get_access_token(code, callback_url) token('authorization_code', redirect_uri: callback_url, code: code) end |
#get_infos(user, additional_params = {}) ⇒ Object
74 75 76 |
# File 'lib/dailymotion-graph-api.rb', line 74 def get_infos(user, additional_params = {}) send_request("/user/#{user}", additional_params) end |
#get_upload_url ⇒ Object
70 71 72 |
# File 'lib/dailymotion-graph-api.rb', line 70 def get_upload_url send_request('/file/upload') end |
#refresh_token ⇒ Object
26 27 28 29 |
# File 'lib/dailymotion-graph-api.rb', line 26 def refresh_token raise 'Missing refresh token' unless @refresh_token token('refresh_token', refresh_token: @refresh_token) end |
#tmp_upload(video_path) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/dailymotion-graph-api.rb', line 35 def tmp_upload(video_path) remote_uri = URI.parse(get_upload_url['upload_url']) upload_connexion = Faraday.new(url: 'http://upload-01.dailymotion.com', ssl: { verify: false }) do |faraday| faraday.request :multipart faraday.response :logger faraday.adapter Faraday.default_adapter end send_request('/upload', remote_uri.query.split('&').collect{|item| item.split('=')}.to_h.merge( { body: { file: Faraday::UploadIO.new(video_path, 'video/mp4') }, connexion: upload_connexion }) ) end |
#videos(user, fields = %w(id title created_time))) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/dailymotion-graph-api.rb', line 57 def videos(user, fields = %w(id title created_time)) has_more = true page = 1 result = [] while has_more response = send_request("/user/#{user}/videos", limit: 100, page: page, fields: fields.join(',')) result += response['list'] has_more = response['has_more'] page += 1 end result end |