Twitter by John Nunemaker

View: New views
6 Messages — Rating Filter:   Alert me  

Twitter by John Nunemaker

by andkjaer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


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@...
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Twitter by John Nunemaker

by Adam Akhtar-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


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-Koser
http://www.marnen.org
marnen@...


--
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@...
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Twitter by John Nunemaker

by andkjaer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


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:

> 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...@...
>
> --
> 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@...
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Twitter by John Nunemaker

by Adam Akhtar-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


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-Koser
http://www.marnen.org
marnen@...
--
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@...
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Twitter by John Nunemaker

by andkjaer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


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:

> 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...@...
> --
> 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@...
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Twitter by John Nunemaker

by Adam Akhtar-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


andkjaer wrote:
> 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.

>
> Thanks... :O)
>
> On 2 Nov., 01:47, Marnen Laibow-Koser <rails-mailing-l...@andreas-

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
marnen@...
--
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@...
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---