Skip to content

froveda/zype-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Zype Video Example App

This is an example application using the Zype api to login a user and to list and show videos.

Login

For the login part of the application, I use Warden along with ActiveModel (for User model), since all the login activity is done through Zype login api.

The login strategy is in ZypeLoginStrategy module:

lib/strategies/zype_login_strategy.rb

It calls to:

https://login.zype.com/oauth/token

with the correct parameters and wait for a 200 response and an access_token value. If it happens, it initializes a new User and then sign in in the system. Otherwise, it will call warden fail!.

In SessionsController I manage the login of the user using warden. If the login is successful, it will redirect to the previous page. If not, Warden is configured in application.rb to redirect to SessionsController#login_fail:

manager.failure_app = ->(env){ SessionsController.action(:login_fail).call(env) }

which will render SessionsController#new with an error message.

Videos listing and show

List of Videos

The root of the application is in HomeController#index. Through an ajax call, it calls to VideosController#index to get the list of videos. In subsequent calls (clicking in previous or next links in home index) it asks for new video pages.

The Video api is being call through ZypeApi module.

Calling ZypeApi.get_videos(page), I get the list of videos in that page calling

https://api.zype.com/videos?app_key=#{ENV['APP_KEY']}&page=#{page}

Show a Video

To show a video, we access to VideosController#show with a video_id got from Zype api, and then calls to

https://api.zype.com/videos/#{video_id}?app_key=#{ENV['APP_KEY']}

through ZypeApi.self.get_video(video_id).

If the video is not subscription_required, then I use

div id="zype_#{@video_id}"
script src="https://player.zype.com/embed/#{@video_id}.js?autoplay=true&app_key=#{ENV['APP_KEY']}" type="text/javascript"

If the video is subscription_required and the user is not logged in, then a paywall subscription form is shown to allow the user to sign in. Otherwise, the video is being shown using:

div id="zype_#{@video_id}"
script src="https://player.zype.com/embed/#{@video_id}.js?autoplay=true&access_token=#{current_user['access_token']} " type="text/javascript"

Considerations

  • I use bootstrap-sass gem to include bootstrap 3 components into the application
  • A live version of the application is hosted on Heroku. click here to access it. Logint with the following credentials:
  • I have not used ActiveRecord to store users since right now I use the Zype login api to get the data that I need. But in the future, it is possible to use ActiveRecord for users if there is a need to do this

About

Zype exercise

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published