Module: Pupil::Essentials
Instance Method Summary collapse
- #get(url, param = {}) ⇒ Object
- #guess_parameter(parameter) ⇒ Object
- #post(url, param = {}) ⇒ Object
-
#serialize_parameter(parameter) ⇒ String
URL Serialized parameters.
Instance Method Details
#get(url, param = {}) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/pupil/essentials.rb', line 45 def get(url, param={}) param_s = serialize_parameter(param) puts "/1.1/"+url+param_s begin response = @access_token.get("/1.1/"+url+param_s).body rescue => vars raise NetworkError, vars end result = JSON.parse(response) return (result["errors"].nil? rescue true)? result : false end |
#guess_parameter(parameter) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/pupil/essentials.rb', line 34 def guess_parameter(parameter) case parameter.class.to_s when "Fixnum", "Bignum" :user_id when "Symbol", "String" :screen_name else false end end |
#post(url, param = {}) ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/pupil/essentials.rb', line 58 def post(url, param={}) param_s = serialize_parameter(param) begin response = @access_token.post(url+param_s).body rescue => vars raise NetworkError, vars end result = JSON.parse(response) return (result["errors"].nil? rescue true)? result : false end |
#serialize_parameter(parameter) ⇒ String
Returns URL Serialized parameters.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/pupil/essentials.rb', line 11 def serialize_parameter parameter return "" unless parameter.class == Hash ant = Hash.new parameter.each do |key, value| case key.to_sym when :include if value.class == String || Symbol ant[:"include_#{value}"] = "true" break end when :exclude if value.class == String || Symbol ant[:"exclude_#{value}"] = "true" break end else ant[key.to_sym] = value.to_s end end param = ant.inject(""){|k,v|k+"&#{v[0]}=#{URI.escape(v[1])}"}.sub!(/^&/,"?") return param ? param : "" end |