Skip to content

Commit

Permalink
Added API#set_app_restrictions convenience method, which handles the …
Browse files Browse the repository at this point in the history
…non-standard JSON-encoding for that call.
  • Loading branch information
arsduo committed Oct 14, 2011
1 parent eab2baf commit d89e558
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/koala/graph_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ def get_comments_for_urls(urls = [], args = {}, options = {})
args.merge!(:ids => urls.respond_to?(:join) ? urls.join(",") : urls)
get_object("comments", args, options)
end
def set_app_restrictions(app_id, restrictions_hash, args = {}, options = {})
graph_call(app_id, args.merge(:restrictions => MultiJson.encode(restrictions_hash)), "post", options)
end

# GraphCollection support
def get_page(params)
Expand Down
6 changes: 6 additions & 0 deletions spec/fixtures/mock_facebook_responses.yml
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,12 @@ graph_api:
<<: *token_required
with_token: '{"access_token": "<%= APP_ACCESS_TOKEN %>"}'


'/<%= APP_ID %>':
restrictions=<%= MultiJson.encode({"age_distr" => "13+"}) %>:
post:
with_token: "true"

# -- OAuth responses --
/oauth/access_token:
client_id=<%= APP_ID %>&client_secret=<%= SECRET %>&code=<%= OAUTH_CODE %>&redirect_uri=<%= OAUTH_DATA["callback_url"] %>:
Expand Down
27 changes: 27 additions & 0 deletions spec/support/graph_api_shared_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,33 @@
# we can't test this live since test users (or random real users) can't be guaranteed to have pages to manage
@api.should_receive(:api).with("my_page", {:fields => "access_token"}, "get", anything)
@api.get_page_access_token("my_page")
describe "#set_app_restrictions" do
before :all do
oauth = Koala::Facebook::OAuth.new(KoalaTest.app_id, KoalaTest.secret)
app_token = oauth.get_app_access_token
@app_api = Koala::Facebook::API.new(app_token)
@restrictions = {"age_distr" => "13+"}
end

it "makes a POST to /app_id" do
@app_api.should_receive(:graph_call).with(KoalaTest.app_id, anything, "post", anything)
@app_api.set_app_restrictions(KoalaTest.app_id, @restrictions)
end

it "JSON-encodes the restrictions" do
@app_api.should_receive(:graph_call).with(anything, hash_including(:restrictions => MultiJson.encode(@restrictions)), anything, anything)
@app_api.set_app_restrictions(KoalaTest.app_id, @restrictions)
end

it "includes the other arguments" do
args = {:a => 2}
@app_api.should_receive(:graph_call).with(anything, hash_including(args), anything, anything)
@app_api.set_app_restrictions(KoalaTest.app_id, @restrictions, args)
end

it "works" do
@app_api.set_app_restrictions(KoalaTest.app_id, @restrictions).should be_true
end
end

# test all methods to make sure they pass data through to the API
Expand Down

0 comments on commit d89e558

Please sign in to comment.