Br Fantasy Api Plugin

Talk to Br Fantasy Api from your Rails app to get user info.

Installation:


$ gem install br_api_fantasy --no-ri --no-rdoc

Copy br_api_fantasy.example.yml to rails_project/config/br_api_fantasy.yml. Update the api_key to the one given to you by Bleacher Report.

Usage:

After a user logs in or signs up from one of the Bleacher Report's fantasy branded pages, they will be redirected to the passthrough params[:return_to] url, which can be set by the Fantasy Games 3rd party, along with a token (user_token). The 3rd party can use the token to then generate the verified hash on their servers. BR will generate the same hash and compare against it to ensure it's coming from a trusted source.

The plugin contains methods to talk to the br fantasy api. The methods will use the api_key configured in br_api_fantasy.yml:

Methods available:

Br::Api::Fantasy.authenticate('user-token-returned-from-login-page') Br::Api::Fantasy.set_team('user-token-returned-from-login-page', team_id = 160) # 160 is dallas cowboys

Example:


$ ./script/console 
>> pp Br::Api::Fantasy.authenticate('foobar-invalid-token')
{"response_details"=>"user with fantasy token foobar-invalid-token not found",
 "response_data"=>nil,
 "response_summary"=>"user not found",
 "response_status"=>200}
=> nil
>> pp Br::Api::Fantasy.authenticate('8681576f47b87b2988bdc76262164cda00019986')
{"response_details"=>"signature successfully matched",
 "response_data"=>
  {"user_last_name"=>"McCormick",
   "user_first_name"=>"Kenny",
   "user_permalink"=>"http://breport.local/users/309596-kenny-mccormick",
   "user_id"=>309596},
 "response_summary"=>"login success",
 "response_status"=>200}
=> nil
>> pp Br::Api::Fantasy.authenticate('2e54040f9019023d2ad225b92d08ee1c14af1948')
{"response_details"=>"signature successfully matched",
 "response_data"=>
  {"user_last_name"=>"Cartman",
   "user_email"=>"[email protected]",
   "user_first_name"=>"Eric",
   "user_permalink"=>"http://breport.local/users/337228-eric-cartman",
   "user_id"=>337228,
   "fantasy_team_id"=>nil,
   "fantasy_team_name"=>nil},
 "response_summary"=>"user found",
 "response_status"=>200}
 => nil 
>> pp Br::Api::Fantasy.set_team('2e54040f9019023d2ad225b92d08ee1c14af1948', 160)
{"response_details"=>"",
 "response_data"=>
  {"user_last_name"=>"Cartman",
   "user_email"=>"[email protected]",
   "user_first_name"=>"Eric",
   "errors"=>"",
   "user_permalink"=>"http://breport.local/users/337228-eric-cartman",
   "success"=>false,
   "user_id"=>337228,
   "fantasy_team_id"=>160,
   "fantasy_team_name"=>"Dallas Cowboys"},
 "response_summary"=>"fantasy team saved success",
 "response_status"=>200}
 => nil 
>>