Adding Zype to a Rails Application Adding Zype to a Rails Application

Adding Zype to a Rails Application

At Zype, we use our Zype Gem to build fully branded video experiences on the web. Below is a step-by-step guide for how to integrate the Zype Gem into a Rails App. 

1. Add the Zype Gem to your Gemfile and bundle.

gem 'zype', :git => 'git://github.com/edla/zype-cli.git'

2. Add your Zype Configurations to the initializers directory

# Create a new file config/initializers/zype.rb

  Zype.configure do |config|
    config.api_key = {api_key}
    config.host    =  "api.zype.com"
    config.port    =  80
    config.use_ssl = false
  end

You can find your api key from the Zype Platform

3. Add the following javascript to your layout.html.erb to be able to power the appropriate player javascript.

<script type="text/javascript" src="http://api.zype.com/player.js"></script>
<script type="text/javascript"> zype.player_key = {player_key};</script>

You can find your player key from the Zype Platform

4. Create a new instance of your Zype Client so that you can query the Zype Platform to get your videos, playlists, categories, zobjects, and appropriate video players from your Rails App.

@zype = Zype::Client.new

5. Some things that you can do with your Zype Client that could be useful for a web app:

  • Get all your videos
@zype.videos
  • Get a specific video
@zype.videos.find(params[:video_id])
  • Change pagination
@zype.videos.all(per_page: 500)
  • Pagination
@zype.videos.all(page: 2, per_page: 50)
  • Sort (ex. sort by video title)
@zype.videos.all(sort: title, order: asc)
  • Query by zobject type (example: genre)
@zype.zobjects.all(zobject_name, {})
  • Query videos by category (example genre)
@zype.videos.all(category: {genre: Comedy})
  • Get the player for a video
@video = @zype.videos.find(params[:video_id])
@player = @video.player(player_opts)

6. Display the video player in your HTML view

<%= @player['body'].html_safe %>

Was this article helpful?

0 out of 0 found this helpful