简体   繁体   English

Vimeo Gem API导轨

[英]Vimeo Gem API Rails

I have a vimeo account that I would like to link the videos from my account to posts in my rails app. 我有一个vimeo帐户,我想将我帐户中的视频链接到我的Rails应用程序中的帖子。

I have the Vimeo Gem and I'm having difficulty understanding how I implement the API within my post. 我有Vimeo Gem ,但在理解自己的帖子中如何实现API时遇到困难。

For each post created I want to link a video file to the post based on a column from my database which I input the video id. 对于创建的每个帖子,我都希望基于数据库中输入视频ID的列将视频文件链接到帖子。

Does anyone know of any tutorials or example regarding this gem? 有人知道有关此gem的任何教程或示例吗?

Schema 架构

create_table "vimeo", :force => true do |t|
    t.string   "title"
    t.text     "description"
    t.integer  "vimeo_clip_id"
    t.datetime "created_at",    :null => false
    t.datetime "updated_at",    :null => false
  end

Controller 调节器

Show 节目

@vimeo = Vimeo.find(params[:id])
@video = Vimeo.where(:vimeo_clip_id)
@vimeo = Vimeo::Simple::Video.info(@video)

View 视图

<p><%= @vimeo.title %></p>

Outputs 'video_id is not a valid method.'. 输出“ video_id不是有效方法”。

Not sure how to implement the API so it recognises my Vimeo user id and then displays the video as per my video_clip_id I input. 不确定如何实现API,以便它识别我的Vimeo用户ID,然后根据我输入的video_clip_id显示视频。

You have to replace video_id with the vimeo_clip_id value. 您必须用vimeo_clip_id值替换video_id For example in the console 例如在控制台中

Vimeo::Simple::Video.info "78673338"

returns 回报

<HTTParty::Response:0x7ff09a9076e8 large_chunk_of_data_here>

You can create the link you want with the data you receive. 您可以使用接收到的数据创建所需的链接。 In your controller: 在您的控制器中:

def show
  @vimeo = Vimeo.find params[:id]
  @link_url = Vimeo::Simple::Video.info(@vimeo.vimeo_clip_id)[0]['url']
end

and in the view: 并在视图中:

link_to @vimeo.title, @link_url

Please note the following: 请注意以下事项:

  • The controller code can be cleaned up. 控制器代码可以清除。 You probably don't want to be doing the retrieving of the link URL in the controller every time the show page is rendered. 您可能不想在每次显示页面时都在控制器中检索链接URL。 Instead you want to be storing that information with your Vimeo object. 相反,您想将该信息与Vimeo对象一起存储。
  • Inspect the response from the Vimeo API to find out what the [0]['url'] part does. 检查来自Vimeo API的响应,以找出[0]['url']部分的作用。
  • The view code just displays a text link. 查看代码仅显示一个文本链接。 You can explore other options such as a preview image later. 您可以稍后浏览其他选项,例如预览图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM