module Namba::APIMethods

Public Instance Methods

get_events() click to toggle source
# File lib/namba/api_methods.rb, line 25
def get_events
  post_data_to "http://api.namba.#{self.locale}/getEvents.php"
end
get_friends_list(name = self.username) click to toggle source
# File lib/namba/api_methods.rb, line 17
def get_friends_list name = self.username
  get_response_from "http://api.namba.#{self.locale}/friends.php?username=" + name
end
get_last_mail() click to toggle source
# File lib/namba/api_methods.rb, line 33
def get_last_mail
  post_data_to "http://api.namba.#{self.locale}/getLastMail.php"
end
get_new_mail_count() click to toggle source
# File lib/namba/api_methods.rb, line 29
def get_new_mail_count
  post_data_to "http://api.namba.#{self.locale}/getNewMailCount.php"
end
get_user_info(name = self.username) click to toggle source
# File lib/namba/api_methods.rb, line 6
def get_user_info name = self.username
  get_response_from "http://api.namba.#{self.locale}/getUserInfo.php?username=" + name
end
set_status(text) click to toggle source
# File lib/namba/api_methods.rb, line 21
def set_status text
  post_data_to "http://api.namba.#{self.locale}/setStatus.php", { :username => self.username, :password => self.password, :status => text }
end

Private Instance Methods

get_response_from(url) click to toggle source
# File lib/namba/api_methods.rb, line 39
def get_response_from url
  response = Net::HTTP.get_response(URI.parse(url))
  raise_or_return response
end
post_data_to(url, params = { :username => self.username, :password => self.password }) click to toggle source
# File lib/namba/api_methods.rb, line 44
def post_data_to url, params = { :username => self.username, :password => self.password }
  response = Net::HTTP.post_form(URI.parse(url), params)
  raise_or_return response
end
raise_or_return(response) click to toggle source
# File lib/namba/api_methods.rb, line 49
def raise_or_return response
  raise InvalidResponseError, "Invalid response from service" unless response.code == "200"
  if response.body == "null"
    return []
  else
    MultiJson.decode(response.body)
  end
end