2
2

More than 5 years have passed since last update.

FacebookOAuth で Publish Action 出来るように拡張する

Posted at

RailsでGemsを拡張する勉強がてらにとりあえずで
- Rails 3.0.3
- FacebookOAuth 0.2.2

使い方 client.me.action namespace, type, { :[ACTION] => url }

config/initializers/facebook_oauth.rb
FacebookOAuth::FacebookObject.class_eval do
  def method_missing(method, *args)
    if method.to_s == 'action'
      namespace = args.shift
      type = args.shift
      params = args.first || {}
      raise ArgumentError if namespace.nil?
      raise ArgumentError if type.nil? 
      @client.send(:_post, "/#{@oid}/#{namespace}:#{type}", params)
      return
    end

    first = args.shift
    params = args.first || {}
    if first and first == :create
      @client.send(:_post, "/#{@oid}/#{method.to_s}", params)
    else
      @client.send(:_get, "/#{@oid}/#{method.to_s}")
    end
  end
end
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2