twhois 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/.rvmrc ADDED
@@ -0,0 +1,2 @@
1
+ rvm gemset use twhois
2
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in twhois.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # Twhois #
2
+
3
+ Whois-like Ruby Gem for Twitter users
4
+
5
+
6
+ ## Installation ##
7
+
8
+ gem install twhois
9
+
10
+
11
+ ## Usage ##
12
+
13
+ ### Command line ###
14
+
15
+ $ twhois jimeh darthvader
16
+ @jimeh:
17
+ Name: Jim Myhrberg
18
+ URL: http://jimeh.me/
19
+ [...]
20
+ @darthvader:
21
+ Name: Darth Vader
22
+ Location: Empire, CO
23
+ [...]
24
+
25
+ ### Ruby
26
+
27
+ require 'twhois'
28
+
29
+ # Lookup a user
30
+ user = Twhois.lookup('jimeh')
31
+ user.screen_name #=> jimeh
32
+ user.name #=> Jim Myhrberg
33
+
34
+ # Lookup a user that doesn't exist
35
+ user = Twhois.lookup('hadsfasdfauwhgiuahwg')
36
+ user.nil? #=> true
37
+
38
+
39
+ ## Note on Patches/Pull Requests
40
+
41
+ * Fork the project.
42
+ * Make your feature addition or bug fix.
43
+ * Add tests for it. This is important so I don't break it in a
44
+ future version unintentionally.
45
+ * Commit, do not mess with rakefile, version, or history.
46
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
47
+ * Send me a pull request. Bonus points for topic branches.
48
+
49
+
50
+ ## License and Copyright
51
+
52
+ Copyright (c) 2010 Jim Myhrberg.
53
+
54
+ Permission is hereby granted, free of charge, to any person obtaining
55
+ a copy of this software and associated documentation files (the
56
+ "Software"), to deal in the Software without restriction, including
57
+ without limitation the rights to use, copy, modify, merge, publish,
58
+ distribute, sublicense, and/or sell copies of the Software, and to
59
+ permit persons to whom the Software is furnished to do so, subject to
60
+ the following conditions:
61
+
62
+ The above copyright notice and this permission notice shall be
63
+ included in all copies or substantial portions of the Software.
64
+
65
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
66
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
67
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
68
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
69
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
70
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
71
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,38 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ #
5
+ # Rspec
6
+ #
7
+
8
+ require 'rspec/core/rake_task'
9
+ RSpec::Core::RakeTask.new(:spec) do |spec|
10
+ spec.pattern = 'spec/**/*_spec.rb'
11
+ end
12
+
13
+ task :default => [:start, :spec, :stop]
14
+
15
+
16
+ #
17
+ # Yard
18
+ #
19
+
20
+ begin
21
+ require 'yard'
22
+ YARD::Rake::YardocTask.new
23
+ rescue LoadError
24
+ task :yardoc do
25
+ abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
26
+ end
27
+ end
28
+
29
+
30
+ #
31
+ # Misc.
32
+ #
33
+
34
+ desc "Start an irb console with Twhois pre-loaded."
35
+ task :console do
36
+ exec "irb -r spec/spec_helper"
37
+ end
38
+ task :c => :console
data/bin/twhois ADDED
@@ -0,0 +1,26 @@
1
+ #! /usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'twhois'
4
+
5
+ ARGV.each do |username|
6
+ user = Twhois.lookup(username)
7
+ if user
8
+ puts "@#{user.screen_name}:"
9
+ puts " Name: #{user.name}"
10
+ puts " URL: #{user.url}" if user.url
11
+ puts " Location: #{user.location}" if user.location
12
+ puts " Description: #{user.description}" if user.description
13
+ puts " Followers: #{user.followers_count}"
14
+ puts " Following: #{user.friends_count}"
15
+ puts " Tweets: #{user.statuses_count}"
16
+ puts " Last Tweet (#{user.status['created_at']}):"
17
+ puts " #{user.status['text']}"
18
+ puts " Timezone: #{user.time_zone}" if user.time_zone
19
+ puts " Joined On: #{user.created_at}"
20
+ puts " Profile Picture: #{user.profile_image_url}"
21
+ puts " Private Account: #{user.protected ? "Yes" : "No"}"
22
+ else
23
+ puts "@#{username}:"
24
+ puts " Not Found"
25
+ end
26
+ end
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+
3
+ module Twhois
4
+ # Kinda acts like the Hashie gem
5
+ class User
6
+
7
+ def initialize(hash)
8
+ hash.keys.each do |key|
9
+ self.class.send(:attr_accessor, key.to_sym)
10
+ self.send("#{key}=", hash[key])
11
+ end
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ # encoding: utf-8
2
+
3
+ module Twhois
4
+ VERSION = "0.0.1"
5
+ end
data/lib/twhois.rb ADDED
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'net/http'
5
+ require 'json'
6
+
7
+ require 'twhois/user'
8
+ require 'twhois/version'
9
+
10
+ module Twhois
11
+
12
+ LOOKUP_HOST = "api.twitter.com"
13
+ LOOKUP_PATH = "/1/users/show.json?screen_name="
14
+
15
+ # Lookup a Twitter user by their username.
16
+ def self.lookup(username)
17
+ res = Net::HTTP.start(LOOKUP_HOST) { |http| http.get(LOOKUP_PATH + username) }
18
+ if res.code == '200'
19
+ User.new(JSON.parse(res.body))
20
+ end
21
+ end
22
+
23
+ end
@@ -0,0 +1,9 @@
1
+ # add project-relative load paths
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+
5
+ # require stuff
6
+ require 'twhois'
7
+ require 'rspec'
8
+ require 'rspec/autorun'
9
+
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Twhois do
4
+
5
+ it "should find author's twitter account" do
6
+ user = Twhois.lookup('jimeh')
7
+ user.screen_name.should == "jimeh"
8
+ user.lang.should == "en"
9
+ user.profile_image_url.should_not be_nil
10
+ user.name.should_not be_nil
11
+ user.location.should_not be_nil
12
+ user.url.should_not be_nil
13
+ user.followers_count.should_not be_nil
14
+ user.description.should_not be_nil
15
+ user.time_zone.should_not be_nil
16
+ user.profile_background_image_url.should_not be_nil
17
+ # ...that should be enough
18
+ end
19
+
20
+ it "should return error on unknown user" do
21
+ user = Twhois.lookup('jimehoawhefoahelfhasdf')
22
+ user.should be_nil
23
+ end
24
+
25
+ end
data/twhois.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'twhois/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'twhois'
7
+ s.version = Twhois::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ['Jim Myhrberg']
10
+ s.email = ['contact@jimeh.me']
11
+ s.homepage = 'https://github.com/jimeh/twhois'
12
+ s.summary = 'Whois-like Ruby Gem for Twitter users'
13
+ s.description = 'Whois-like Ruby Gem for Twitter users'
14
+
15
+ s.rubyforge_project = 'twhois'
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ['lib']
21
+
22
+ s.add_runtime_dependency 'json_pure', '>= 1.0.0'
23
+
24
+ s.add_development_dependency 'rspec', '>= 2.5.0'
25
+ s.add_development_dependency 'yard', '>= 0.6.4'
26
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: twhois
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Jim Myhrberg
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-03-02 00:00:00 +00:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: json_pure
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 23
30
+ segments:
31
+ - 1
32
+ - 0
33
+ - 0
34
+ version: 1.0.0
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: rspec
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 27
46
+ segments:
47
+ - 2
48
+ - 5
49
+ - 0
50
+ version: 2.5.0
51
+ type: :development
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: yard
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 15
62
+ segments:
63
+ - 0
64
+ - 6
65
+ - 4
66
+ version: 0.6.4
67
+ type: :development
68
+ version_requirements: *id003
69
+ description: Whois-like Ruby Gem for Twitter users
70
+ email:
71
+ - contact@jimeh.me
72
+ executables:
73
+ - twhois
74
+ extensions: []
75
+
76
+ extra_rdoc_files: []
77
+
78
+ files:
79
+ - .gitignore
80
+ - .rvmrc
81
+ - Gemfile
82
+ - README.md
83
+ - Rakefile
84
+ - bin/twhois
85
+ - lib/twhois.rb
86
+ - lib/twhois/user.rb
87
+ - lib/twhois/version.rb
88
+ - spec/spec_helper.rb
89
+ - spec/twhois_spec.rb
90
+ - twhois.gemspec
91
+ has_rdoc: true
92
+ homepage: https://github.com/jimeh/twhois
93
+ licenses: []
94
+
95
+ post_install_message:
96
+ rdoc_options: []
97
+
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ hash: 3
106
+ segments:
107
+ - 0
108
+ version: "0"
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ hash: 3
115
+ segments:
116
+ - 0
117
+ version: "0"
118
+ requirements: []
119
+
120
+ rubyforge_project: twhois
121
+ rubygems_version: 1.5.0
122
+ signing_key:
123
+ specification_version: 3
124
+ summary: Whois-like Ruby Gem for Twitter users
125
+ test_files:
126
+ - spec/spec_helper.rb
127
+ - spec/twhois_spec.rb