Module: Twhois
- Defined in:
- lib/twhois.rb,
lib/twhois/user.rb,
lib/twhois/version.rb
Defined Under Namespace
Classes: InvalidUsername, User
Constant Summary collapse
- LOOKUP_HOST =
"api.twitter.com"
- LOOKUP_PATH =
"/1/users/show.json?screen_name="
- VERSION =
"0.0.4"
Class Method Summary collapse
-
.lookup(username) ⇒ Object
Lookup a Twitter user by their username.
- .valid_username?(username) ⇒ Boolean
Class Method Details
.lookup(username) ⇒ Object
Lookup a Twitter user by their username.
18 19 20 21 22 23 24 |
# File 'lib/twhois.rb', line 18 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 |
.valid_username?(username) ⇒ Boolean
26 27 28 29 |
# File 'lib/twhois.rb', line 26 def self.valid_username?(username) return false if username.match(/^[a-zA-Z0-9_]{1,15}$/).nil? return true end |