mirror of
https://github.com/jimeh/twhois.git
synced 2026-02-19 10:56:41 +00:00
Merge branch 'release/v0.0.3'
This commit is contained in:
20
LICENSE
Normal file
20
LICENSE
Normal file
@@ -0,0 +1,20 @@
|
||||
Copyright (c) 2011 Jim Myhrberg.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
12
README.md
12
README.md
@@ -1,6 +1,6 @@
|
||||
# Twhois #
|
||||
|
||||
Whois-like Ruby Gem for Twitter users
|
||||
Whois-like command-line tool and Ruby Gem for Twitter users
|
||||
|
||||
|
||||
## Installation ##
|
||||
@@ -36,6 +36,14 @@ Whois-like Ruby Gem for Twitter users
|
||||
user.nil? #=> true
|
||||
|
||||
|
||||
## Why? ##
|
||||
|
||||
@sxtxixtxcxh: make me a gem
|
||||
@jimeh: no
|
||||
@sxtxixtxcxh: sudo make me a gem
|
||||
@jimeh: ok
|
||||
|
||||
|
||||
## Note on Patches/Pull Requests
|
||||
|
||||
* Fork the project.
|
||||
@@ -49,7 +57,7 @@ Whois-like Ruby Gem for Twitter users
|
||||
|
||||
## License and Copyright
|
||||
|
||||
Copyright (c) 2010 Jim Myhrberg.
|
||||
Copyright (c) 2011 Jim Myhrberg.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
|
||||
45
bin/twhois
45
bin/twhois
@@ -4,25 +4,32 @@ require 'twhois'
|
||||
|
||||
if ARGV.size > 0
|
||||
ARGV.each do |username|
|
||||
user = Twhois.lookup(username)
|
||||
if user
|
||||
puts "@#{user.screen_name}:"
|
||||
puts " Name: #{user.name}"
|
||||
puts " URL: #{user.url}" if user.url
|
||||
puts " Location: #{user.location}" if user.location
|
||||
puts " Description: #{user.description}" if user.description
|
||||
puts " Followers: #{user.followers_count}"
|
||||
puts " Following: #{user.friends_count}"
|
||||
puts " Tweets: #{user.statuses_count}"
|
||||
puts " Last Tweet (#{user.status['created_at']}):"
|
||||
puts " #{user.status['text']}"
|
||||
puts " Timezone: #{user.time_zone}" if user.time_zone
|
||||
puts " Joined On: #{user.created_at}"
|
||||
puts " Profile Picture: #{user.profile_image_url}"
|
||||
puts " Private Account: #{user.protected ? "Yes" : "No"}"
|
||||
else
|
||||
puts "@#{username}:"
|
||||
puts " Not Found"
|
||||
begin
|
||||
user = Twhois.lookup(username)
|
||||
if user
|
||||
puts "@#{user.screen_name}:"
|
||||
puts " Name: #{user.name}"
|
||||
puts " URL: #{user.url}" if user.respond_to?(:url)
|
||||
puts " Profile: http://twitter.com/#{user.screen_name}"
|
||||
puts " Location: #{user.location}" if user.respond_to?(:location)
|
||||
puts " Description: #{user.description}" if user.respond_to?(:description)
|
||||
puts " Followers: #{user.followers_count}"
|
||||
puts " Following: #{user.friends_count}"
|
||||
puts " Tweets: #{user.statuses_count}"
|
||||
if user.respond_to?(:status)
|
||||
puts " Last Tweet (#{user.status['created_at']}):"
|
||||
puts " #{user.status['text']}"
|
||||
end
|
||||
puts " Timezone: #{user.time_zone}" if user.respond_to?(:time_zone)
|
||||
puts " Joined On: #{user.created_at}"
|
||||
puts " Profile Picture: #{user.profile_image_url}"
|
||||
puts " Private Account: #{user.protected ? "Yes" : "No"}"
|
||||
else
|
||||
puts "@#{username}:"
|
||||
puts " Not Found"
|
||||
end
|
||||
rescue Twhois::InvalidUsername => e
|
||||
puts "\"#{username}\" is not a valid Twitter username"
|
||||
end
|
||||
end
|
||||
else
|
||||
|
||||
@@ -12,12 +12,20 @@ module Twhois
|
||||
LOOKUP_HOST = "api.twitter.com"
|
||||
LOOKUP_PATH = "/1/users/show.json?screen_name="
|
||||
|
||||
class InvalidUsername < StandardError; end
|
||||
|
||||
# Lookup a Twitter user by their username.
|
||||
def self.lookup(username)
|
||||
raise InvalidUsername, "Username is invalid" unless valid_username?(username)
|
||||
res = Net::HTTP.start(LOOKUP_HOST) { |http| http.get(LOOKUP_PATH + username) }
|
||||
if res.code == '200'
|
||||
User.new(JSON.parse(res.body))
|
||||
end
|
||||
end
|
||||
|
||||
def self.valid_username?(username)
|
||||
return false if username.match(/^[a-zA-Z0-9_]{1,15}$/).nil?
|
||||
return true
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# encoding: utf-8
|
||||
|
||||
module Twhois
|
||||
VERSION = "0.0.2"
|
||||
VERSION = "0.0.3"
|
||||
end
|
||||
|
||||
@@ -18,8 +18,18 @@ describe Twhois do
|
||||
end
|
||||
|
||||
it "should return error on unknown user" do
|
||||
user = Twhois.lookup('jimehoawhefoahelfhasdf')
|
||||
user = Twhois.lookup('akjsdfkjasdfasd')
|
||||
user.should be_nil
|
||||
end
|
||||
|
||||
it "should raise an exception on invalid usernames" do
|
||||
lambda { # invalid characters
|
||||
user = Twhois.lookup("abc/damn")
|
||||
}.should raise_error(Twhois::InvalidUsername)
|
||||
|
||||
lambda { # longer than 15 characters
|
||||
user = Twhois.lookup("abcasdjfakajsdfasdfasdfa")
|
||||
}.should raise_error(Twhois::InvalidUsername)
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user