HighDots Forums  

Twitter by John Nunemaker

Ruby On Rails Talk Ruby On Rails programming language mailing list


Discuss Twitter by John Nunemaker in the Ruby On Rails Talk forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
andkjaer
 
Posts: n/a

Default Twitter by John Nunemaker - 10-31-2009 , 05:35 AM






Hi Railer's,
Im pllaying around with the Twitter API wrapper by John Nunemaker, but
i'm wondering where to put all the logic.
It can't find any examples with this code built into rails.

What im doing now is like this, by the way Im pretty new to rails and
ruby:

def index
@twitter_search = search_twitter_for('#twitter');
end

def show
@twitter_search = search_twitter_for('#twitter');
end

private

def search_twitter_for(query)
Twitter::Search.new(query)
end

Is that the right way to use it?

What if I want to use the OAuth, where do I put the following?

oauth = Twitter::OAuth.new('consumer token', 'consumer secret')
oauth.authorize_from_access('access token', 'access secret')

client = Twitter::Base.new(oauth)

Should i live in a model of it's own or?

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk (AT) googlegroups (DOT) com
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe (AT) googlegroups (DOT) com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply With Quote
  #2  
Old   
Marnen Laibow-Koser
 
Posts: n/a

Default Re: Twitter by John Nunemaker - 11-01-2009 , 11:56 AM






andkjaer wrote:
Quote:
Hi Railer's,
Im pllaying around with the Twitter API wrapper by John Nunemaker, but
i'm wondering where to put all the logic.
It can't find any examples with this code built into rails.

What im doing now is like this, by the way Im pretty new to rails and
ruby:

def index
@twitter_search = search_twitter_for('#twitter');
end

def show
@twitter_search = search_twitter_for('#twitter');
end
You should never have two methods with identical bodies. One should
alias or call the other. Remember, duplication is bad.

make_resourceful would probably help you here too.

Quote:
private

def search_twitter_for(query)
Twitter::Search.new(query)
end
If it were me, I don't think I'd bother with this method. But if you
must have it, the controller is certainly not the right place for it.
If you can't just call Twitter::Search from the controller (why not?),
then make this a model method.

Quote:
Is that the right way to use it?
It may be the right way to use the Twitter gem, but it's the wrong way
to use Rails.

Quote:
What if I want to use the OAuth, where do I put the following?

oauth = Twitter::OAuth.new('consumer token', 'consumer secret')
oauth.authorize_from_access('access token', 'access secret')

client = Twitter::Base.new(oauth)

Should i live in a model of it's own or?
That should probably go in a controller before_filter, although you
might want to wrap it up into a model method to make the controller
cleaner. You might also want to use Authlogic with OAuth.
Best,
--
Marnen Laibow-Koser
http://www.marnen.org
marnen (AT) marnen (DOT) org


--
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk (AT) googlegroups (DOT) com
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe (AT) googlegroups (DOT) com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply With Quote
  #3  
Old   
andkjaer
 
Posts: n/a

Default Re: Twitter by John Nunemaker - 11-01-2009 , 02:48 PM



Hi Marnen,
Thank you for the answer, colud you please explain this a little bit
more: "It may be the right way to use the Twitter gem, but it's the
wrong way
to use Rails."

On 1 Nov., 18:56, Marnen Laibow-Koser <rails-mailing-l...@andreas-
s.net> wrote:
Quote:
andkjaer wrote:
Hi Railer's,
Im pllaying around with the Twitter API wrapper by John Nunemaker, but
i'm wondering where to put all the logic.
It can't find any examples with this code built into rails.

What im doing now is like this, by the way Im pretty new to rails and
ruby:

def index
* *@twitter_search = search_twitter_for('#twitter');
end

def show
* *@twitter_search = search_twitter_for('#twitter');
end

You should never have two methods with identical bodies. *One should
alias or call the other. *Remember, duplication is bad.

