lib/mambanation/base.rb in mambanation-0.1.19 vs lib/mambanation/base.rb in mambanation-0.1.20
- old
+ new
@@ -9,44 +9,48 @@
def initialize(client, fbs_cookies = nil)
@client = client
@fbs_cookies = fbs_cookies
end
+ # Class method to fetch current user based on cookie
+ def self.current_user(client, fbs_cookies)
+ MambaNation::Base.new(client, fbs_cookies).current_user
+ end
+
#
# Famous
#
def famous(query = {})
perform_get("/users/famous.json", :query => query)
end
- def current_user
- perform_get("/users/me") unless fbs_cookies.nil?
+ def current_user(query = {})
+ perform_get("/users/me", :query => query) unless 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
def user_by_email(email, query = {})
perform_get("/users/find_by?facebook_id=#{email}", :query => query)
end
- # Options: user_id, facebook_id
def user(id, query = {})
perform_get("/users/#{id.to_i}.json", :query => query)
end
alias_method :user_by_id, :user
- def user_set_websession(id, credentials)
- perform_post("/users/#{id.to_i}/update_websession", :body => { :user => { :user_credentials => credentials }})
+ def user_set_websession(id, credentials, query = {})
+ perform_post("/users/#{id.to_i}/update_websession", :body => { :user => { :user_credentials => credentials } }.merge(query))
end
#
# User actions
#
- def user_last_login(id)
- perform_get("/users/#{id.to_i}/last_login.json")
+ def user_last_login(id, query = {})
+ perform_get("/users/#{id.to_i}/last_login.json", :query => query)
end
def user_chats(id, query = {})
perform_get("/users/#{id.to_i}/chats.json", :query => query)
end
@@ -71,11 +75,11 @@
perform_put("/users/#{id.to_i}/suspend")
end
# Options: user_id, :limit
def user_media(id, query = {})
- perform_get("/users/#{id.to_i}/media.json", :query => query)
+ perform_get("/users/#{id.to_i}/media.json", :query => {}.merge(query))
end
# Options: user_id, facebook_id
def user_friends(id, query = {})
perform_get("/users/#{id.to_i}/friends.json", :query => query)
@@ -83,12 +87,12 @@
#
# Facets
#
# Options: facet_id
- def facet(id)
- perform_get("/facets/#{id.to_i}.json")
+ def facet(id, query = {})
+ perform_get("/facets/#{id.to_i}.json", :query => query)
end
def famous_facets(query = {})
perform_get("/facets/famous.json", :query => query)
end
@@ -118,25 +122,24 @@
end
#
# Mission Statuses
#
-
- def mission_status user_id, mission_id, query = {}
- perform_get("/users/#{user_id.to_i}/mission_status/#{mission_id}.json", :query => query)
+ def mission_status(id, mission_id, query = {})
+ perform_get("/users/#{id.to_i}/mission_status/#{mission_id}.json", :query => query)
end
def mission_statuses(id, query = {})
perform_get("/users/#{id.to_i}/mission_statuses.json", :query => query)
end
def missions_family_statuses(id, query = {})
perform_get("/users/#{id.to_i}/missions_family_statuses.json", :query => query)
end
- def mission_start!(id, mission_id)
- perform_put("/users/#{id.to_i}/mission_statuses/#{mission_id.to_i}/start")
+ def mission_start!(id, mission_id, query = {})
+ perform_put("/users/#{id.to_i}/mission_statuses/#{mission_id.to_i}/start", :query => {}.merge(query))
end
#
# Posts
#
@@ -146,23 +149,23 @@
def user_posts(id, application_id, query = {})
perform_get("/users/#{id.to_i}/posts.json", :query => { :application_id => application_id }.merge(query))
end
- def create_post(id, post, application_id)
- perform_post("/posts", :body => { :user_id => id, :post => post, :application_id => application_id })
+ def create_post(id, post, application_id, query = {})
+ perform_post("/posts", :body => { :user_id => id, :post => post, :application_id => application_id }.merge(query))
end
- def publish_post(id, stream_id)
- perform_post("/posts/#{id}/publish.json", :body => { :post => { :stream_id => stream_id } })
+ def publish_post(id, stream_id, query = {})
+ perform_post("/posts/#{id}/publish.json", :body => { :post => { :stream_id => stream_id } }.merge(query))
end
#
# Roles
#
- def user_roles(id)
- perform_get("/users/#{id.to_i}/roles.json")
+ def user_roles(id, query = {})
+ perform_get("/users/#{id.to_i}/roles.json", :query => query)
end
#
# Users System Messages
#
@@ -172,12 +175,12 @@
def user_unread_system_messages(id, query = {})
perform_get("/users/#{id.to_i}/unread_system_messages.json", :query => query)
end
- def read_user_message(id, message_id)
- perform_post("/users/#{id.to_i}/messages/#{message_id.to_i}/read.json", :body => {})
+ def read_user_message(id, message_id, query = {})
+ perform_post("/users/#{id.to_i}/messages/#{message_id.to_i}/read.json", :body => {}.merge(query))
end
#
# User Announcements
#
@@ -197,15 +200,15 @@
when file =~ /\.gif$/ then 'image/gif'
when file =~ /\.png$/ then 'image/png'
else 'application/octet-stream'
end
end
-
+
def mime_type(f) self.class.mime_type(f) end
-
+
CRLF = "\r\n"
-
+
def self.build_multipart_bodies(parts)
boundary = Time.now.to_i.to_s(16)
body = ""
parts.each do |key, value|
esc_key = CGI.escape(key.to_s)
@@ -223,10 +226,10 @@
{
:body => body,
:headers => {"Content-Type" => "multipart/form-data; boundary=#{boundary}"}
}
end
-
+
def build_multipart_bodies(parts) self.class.build_multipart_bodies(parts) end
private
def request_options(opts={})