Sha256: 31d5f0899df3e0fc025114d2ba44f2873cec9ac0511fea150236c40f79214136
Contents?: true
Size: 1.46 KB
Versions: 2
Compression:
Stored size: 1.46 KB
Contents
module SchoolFriend module APIMethods class << self def included(base) base.extend(ClassMethods) base.send(:attr_reader, :session) end end module ClassMethods def api_method(*methods) options = methods.last.is_a?(Hash) ? methods.pop : {} namespace = name.sub(/^.+::/, '') namespace[0] = namespace[0].downcase methods.each do |method| call = "session.api_call('#{namespace}.#{method.to_s.gsub(/_([a-z])/) { $1.upcase }}', params" call += options[:session_only] ? ', true)' : ')' class_eval <<-OES, __FILE__, __LINE__ + 1 def #{method}(params = {}) # def get_widgets(params = {}) response = #{call} # response = session.api_call('widget.getWidgets', params, true) if response.is_a?(Net::HTTPSuccess) # if response.is_a?(Net::HTTPSuccess) JSON.parse(response.body, :quirks_mode => true) # JSON(response.body, :quirks_mode => true) else # else response.error! # response.error! end # end end # end OES end end end def initialize(session) @session = session end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
school_friend-0.1.1 | lib/school_friend/api_methods.rb |
school_friend-0.1.0 | lib/school_friend/api_methods.rb |