Git Product home page Git Product logo

flix's Introduction

Flix

TODO: Write a gem description

Installation

Add this line to your application's Gemfile:

gem 'flix'

And then execute:

$ bundle

Or install it yourself as:

$ gem install flix

Usage

You can use omniauth-netflix to auth with Netflix and get a user's netflix_key, netflix_secret, and netflix_uid

In an initializer like omniauth.rb

provider :netflix, NETFLIX_CONSUMER_KEY, NETFLIX_CONSUMER_SECRET

This was in my User model user.rb

def apply_netflix(auth)
  puts "Did you Make it To NETFLIX: #{auth['info']}"
  self.name = auth["info"]["name"]
  self.username = auth["info"]["nickname"]
  self.role = auth["provider"]
                        
  credentials = auth["credentials"]
  authentications.build(:provider => auth["provider"], 
                        :uid => auth["uid"],
                        :access_token => credentials.token,
                        :access_secret => credentials.secret)
end

def netflix_key
  authentications.where(provider: "netflix").first.access_token if authentications.where(provider: "netflix").any?
end

def netflix_secret
  authentications.where(provider: "netflix").first.access_secret if authentications.where(provider: "netflix").any?
end

def netflix_uid
  authentications.where(provider: "netflix").first.uid if authentications.where(provider: "netflix").any?
end

Example of creating a Class to use Flix:

class NFlix
  
  def self.flix_client(user)
    Flix.configure do |config|
      config.consumer_key = NETFLIX_CONSUMER_KEY
      config.consumer_secret = NETFLIX_CONSUMER_SECRET
      config.oauth_token = user.netflix_key
      config.oauth_token_secret = user.netflix_secret
      config.uid = user.netflix_uid
    end
    
    return Flix
  end
  
end

Then you can create an instance of Flix in a controller

@flix = NFlix.flix_client(current_user)

Then in a view you can access Netflix like this


<% if @flix.user %>
  <div class="row">
    <h2>Netflix User</h2>
    <pre>
      <%= @flix.user["first_name"] %> <%= @flix.user["last_name"] %>
    </pre>
  </div>

  <div class="row">
      <h2>Netflix Instant Queue</h2>
      <% @flix.instant_queue.each do |queue_item| %>
        <pre>
          <img src="<%= queue_item["box_art"]["medium"] %>">
          <%= queue_item["title"]["short"] %>
        </pre>
      <% end %>
  </div>
<% end %>

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.