Skip to content

Commit

Permalink
Merge pull request #1 from michaelparenteau/hey-buddy
Browse files Browse the repository at this point in the history
Bringing back the tweets - Thanks Rob!
  • Loading branch information
michaelparenteau committed Dec 6, 2011
2 parents 7b16408 + 268243d commit 30bb422
Show file tree
Hide file tree
Showing 8 changed files with 158 additions and 18 deletions.
14 changes: 13 additions & 1 deletion Gemfile
@@ -1,9 +1,21 @@
source "http://rubygems.org"
gem "i18n"
gem "activesupport", "~> 3.1", :require => nil
gem "rake"
gem "rack"
gem "sinatra", "1.1.2", :require => "sinatra"
gem "haml"
gem "sinatra-static-assets"
gem "maruku"
gem "swish"
gem "twitter"
gem "heroku"
gem "heroku"

group :test do
gem "fakeweb"
gem "rack-test"
gem "mocha"
gem "rspec"
gem "guard"
gem "guard-rspec"
end
33 changes: 33 additions & 0 deletions Gemfile.lock
@@ -1,16 +1,24 @@
GEM
remote: http://rubygems.org/
specs:
activesupport (3.1.3)
multi_json (~> 1.0)
addressable (2.2.6)
crack (0.3.1)
diff-lcs (1.1.3)
emk-sinatra-url-for (0.2.1)
sinatra (>= 0.9.1.1)
fakeweb (1.3.0)
faraday (0.7.5)
addressable (~> 2.2.6)
multipart-post (~> 1.1.3)
rack (>= 1.1.0, < 2)
faraday_middleware (0.7.0)
faraday (~> 0.7.3)
guard (0.8.8)
thor (~> 0.14.6)
guard-rspec (0.5.7)
guard (>= 0.8.4)
haml (3.0.25)
hashie (1.1.0)
heroku (2.11.0)
Expand All @@ -21,17 +29,32 @@ GEM
httparty (0.8.1)
multi_json
multi_xml
i18n (0.6.0)
launchy (2.0.5)
addressable (~> 2.2.6)
maruku (0.6.0)
syntax (>= 1.0.0)
metaclass (0.0.1)
mime-types (1.17.2)
mocha (0.10.0)
metaclass (~> 0.0.1)
multi_json (1.0.3)
multi_xml (0.4.1)
multipart-post (1.1.3)
rack (1.2.1)
rack-test (0.6.1)
rack (>= 1.0)
rake (0.9.2.2)
rest-client (1.6.7)
mime-types (>= 1.16)
rspec (2.7.0)
rspec-core (~> 2.7.0)
rspec-expectations (~> 2.7.0)
rspec-mocks (~> 2.7.0)
rspec-core (2.7.1)
rspec-expectations (2.7.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.7.0)
rubyzip (0.9.4)
simple_oauth (0.1.5)
sinatra (1.1.2)
Expand All @@ -46,6 +69,7 @@ GEM
httparty (>= 0.6.1)
syntax (1.0.0)
term-ansicolor (1.0.7)
thor (0.14.6)
tilt (1.2.2)
twitter (1.7.2)
faraday (~> 0.7.4)
Expand All @@ -59,10 +83,19 @@ PLATFORMS
ruby

DEPENDENCIES
activesupport (~> 3.1)
fakeweb
guard
guard-rspec
haml
heroku
i18n
maruku
mocha
rack
rack-test
rake
rspec
sinatra (= 1.1.2)
sinatra-static-assets
swish
Expand Down
13 changes: 13 additions & 0 deletions Guardfile
@@ -0,0 +1,13 @@
# A sample Guardfile
# More info at https://github.com/guard/guard#readme

