hangout 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.rbenv-version ADDED
@@ -0,0 +1 @@
1
+ 1.9.3-p125
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source :rubygems
2
+
3
+ gem 'foursquare2'
4
+
5
+ group "development" do
6
+ gem "rake"
7
+ end
8
+
9
+ group "test" do
10
+ gem "minitest"
11
+ gem "hashie"
12
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,28 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ addressable (2.2.7)
5
+ faraday (0.7.6)
6
+ addressable (~> 2.2)
7
+ multipart-post (~> 1.1)
8
+ rack (~> 1.1)
9
+ faraday_middleware (0.8.4)
10
+ faraday (>= 0.7.4, < 0.9)
11
+ foursquare2 (1.3.6)
12
+ faraday (>= 0.6, < 0.8)
13
+ faraday_middleware (>= 0.8)
14
+ hashie (~> 1.0)
15
+ hashie (1.2.0)
16
+ minitest (2.11.3)
17
+ multipart-post (1.1.5)
18
+ rack (1.4.1)
19
+ rake (0.9.2.2)
20
+
21
+ PLATFORMS
22
+ ruby
23
+
24
+ DEPENDENCIES
25
+ foursquare2
26
+ hashie
27
+ minitest
28
+ rake
data/README ADDED
@@ -0,0 +1,18 @@
1
+ ___ ___ ___ ___ ___ ___ ___
2
+ /\__\ /\ \ /\__\ /\ \ /\ \ /\__\ /\ \
3
+ /:/__/_ /::\ \ /:| _|_ /::\ \ /::\ \ /:/ _/_ \:\ \
4
+ /::\/\__\ /::\:\__\ /::|/\__\ /:/\:\__\ /:/\:\__\ /:/_/\__\ /::\__\
5
+ \/\::/ / \/\::/ / \/|::/ / \:\:\/__/ \:\/:/ / \:\/:/ / /:/\/__/
6
+ /:/ / /:/ / |:/ / \::/ / \::/ / \::/ / \/__/
7
+ \/__/ \/__/ \/__/ \/__/ \/__/ \/__/
8
+
9
+ Hangout is a simple command line interface to your friend's recent check-ins on
10
+ FourSquare. All of the cool kids are using it and you just have to go and
11
+ hangout with them.
12
+
13
+ Usage
14
+ -----
15
+
16
+ Just bash the following command into your prompt to join all of the cool kids.
17
+
18
+ $ hangout
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'rake/testtask'
2
+
3
+ task :default => :test
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs.push "lib"
7
+ t.test_files = FileList['test/*_test.rb']
8
+ t.verbose = true
9
+ end
data/bin/hangout ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'bundler/setup'
4
+
5
+ require 'foursquare2'
6
+
7
+ $:.unshift File.join File.dirname(__FILE__), '../lib'
8
+ require 'hangout'
9
+
10
+ CLIENT_ID = "KBLF31MGQW5WFW3RUH5CLL2QBXG1JG2L0DEJLIY1S5MXPFX0"
11
+ REDIRECT_URI = "http://xoeb.us/hangout/callback"
12
+ CONFIG_FILE = File.expand_path("~/.foursquare")
13
+
14
+ client = Foursquare2::Client.new(:oauth_token => get_user_token)
15
+
16
+ recent_checkins = client.recent_checkins :afterTimestamp => Time.now.to_i - 14400
17
+
18
+ recent_checkins.each do |checkin|
19
+ c = Hangout::Checkin.parse(checkin)
20
+ puts c
21
+ end
22
+
23
+
data/hangout.gemspec ADDED
@@ -0,0 +1,19 @@
1
+ lib = File.expand_path('../lib/', __FILE__)
2
+ $:.unshift lib unless $:.include?(lib)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "hangout"
6
+ s.version = "0.0.1"
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["Chris Brown"]
9
+ s.email = ["xoebus@xoeb.us"]
10
+ s.homepage = "https://github.com/xoebus/hangout"
11
+ s.summary = "Find nearby foursquare friends to hangout with."
12
+ s.description = "Find foursquare friends that have checked in nearby you recently. More features soon."
13
+
14
+ s.add_dependency('foursquare2')
15
+
16
+ s.require_path = 'lib'
17
+ s.bindir = 'bin'
18
+ s.files = `git ls-files`.split("\n")
19
+ end
@@ -0,0 +1,22 @@
1
+ def authorize client_id, redirect_uri
2
+ `open https://foursquare.com/oauth2/authenticate?client_id=#{client_id}&response_type=token&redirect_uri=#{redirect_uri}`
3
+ end
4
+
5
+ def get_user_token
6
+ if File.exists? CONFIG_FILE
7
+ File.read CONFIG_FILE
8
+ else
9
+ puts "Well shucks, looks like you haven't used this little app before."
10
+ puts "I'm going to open the browser now and grab a number for you. Could"
11
+ puts "you do me a favour and paste it in here?"
12
+ puts
13
+ puts "<Press return to open your browser...>"
14
+ gets
15
+ authorize CLIENT_ID, REDIRECT_URI
16
+ puts "Paste the key in here:"
17
+ key = gets
18
+ File.new(CONFIG_FILE) do |f|
19
+ f.write(key)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,35 @@
1
+ module Hangout
2
+ class InvalidCheckinError < StandardError; end;
3
+
4
+ class Checkin
5
+ attr_reader :user_name
6
+ attr_reader :created_at
7
+ attr_reader :location
8
+
9
+ def self.parse checkin
10
+ new.parse checkin
11
+ end
12
+
13
+ def parse(checkin)
14
+ begin
15
+ @user_name = [checkin.user.firstName, checkin.user.lastName].join " "
16
+ @created_at = Time.at(checkin.createdAt)
17
+ @location = checkin.venue.name
18
+ rescue NoMethodError => e
19
+ raise InvalidCheckinError
20
+ end
21
+
22
+ self
23
+ end
24
+
25
+ def time
26
+ hour = @created_at.hour.to_s.rjust(2, '0')
27
+ mins = @created_at.min.to_s.rjust(2, '0')
28
+ "#{hour}:#{mins}"
29
+ end
30
+
31
+ def to_s
32
+ "#{user_name} - #{location} (#{time})"
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,7 @@
1
+ class String
2
+ [:gray, :red, :green, :yellow, :blue, :purple, :cyan, :white].each_with_index do |color, i|
3
+ define_method color do
4
+ "\033[1;#{30+i}m#{self}\033[0m"
5
+ end
6
+ end if $stdin.tty?
7
+ end
data/lib/hangout.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'hangout/color'
2
+ require 'hangout/checkin'
3
+ require 'hangout/auth'
@@ -0,0 +1,55 @@
1
+ require 'minitest/autorun'
2
+
3
+ require 'hashie'
4
+ require 'hangout'
5
+
6
+ module Hangout
7
+ class CheckinTest < MiniTest::Unit::TestCase
8
+ def setup
9
+ @hash_good = good_hash
10
+ @hash_bad = bad_hash
11
+ end
12
+
13
+ def test_parse
14
+ c = Checkin.parse(@hash_good)
15
+
16
+ assert_equal c.user_name, "Chris Brown"
17
+ assert_equal c.time, "05:04"
18
+ assert_equal c.location, "Disneyland!"
19
+ end
20
+
21
+ def test_parse_missing_attributes
22
+ assert_raises (InvalidCheckinError) {
23
+ c = Checkin.parse(@hash_bad)
24
+ }
25
+ end
26
+
27
+ def test_string
28
+ c = Checkin.parse(@hash_good)
29
+ s = c.to_s
30
+
31
+ assert_match /Chris Brown/, s
32
+ assert_match /05:04/, s
33
+ assert_match /Disneyland!/, s
34
+
35
+ # Check we aren't outputting an ugly date format.
36
+ refute_match /\d\d-\d\d/, s
37
+ end
38
+
39
+ private
40
+ def good_hash
41
+ h = ::Hashie::Mash.new
42
+ h.user!.firstName = "Chris"
43
+ h.user!.lastName = "Brown"
44
+ h.createdAt = Time.local(2008, 9, 1, 5, 4, 35).to_i
45
+ h.venue!.name = "Disneyland!"
46
+
47
+ h
48
+ end
49
+
50
+ def bad_hash
51
+ h = good_hash.name = nil
52
+ h
53
+ end
54
+ end
55
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hangout
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Chris Brown
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: foursquare2
16
+ requirement: &70292333398320 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70292333398320
25
+ description: Find foursquare friends that have checked in nearby you recently. More
26
+ features soon.
27
+ email:
28
+ - xoebus@xoeb.us
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - .rbenv-version
34
+ - Gemfile
35
+ - Gemfile.lock
36
+ - README
37
+ - Rakefile
38
+ - bin/hangout
39
+ - hangout.gemspec
40
+ - lib/hangout.rb
41
+ - lib/hangout/auth.rb
42
+ - lib/hangout/checkin.rb
43
+ - lib/hangout/color.rb
44
+ - test/checkin_test.rb
45
+ homepage: https://github.com/xoebus/hangout
46
+ licenses: []
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubyforge_project:
65
+ rubygems_version: 1.8.11
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: Find nearby foursquare friends to hangout with.
69
+ test_files: []