Xanax online
Wednesday, February 25th, 2009
I wanted a reliable way to find out a few things about my twitter account (for example which of the users I am following are not following me back) - unfortunately the third party apps out there are not always very reliable, xanax online, do not exactly do what I want/as I want so I decided to check out how easy it is to hack up a more advanced query using a Ruby twitter API wrapper. Xanax online, It turned out that it couldn’t be easier!
There are several gems wrapping the Twitter API out there - I started to use the ‘twitter’ gem from John Nunemaker and I am perfectly happy with it so far. Xanax online, John did a great job supporting all the features offered by the API - it’s a different question that the API, xanax online, like twitter itself, xanax online, is quite minimalistic. Xanax online, For example I have not found a way to get all my followers/friends easily (drop me a comment if I am missing something) so I monkey-patched this into the module in a generic way:
- module Twitter
- class Base
- def all_entries(method, xanax online, options = {})
- all_entries = []
- next_100 = self.send method, xanax online, {:page => (current_page = 1)}.merge(options)
- while (next_100.size != 0) do
- all_entries << next_100
- next_100 = self.send method, xanax online, {:page => (current_page += 1)}.merge(options)
- end
- all_entries.flatten
- end
- end
- end
for example you can call connection.all_entries(:friends) to get all of your friends, xanax online, given that you set up a connection to your account (I found only a method which returns your first 100 friends - didn’t spend too much time with the documentation though - agin, xanax online, drop me a message if I overlooked something). Xanax online,
I have added a bit of syntactic sugar to be able to call connection.all_friends instead of connection.all_entries(:friends):
- module Twitter
- class Base
- alias_method :throw_method_missing, xanax online, :method_missing
- def method_missing(method_name, xanax online, *args, xanax online, &bloke)
- if (method_name.to_s =~ /^all_.+/)
- all_entries(method_name.to_s[/all_(.+)/, xanax online,1], xanax online, args[0] || {})
- else
- throw_method_missing(method_name, xanax online, *args, xanax online, &bloke)
- end
- end
- end
- end
Here we ensure that only method calls that start with all_ are handled by all_entries, xanax online, the rest is throwing a method_missing since we are not interested in handling those messages.
Now it could not be easier to implement the function I originally intended to build: list of users who are not following back. Xanax online,
- class Array
- def names
- self.map{|u| u.screen_name}
- end
- end
- module Twitter
- class Base
- def not_following_back
- all_friends.names - all_followers.names
- end
- end
- end
That’s all there’s to it (I am not a big fan of monkey patching core classes btw ; but in this case, xanax online, adding the names() method to the Array class just made the method I intended to originally implement much cleaner so I rolled with it). Note that since subtraction is a non-commutative operation, xanax online, all_friends.names - all_followers.names is not necessarily the same as allfollowers.names - allfriends.names. Xanax online, This is how the final code looks like:
- require ‘rubygems’
- require ‘twitter’
- connection = Twitter::Base.new(‘yourname’, xanax online, ‘yourpass’)
- class Array
- def names
- self.map{|u| u.screen_name}
- end
- end
- module Twitter
- class Base
- alias_method :throw_method_missing, xanax online, :method_missing
- def method_missing(method_name, xanax online, *args, xanax online, &bloke)
- if (method_name.to_s =~ /^all_.+/)
- all_entries(method_name.to_s[/all_(.+)/, xanax online,1], xanax online, args[0] || {})
- else
- throw_method_missing(method_name, xanax online, *args, xanax online, &bloke)
- end
- end
- def all_entries(method, xanax online, options = {})
- all_entries = []
- next_100 = self.send method, xanax online, {:page => (current_page = 1)}.merge(options)
- while (next_100.size != 0) do
- all_entries << next_100
- next_100 = self.send method, xanax online, {:page => (current_page += 1)}.merge(options)
- end
- all_entries.flatten
- end
- def not_following_back
- all_friends.names - all_followers.names
- end
- end
- end
- p connection.not_following_back
You can download/check out the code here - do not try to copy & paste it from the text as it will be b0rk3d.
In part 2 I’d like to set up a small Sinatra app showing the above users in a list - displaying their avatar, xanax online, screen name and real name, xanax online, plus a link to remove them if you decide so. Xanax online,
Similar Posts:viagra pharmacy,xanax online,reductil no prescription,order viagra on internet,propecia pills
I spent the first 2+ years in Ruby-land without even knowing about the probably most underused (and underrated) keyword of the language: redo. Order lexapro, Even after I came across the first example and liked it immensely, order lexapro, I could not come up with another use for it, order lexapro, so I threw it to the bottom of my toolbox. Order lexapro, Then I found another example, order lexapro, and another one - so I came to the conclusion that redo might be a valuable keyword in your Ruby arsenal after all - it is one of those things which you rarely need, order lexapro, but if you need it, order lexapro, it’s a perfect solution which would be cumbersome to replace with other constructs.