lib/mambanation/base.rb in mambanation-0.1.25 vs lib/mambanation/base.rb in mambanation-0.1.26
- old
+ new
@@ -149,11 +149,28 @@
#
def posts(id, query = {})
perform_get("/posts/#{id}.json", :query => query)
end
- def user_posts(id, application_id, query = {})
- perform_get("/users/#{id.to_i}/posts.json", :query => { :application_id => application_id }.merge(query))
+ # options:
+ # application_id Integer,
+ # posts Array, Hash, String
+ def user_posts(id, query = {})
+ query[:posts] = CGI.escape(urlencode_array({:posts => query[:posts]})) if query.is_a?(Hash) && query[:posts]
+
+ perform_get("/users/#{id.to_i}/posts.json", :query => query)
+ end
+
+ def urlencode_array(value_hash)
+ return_string = ''
+ value_hash.each_pair do |k,v|
+ return_string = case v.class.to_s
+ when "Hash" then urlencode_array(v)
+ when "Array" then v.map { |value| value.is_a?(Hash) ? urlencode_array(value) : "#{k}[]=#{value}" }.join('&')
+ else "#{k}[]=#{v}"
+ end
+ end
+ return_string
end
def create_post(id, post, application_id, query = {})
perform_post("/posts", :body => { :user_id => id, :post => post, :application_id => application_id }.merge(query))
end