Class: Me2day::Client
Defined Under Namespace
Classes: InternalServerError, UnauthenticatedError
Constant Summary collapse
- DEFAULT_FORMAT =
'json'
- @@apis =
%w( accept_friendship_request create_comment create_post delete_comment delete_post friendship get_bands get_comments get_friends get_friendship_requests get_latests get_metoos get_person get_posts get_settings metoo noop track_comments )
Class Method Summary collapse
-
.get_auth_url(options = {}) ⇒ Object
attr_accessor :app_key.
Instance Method Summary collapse
-
#get(path, options = {}) ⇒ Object
General helper methods (deprecated).
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #method_missing(method_sym, *args, &block) ⇒ Object
- #post(path, options = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
40 41 42 43 44 45 46 |
# File 'lib/me2day/client.rb', line 40 def initialize(={}) @app_key = [:app_key] @user_id = [:user_id] @user_key = [:user_key] @auth = { :uid => @user_id, :ukey => u_key(@user_key) } self.class.headers 'me2_application_key' => @app_key end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_sym, *args, &block) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/me2day/client.rb', line 48 def method_missing(method_sym, *args, &block) if @@apis.include?(method_sym.to_s) id_part = args.first.is_a?(String) ? "/#{args.first}" : '' = args.last.is_a?(Hash) ? args.last : {} format = ? (.delete(:format) || DEFAULT_FORMAT) : DEFAULT_FORMAT .merge!(@auth) resp = self.class.get("/#{method_sym}#{id_part}.#{format}", :query => ) case resp.response.code.to_s when "200" resp.parsed_response when "401" raise UnauthenticatedError, resp.parsed_response.to_s when "500" raise InternalServerError, resp.parsed_response.to_s else raise "Unknown Error", resp.inspect end else super end end |
Class Method Details
.get_auth_url(options = {}) ⇒ Object
attr_accessor :app_key
33 34 35 36 37 |
# File 'lib/me2day/client.rb', line 33 def get_auth_url(={}) raise "app_key is required" unless [:app_key] self.headers 'me2_application_key' => [:app_key] @auth_url ||= get("/get_auth_url.json")["url"] end |
Instance Method Details
#get(path, options = {}) ⇒ Object
General helper methods (deprecated)
72 |
# File 'lib/me2day/client.rb', line 72 def get(path, ={}); self.class.get(path, ).parsed_response end |
#post(path, options = {}) ⇒ Object
73 |
# File 'lib/me2day/client.rb', line 73 def post(path, ={}); self.class.post(path, ).parsed_response end |