Skip to content

Commit

Permalink
add MiniFB.delete for DELETE requests to the graph API (also supports…
Browse files Browse the repository at this point in the history
… batch delete).
  • Loading branch information
isuda committed Sep 14, 2011
1 parent babd1c8 commit 392feeb
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion lib/mini_fb.rb
Expand Up @@ -610,6 +610,31 @@ def self.post(access_token, id, options={})
return fetch(url, options)

end

# Sends a DELETE request to the Facebook Graph API
# options:
# - type: eg: feed, home, etc
# - metadata: to include metadata in response. true/false
# - params: Any additional parameters you would like to submit
def self.delete(access_token, ids, options={})
url = "#{graph_base}"
params = options[:params] || {}
if ids.is_a?(Array)
params["ids"] = ids.join(',')
else
url << "#{ids}"
end
url << "/#{options[:type]}" if options[:type]
options.delete(:type)
options.each do |key, value|
params[key] = "#{value}"
end
params["access_token"] = "#{(access_token)}"
options[:params] = params
options[:method] = :delete
return fetch(url, options)

end

# Executes an FQL query
def self.fql(access_token, fql_query, options={})
Expand Down Expand Up @@ -654,9 +679,16 @@ def self.rest(access_token, api_method, options={})
def self.fetch(url, options={})

begin
if options[:method] == :post
case options[:method]
when :post
@@log.debug 'url_post=' + url if @@logging
resp = RestClient.post url, options[:params]
when :delete
if options[:params] && options[:params].size > 0
url += '?' + options[:params].map { |k, v| CGI.escape(k.to_s) + '=' + CGI.escape(v.to_s) }.join('&')
end
@@log.debug 'url_delete=' + url if @@logging
resp = RestClient.delete url
else
if options[:params] && options[:params].size > 0
url += '?' + options[:params].map { |k, v| CGI.escape(k.to_s) + '=' + CGI.escape(v.to_s) }.join('&')
Expand Down

0 comments on commit 392feeb

Please sign in to comment.