lib/namba/api_methods.rb in namba-1.0.0.1 vs lib/namba/api_methods.rb in namba-1.0.1

- old
+ new

@@ -2,23 +2,23 @@ require 'multi_json' module Namba module APIMethods def get_user_info name = self.username - get_responce_from "http://api.namba.#{self.locale}/getUserInfo.php?username=" + name + get_response_from "http://api.namba.#{self.locale}/getUserInfo.php?username=" + name end def get_user_video name = self.username - get_responce_from "http://api.namba.#{self.locale}/getVideo.php?username=" + name + get_response_from "http://api.namba.#{self.locale}/getVideo.php?username=" + name end def get_user_photo name = self.username - get_responce_from "http://api.namba.#{self.locale}/getPhoto.php?username=" + name + get_response_from "http://api.namba.#{self.locale}/getPhoto.php?username=" + name end def get_friends_list name = self.username - get_responce_from "http://api.namba.#{self.locale}/friends.php?username=" + name + get_response_from "http://api.namba.#{self.locale}/friends.php?username=" + name end def set_status text post_data_to "http://api.namba.#{self.locale}/setStatus.php", { :username => self.username, :password => self.password, :status => text } end @@ -35,16 +35,18 @@ post_data_to "http://api.namba.#{self.locale}/getLastMail.php" end private - def get_responce_from url + def get_response_from url response = Net::HTTP.get_response(URI.parse(url)) + raise InvalidResponseError, "Invalid response from service" unless response.code == "200" MultiJson.decode(response.body) end def post_data_to url, params = { :username => self.username, :password => self.password } response = Net::HTTP.post_form(URI.parse(url), params) + raise InvalidResponseError, "Invalid response from service" unless response.code == "200" MultiJson.decode(response.body) end end end