guard 'rspec', :version => 2 do
watch(%r{^spec/.+_spec\.rb$})
watch('spec/spec_helper.rb') { "spec" }
watch('app.rb') { "spec" }
watch(%r{^(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
watch('spec/spec_helper.rb') { "spec" }
end

10 changes: 10 additions & 0 deletions README.md
Expand Up @@ -4,6 +4,16 @@

This is my playground. I will have a place to show my artwork, some of my user interface design and I will also start making some poster-like blog posts. I had a lot of fun making all of this so far and plan on continuing the theme. All art, design and development was done by me. You can see it all here, even the PSD. Enjoy

## Running Specs

Simple spec suite using RSpec/Mocha can be run via:

rake # the default task runs the whole suite

Or for automatic test runs while developing:

bundle exec guard

## Tech Used:

* [Sinatra](http://sinatrarb.com) (Ruby and Rubygems)
Expand Down
8 changes: 8 additions & 0 deletions Rakefile
@@ -0,0 +1,8 @@
require "rubygems"
require "bundler/setup"
require "rspec/core/rake_task"

RSpec::Core::RakeTask.new(:spec)

task :default => [:spec]

38 changes: 24 additions & 14 deletions app.rb
Expand Up @@ -2,25 +2,35 @@
require "bundler/setup"
require "rack"
require "sinatra"
require 'sinatra/static_assets'
require 'swish'
require 'twitter'
require "sinatra/static_assets"
require "swish"
require "twitter"
require "active_support/cache"


# FOR BASIC AUTH USE BELOW, REPLACE ['username', 'password'] with actual credentials
# use Rack::Auth::Basic do |username, password|
# [username, password] == ['username', 'password']
# end
DefaultCacheExpirationTime = 4.hours

set :haml, {:format => :html5}
set :cache, ActiveSupport::Cache::MemoryStore.new(:expires_in => DefaultCacheExpirationTime)

get '/' do

@page_title = "Artist & Designer at Relevance, Inc. in Durham, NC"
# @tweet = Twitter.user_timeline("parenteau").first.text
@player = Dribbble::Player.find('michaelparenteau')
@shot = @player.shots.first

@tweet = last_tweet
@shot = last_shot
haml :index
end

def last_shot
Dribbble::Player.find('michaelparenteau').shots.first
end

end
def last_tweet
settings.cache.fetch(:last_tweet) do
begin
Twitter.user_timeline("parenteau").first.text
rescue => e
$stderr.puts "Could not retrieve latest tweet!"
$stderr.puts e
nil
end
end
end
52 changes: 52 additions & 0 deletions spec/app_spec.rb
@@ -0,0 +1,52 @@
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[..])
Bundler.require(:test)
ENV['RACK_ENV'] = 'test'
require 'app'
require 'rspec'
require 'mocha'
require 'rack/test'

RSpec.configure do |conf|
conf.include Rack::Test::Methods
conf.mock_with :mocha
end

describe "the App" do
def app
Sinatra::Application
end

before do
# Don't allow any real http requests -- we don't want Dribble or Twitter
# requests happening during test runs
FakeWeb.allow_net_connect = false
end

it "has a good response" do
app.any_instance.stubs(:last_shot).returns(stub_everything("dribble shot"))
app.any_instance.stubs(:last_tweet).returns("some tweet")
get '/'
last_response.should be_ok
end

it "shows friendly error message if tweets can't be loaded" do
app.any_instance.stubs(:last_shot).returns(stub_everything("dribble shot"))
app.any_instance.expects(:last_tweet).returns(nil)
get "/"
last_response.body.should include("Twitter requests are timing out")
end

it "shows friendly error message if twitter raises an exception" do
app.any_instance.stubs(:last_shot).returns(stub_everything("dribble shot"))
Twitter.expects(:user_timeline).raises(RuntimeError)
get "/"
last_response.body.should include("Twitter requests are timing out")
end

it "shows the latest tweet" do
app.any_instance.stubs(:last_shot).returns(stub_everything("dribble shot"))
app.any_instance.expects(:last_tweet).returns("this is a tweet!")
get "/"
last_response.body.should include("this is a tweet!")
end
end
8 changes: 5 additions & 3 deletions views/index.haml
Expand Up @@ -13,8 +13,10 @@
%a{:href => 'http://twitter.com/michaelparenteau',:target => '_blank'} twitter
.tweet
%p
Twitter requests are timing out... sorry, this is not the tweet you are looking for.
/ = @tweet
-if @tweet.nil?
Twitter requests are timing out... sorry, this is not the tweet you are looking for.
-else
= @tweet
.four.columns.ampersand
=image_tag("/images/ampersand.png", :alt => "Ampersand (&)")
.six.columns.dribbble
Expand All @@ -25,4 +27,4 @@
.clear

.sixteen.columns.surfer-and-fish-water
=image_tag("/images/surfer-and-fish-water.png", :alt => "Cyclops alien on a surfboard chasing 3 flying fish")
=image_tag("/images/surfer-and-fish-water.png", :alt => "Cyclops alien on a surfboard chasing 3 flying fish")

0 comments on commit 30bb422

Please sign in to comment.