Giter VIP home page Giter VIP logo

facebook_test_users's Introduction

A gem to ease the pain of managing Facebook test users

Testing Facebook apps is hard; part of that difficulty comes from managing your test users. Currently, Facebook's "Developer" app doesn't offer any way to do it, so you wind up with a bunch of curl commands and pain (see Facebook's API documentation for details).

This gem tries to take away the pain of managing your test users. It's easy to get started.

$ gem install facebook_test_users

$ fbtu apps register --name myapp --app-id 123456 --app-secret abcdef

$ fbtu users list --app myapp

$ fbtu users create --app myapp --name Fred

$ fbtu users change --app myapp --user 1000000093284356 --name "Sir Fred"

$ fbtu apps add-user --from-app myapp --user 1000000093284356 --to-app myotherapp

$ fbtu apps rm-user --app myapp --user 1000000093284356

$ fbtu users rm --app myapp --user 1000000093284356

You can also use it in your own Ruby applications; require "facebook_test_users" and off you go.

Integration with Rails apps

It's easy to integrate with Rails apps. For example, if your app has a "config/omniauth/#{Rails.env}.yml" file containing:

facebook:
  name:       http://localhost:3000
  API_key:    123456789012
  app_secret: a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6

and config/initializers/omniauth.rb containing:

omniauth_yml_path = Rails.root.join("config", "omniauth", Rails.env + ".yml")
SETTINGS = YAML.load(IO.read(omniauth_yml_path))

Rails.application.config.middleware.use OmniAuth::Builder do
  SETTINGS.each do |service, secrets|
    provider service.to_sym, secrets['API_key'], secrets['app_secret']
  end
end

then you could build simple rake tasks like this:

require 'facebook_test_users/cli'
require File.expand_path "#{Rails.root}/config/initializers/omniauth.rb"

fb = SETTINGS['facebook']
APP_ID = fb['API_key']
SECRET = fb['app_secret']

namespace :fbtu do
  namespace :app do
    desc 'Register facebook app credentials with fbtu'
    task :register do
      FacebookTestUsers::App.create!(:name => fb['name'], :id => APP_ID, :secret => SECRET)
      puts "Registered app '#{fb['name']}'"
    end
  end

  namespace :users do
    desc 'List test users via fbtu'
    task :list do
      cli = FacebookTestUsers::CLI::Main.start [:users, :list, '--app', fb['name'] ]
    end
  end
end

Then after running rake fbtu:app:register, you can invoke fbtu commands as per normal, using --app http://localhost:3000 to refer to the registered app.

facebook_test_users's People

Contributors

kasatani avatar millisami avatar smerritt avatar

Watchers

 avatar  avatar

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.