Nested members?

4 views
Skip to first unread message

Jeroen van Dijk

unread,
Dec 22, 2010, 10:01:32 AM12/22/10
to restfulie
Hi all,

I'm currently implementing an activity stream which I like to combine
with Restfulie. I think the tokamak dsl is really nice and useful.
What I didn't find though was how to add nested member objects.

In the following gist I show what I mean and what i would like to see:
https://gist.github.com/751614

The parts below the comments 'object' and 'indirect object' feel like
a hack. Is this missing functionality from Restfulie or am I doing it
wrong?

Any hints?

Cheers,
Jeroen


Ps Guilherme thanks for pointing me to this list

Luis Cipriani

unread,
Dec 22, 2010, 10:24:05 AM12/22/10
to rest...@googlegroups.com
You could obtain what you show on gist doing this:

collection(@activities) do |collection|
  collection.members do |member, activity|
    member.values { |values|
      values.id activity.id
      values.title activity.title

      # ACTOR
      values.actor { 
values.type activity.actor_type.downcase
values.id activity.actor_id
}

      # VERB
      values.verbs activity.verbs

      # OBJECT
      values.object {
values.type activity.object_type.downcase
values.id activity.object_id 
values.content activity.object.content if activity.object_content?
}

      # Indirect OBJECT
      if activity.indirect_object
        values.indirect_object {
values.type activity.indirect_object_type.downcase
values.id activity.indirect_object_id
}
      end

    }
  end
  

end

Regards,

Cipriani

Guilherme Silveira

unread,
Dec 23, 2010, 12:32:59 PM12/23/10
to rest...@googlegroups.com
Hi guys,

I've extracted tokamak so it has its own project now and can also be
used by other Restfulie client and servers:
https://github.com/caelum/tokamak

It is the same code as earlier but in another namespace. As soon as we
get Restfulie 1.0 out (just missing some extra docs) it will be
already using this namespace.

Great work.

Btw, I've used the example mentioned here to create the README file at github.

Regards

Guilherme Silveira
Caelum | Ensino e Inovação
http://www.caelum.com.br/

Jeroen van Dijk

unread,
Dec 24, 2010, 5:30:01 AM12/24/10
to rest...@googlegroups.com
Thanks for the comments guys. Everything you suggested works fine.

I have one question about the new gem and the role of the server library. I currently only use Restfulie for the tokamak  templates, I do not use the act_as_restfulie controller extension. I'm wondering whether the server (controller) part of Restfulie does really more then e.g. https://github.com/josevalim/inherited_resources (which I'm using)? To me as an outsider it feels this part of the library is not really needed.

Regards,
Jeroen

Guilherme Silveira

unread,
Dec 24, 2010, 7:55:05 AM12/24/10
to rest...@googlegroups.com

hi Jeroen, how are you doing?

The question makes sense and the answer depends on how you use it

Those who use sinatra or pure rack, tokamak alone will do the trick.

If you are using rails 3, the restfulie gem adds a few responder traits, as cache, etag and some navigation controls by default.it also patches rails to support patch. I have been using the traits to enhance the http response with conventions.another example of that is the 404 trait that suggests similar resources.

Finally, the client side is also in the gem.

So it depends on what you want to achieve...

Suggestions?

Regards

Le 24 déc. 2010 10:21, "Jeroen van Dijk" <jeroentj...@gmail.com> a écrit :

Thanks for the comments guys. Everything you suggested works fine.

I have one question about the new gem and the role of the server library. I currently only use Restfulie for the tokamak  templates, I do not use the act_as_restfulie controller extension. I'm wondering whether the server (controller) part of Restfulie does really more then e.g. https://github.com/josevalim/inherited_resources (which I'm using)? To me as an outsider it feels this part of the library is not really needed.

Regards,

Jeroen



On Thu, Dec 23, 2010 at 6:32 PM, Guilherme Silveira <guilherme...@caelum.com.br> wrote:
>

> ...

Jeroen van Dijk

unread,
Dec 24, 2010, 10:51:43 AM12/24/10
to rest...@googlegroups.com
Hi Guilherme, 

On Fri, Dec 24, 2010 at 1:55 PM, Guilherme Silveira <guilherme...@caelum.com.br> wrote:

hi Jeroen, how are you doing?

I'm good thanks :) How are you?
 

The question makes sense and the answer depends on how you use it

Those who use sinatra or pure rack, tokamak alone will do the trick.

Cool, did you already publish it as a separate gem to rubygems.org

If you are using rails 3, the restfulie gem adds a few responder traits, as cache, etag and some navigation controls by default.it also patches rails to support patch. I have been using the traits to enhance the http response with conventions.another example of that is the 404 trait that suggests similar resources.

Finally, the client side is also in the gem.

So it depends on what you want to achieve...

Suggestions?

I think I need to be more familiar with the complete library before I can really say what parts are necessary and what parts are already available in other libraries. I was just wondering. I'll give a more informed opinion when a I no more :)

Jeroen 

Guilherme Silveira

unread,
Jan 28, 2011, 8:44:07 AM1/28/11
to restfulie
Hi Jeroen,

I spoke to Luiz and he gave the following suggestion for inner collections:

values.users []
base.users.each do |user|
values.user do
end
end

Is your problem with top level or inner collections?

Regards

Guilherme Silveira
Caelum | Ensino e Inovação
http://www.caelum.com.br/

Jeroen van Dijk

unread,
Feb 2, 2011, 6:00:38 AM2/2/11
to rest...@googlegroups.com
Hi Guilherme, 

The original solution Luis Cipriani pointed out worked for me for the original problem of nested members. However I did get a problem with nested collections as well. The other email thread is about custom top level collections, but inner collections are also a bit tricky. Your proposed solution doesn't work for me (I tried it with Restfulie 1.0.0). However the following did work for me https://gist.github.com/807545

Is it just me or does the current dsl feel a bit verbose? Does this have a technical reason, is it necessary? I'll think about possible alternatives when I have a better understanding of how Tokamak works.

Regards,

Jeroen

Guilherme Silveira

unread,
Feb 3, 2011, 8:27:44 AM2/3/11
to restfulie
Hi Jeroen,

I've got the same feeling. The problem is that in order to be less
verbose, it need a few hacks in some corner cases.

So we should be aiming to minimize this code:

if comments = @comments.try(:[], activity.id)
member.members(:root => "comments", :collection => comments) do
|member, comment|
member.values { |comment_values|
comment_values.timestamp comment.created_at.to_i

Do you have any suggestion on how you would like it to look like?
I can see no drawback on removing one line from there (the values definition):

if comments = @comments.try(:[], activity.id)
member.members(:root => "comments", :collection => comments) do
|member, comment|
member.timestamp comment.created_at.to_i

I have implemented it and went a little bit more deeper, supporting
also the next one, but then there are some scope issues:

if comments = @comments.try(:[], activity.id)
members(:root => "comments", :collection => comments) do |comment|
timestamp comment.created_at.to_i

Let me know some suggestions on how it could look like and I will try
to implement it. I can move forward with the second one - it has
already been implemented and is backward compatible - does it already
help a little bit?

Regards

~Guilherme

Reply all
Reply to author
Forward
0 new messages