Skip to content

Instantly share code, notes, and snippets.

@paul
Created December 16, 2011 20:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paul/1487935 to your computer and use it in GitHub Desktop.
Save paul/1487935 to your computer and use it in GitHub Desktop.
post = Post.detect { |p| p.author == some_author } # GET /posts?author_href=/authors/1234
posts = Post.select { |p| p.q == "Stuff" } # GET /posts?q=Stuff
posts = Post.select { |p| p.title == "Stuff" } # GET /posts (since `title` isn't an available query param, fall back to Enumerable#select)
post = Post.get("http://api.ls.com/posts/1")
posts = Post.get_collection("http://api.ls.com/posts/1")
posts = Post.get_collection(Service.discover("AllPosts"))
posts = Post.get_collection() # auto-discovers based on service_name/uri
# Given service_uri = /posts{?author_href}
posts = Post.select { |p| p.author_href == "/authors/1" } # GET /posts?author_href=/authors/1
posts = Post.select { |p| p.title == "test" } # GET /posts, with block forwarded to Enumerable#select
comments = Post.comments.select { |c| c.author_href = "/authors/1" } # GET /posts/1/comments?author_href=/authors/1
comments = Comment.get_collection(post.comments_href).select { |c| ... } # Equivalent to above
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment