lib/mambanation/base.rb in mambanation-0.0.5 vs lib/mambanation/base.rb in mambanation-0.1.0
- old
+ new
@@ -2,21 +2,26 @@
class Base
extend Forwardable
def_delegators :client, :get, :post, :put, :delete
- attr_reader :client
+ attr_reader :client, :fbs_cookies
- def initialize(client)
+ def initialize(client, fbs_cookies = nil)
@client = client
+ @fbs_cookies = fbs_cookies
end
#
# Users
#
- def create_user(user)
- perform_post("/users", :body => { :user => user })
+ # def create_user(user)
+ # perform_post("/users", :body => { :user => user })
+ # end
+
+ def current_user
+ perform_post("/users/me") if !fbs_cookies.nil?
end
def user_by_facebook_id(facebook_id, query = {})
perform_get("/users/find_by?facebook_id=#{facebook_id.to_i}", :query => query)
end
@@ -180,23 +185,29 @@
def build_multipart_bodies(parts) self.class.build_multipart_bodies(parts) end
private
+ def request_options opts={}
+ opts[:headers] ||= {}
+ opts[:headers].merge! "FB-Cookies" => fbs_cookies
+ opts
+ end
+
def perform_get(path, options={})
- MambaNation::Request.get(self, path, options)
+ MambaNation::Request.get(self, path, request_options(options))
end
def perform_post(path, options={})
- MambaNation::Request.post(self, path, options)
+ MambaNation::Request.post(self, path, request_options(options))
end
def perform_put(path, options={})
- MambaNation::Request.put(self, path, options)
+ MambaNation::Request.put(self, path, request_options(options))
end
def perform_delete(path, options={})
- MambaNation::Request.delete(self, path, options)
+ MambaNation::Request.delete(self, path, request_options(options))
end
end
end