make_resourceful would probably help you here too.



private

def search_twitter_for(query)
* *Twitter::Search.new(query)
end

If it were me, I don't think I'd bother with this method. *But if you
must have it, the controller is certainly not the right place for it.
If you can't just call Twitter::Search from the controller (why not?),
then make this a model method.



Is that the right way to use it?

It may be the right way to use the Twitter gem, but it's the wrong way
to use Rails.



What if I want to use the OAuth, where do I put the following?

oauth = Twitter::OAuth.new('consumer token', 'consumer secret')
oauth.authorize_from_access('access token', 'access secret')

client = Twitter::Base.new(oauth)

Should i live in a model of it's own or?

That should probably go in a controller before_filter, although you
might want to wrap it up into a model method to make the controller
cleaner. *You might also want to use Authlogic with OAuth.
Best,
--
Marnen Laibow-Koserhttp://www.marnen.org
mar... (AT) marnen (DOT) org

--
Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk (AT) googlegroups (DOT) com
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe (AT) googlegroups (DOT) com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply With Quote
  #4  
Old   
Marnen Laibow-Koser
 
Posts: n/a

Default Re: Twitter by John Nunemaker - 11-01-2009 , 06:47 PM



andkjaer wrote:
Quote:
Hi Marnen,
Thank you for the answer, colud you please explain this a little bit
more: "It may be the right way to use the Twitter gem, but it's the
wrong way
to use Rails."

I mean that -- as detailed in my earlier post -- you're not really
putting things in the best places for the MVC nature of the framework.

Quote:
On 1 Nov., 18:56, Marnen Laibow-Koser <rails-mailing-l...@andreas-
Best,
--
Marnen Laibow-Koser
http://www.marnen.org
marnen (AT) marnen (DOT) org
--
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk (AT) googlegroups (DOT) com
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe (AT) googlegroups (DOT) com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply With Quote
  #5  
Old   
andkjaer
 
Posts: n/a

Default Re: Twitter by John Nunemaker - 11-02-2009 , 04:19 AM



I know, that's why I ask where to put the different things. What I
don't understand right now is you write "It may be the right way to
use the Twitter gem, but it's the wrong way
to use Rails." How should i then use the GEM the Rails way (Right
way)?

Thanks... :O)

On 2 Nov., 01:47, Marnen Laibow-Koser <rails-mailing-l...@andreas-
s.net> wrote:
Quote:
andkjaer wrote:
Hi Marnen,
Thank you for the answer, colud you please explain this a little bit
more: "It may be the right way to use the Twitter gem, but it's the
wrong way
to use Rails."

I mean that -- as detailed in my earlier post -- you're not really
putting things in the best places for the MVC nature of the framework.

On 1 Nov., 18:56, Marnen Laibow-Koser <rails-mailing-l...@andreas-

Best,
--
Marnen Laibow-Koserhttp://www.marnen.org
mar... (AT) marnen (DOT) org
--
Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk (AT) googlegroups (DOT) com
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe (AT) googlegroups (DOT) com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply With Quote
  #6  
Old   
Marnen Laibow-Koser
 
Posts: n/a

Default Re: Twitter by John Nunemaker - 11-02-2009 , 09:32 AM



andkjaer wrote:
Quote:
I know, that's why I ask where to put the different things. What I
don't understand right now is you write "It may be the right way to
use the Twitter gem, but it's the wrong way
to use Rails." How should i then use the GEM the Rails way (Right
way)?
I already made specific suggestions about moving stuff into the model.
Pleasef
follow them.

Quote:
Thanks... :O)

On 2 Nov., 01:47, Marnen Laibow-Koser <rails-mailing-l...@andreas-
Best,
--
Marnen Laibow-Koser
http://www.marnen.org
marnen (AT) marnen (DOT) org
--
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk (AT) googlegroups (DOT) com
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe (AT) googlegroups (DOT) com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.