Permalink
Browse files

Rohit/Akriti Added code for getting employers list from FB and displa…

…ying in radio buttons
  • Loading branch information...
rohitggarg committed Feb 21, 2013
1 parent ccd264a commit 4b0b2ba17b4a641270585167cf632ed05af489f7
@@ -4,6 +4,14 @@ class FacebookShareWidget::FacebookController < FacebookShareWidget::Application
def index
end
+ def employers
+ begin
+ @employers = my_employers
+ rescue Exception => ex
+ log_exception_and_render_as_json(ex)
+ end
+ end
+
def friends
begin
render json: facebook_friends_for_link(params[:link]), status: :ok
@@ -0,0 +1,2 @@
+- @employers.each do |employer|
+ = radio_button_tag 'employer', employer.name, false, id: "emp_#{employer.id}"
View
@@ -1,5 +1,6 @@
FacebookShareWidget::Engine.routes.draw do
get 'facebook' => 'facebook#index'
get 'facebook/friends' => 'facebook#friends'
+ get 'facebook/employers' => 'facebook#employers'
post 'facebook/share' => 'facebook#share'
end
@@ -18,6 +18,14 @@ def facebook_user(facebook_id)
FbGraph::User.new(facebook_id, access_token: self.facebook_access_token)
end
+ def my_employers
+ employers = []

This comment has been minimized.

Show comment Hide comment
@woodhull

woodhull Feb 26, 2013

Owner

It's probably a good idea to add caching in memcache here like we do for the friends call.

@woodhull

woodhull Feb 26, 2013

Owner

It's probably a good idea to add caching in memcache here like we do for the friends call.

+ facebook_me.work.each do |work_object|
+ employers << work_object.employer
+ end
+ employers
+ end
+
def facebook_friends
Rails.cache.fetch("friends_for_#{self.facebook_access_token}", :expires_in => 1.hour) do
friends = {}
@@ -33,7 +33,27 @@
response.body.should == { message: user_prompt }.to_json
end
end
-
+ describe "#employers" do
+ it "should return employers list" do
+ employers = [{ id: "1", name: "Thoughtworks" }]
+ controller.should_receive(:my_employers) { employers }
+
+ get :employers
+
+ response.should be_successful
+ assigns(:employers).to_json.should == employers.to_json
+ end
+
+ it "should return error message on fail" do
+ error = Exception.new("some error")
+ controller.should_receive(:my_employers).and_raise(error)
+
+ get :employers
+
+ response.should_not be_successful
+ response.body.should == { message: user_prompt }.to_json
+ end
+ end
describe "#share" do
context "successful post" do
before(:each) do
@@ -95,6 +95,17 @@ def initialize
end
end
+ describe "#my_employers" do
+ it "should return back list of my employers" do
+ raw_employers = [OpenStruct.new(employer: { id: "1", name: "name" }, position: {id: "123",
+ name: "Senior Consultant"}, start_date: "2012-03")]
+ me = mock
+ me.stub(:work) { raw_employers }
+ subject.stub(:facebook_me) { me }
+
+ subject.my_employers.should == [{ id: "1", name: "name" }]
+ end
+ end
describe "#post" do
it "should post to user wall" do
user = mock

1 comment on commit 4b0b2ba

@woodhull

This comment has been minimized.

Show comment Hide comment
@woodhull

woodhull Feb 26, 2013

Owner

It would be nice to build this in an as generic way as possible so we can also support people who go to school at the same institution for organizations where that makes sense.

Owner

woodhull commented on 4b0b2ba Feb 26, 2013

It would be nice to build this in an as generic way as possible so we can also support people who go to school at the same institution for organizations where that makes sense.

Please sign in to comment.