Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Josep M. Bach
committed
Feb 9, 2011
0 parents
commit f22c31d
Showing
11 changed files
with
246 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,3 @@ | |||
pkg/* | |||
*.gem | |||
.bundle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,2 @@ | |||
--color | |||
--format documentation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,4 @@ | |||
source "http://rubygems.org" | |||
|
|||
gemspec | |||
gem 'meme_generator', git: 'git://github.com/txus/meme', branch: 'develop' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,41 @@ | |||
GIT | |||
remote: git://github.com/txus/meme | |||
revision: 39d1931b6b210d96369efbfbc8bf3cc6d8d40f20 | |||
branch: develop | |||
specs: | |||
meme_generator (1.0) | |||
nokogiri (~> 1.4) | |||
|
|||
PATH | |||
remote: . | |||
specs: | |||
memetalk (0.0.1) | |||
talker | |||
|
|||
GEM | |||
remote: http://rubygems.org/ | |||
specs: | |||
diff-lcs (1.1.2) | |||
eventmachine (0.12.10) | |||
nokogiri (1.4.4) | |||
rspec (2.5.0) | |||
rspec-core (~> 2.5.0) | |||
rspec-expectations (~> 2.5.0) | |||
rspec-mocks (~> 2.5.0) | |||
rspec-core (2.5.1) | |||
rspec-expectations (2.5.0) | |||
diff-lcs (~> 1.1.2) | |||
rspec-mocks (2.5.0) | |||
talker (0.0.4) | |||
eventmachine | |||
yajl-ruby | |||
yajl-ruby (0.8.0) | |||
|
|||
PLATFORMS | |||
ruby | |||
|
|||
DEPENDENCIES | |||
meme_generator! | |||
memetalk! | |||
rspec | |||
talker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,15 @@ | |||
require 'bundler' | |||
Bundler::GemHelper.install_tasks | |||
|
|||
require 'rspec/core/rake_task' | |||
RSpec::Core::RakeTask.new(:spec) do |spec| | |||
spec.pattern = FileList['spec/**/*_spec.rb'] | |||
end | |||
|
|||
task default: :spec | |||
|
|||
desc 'hey' | |||
task :publish do | |||
require 'memetalk' | |||
Memetalk.publish 'link' | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,34 @@ | |||
#!/usr/bin/env ruby | |||
$: << 'lib' | |||
require 'bundler' | |||
Bundler.require | |||
require 'memetalk' | |||
|
|||
if ARGV.any? { |a| a == '--help' || a == '-h' } | |||
puts | |||
puts 'Memetalk. Brought to you by Codegram' | |||
puts '------------------------------------' | |||
puts 'Generates and publishes memes to a Talkerapp room (see talkerapp.com).' | |||
puts | |||
puts 'You should have a ~/.memetalkrc with the following data:' | |||
puts | |||
puts "\ttalker:" | |||
puts "\t token: 'MY_API_TOKEN' (go to Settings in your Talker account to get yours)" | |||
puts "\t room: YOUR_ROOM_ID (the number id of your room, for example 3874)\n" | |||
puts | |||
puts 'USAGE:' | |||
puts "\t\tmemetalk GENERATOR LINE1 [LINE2]\n" | |||
puts "\tExample:" | |||
puts "\t\tmemetalk Y_U_NO \"TEST\" \"WHY U NO GREEN\"\n" | |||
puts | |||
puts "...and your meme will be posted to your Talker room!\n" | |||
puts | |||
puts 'Available generators are:' | |||
Memetalk.list.each do |m| | |||
puts "\t#{m}" | |||
end | |||
puts | |||
exit(0) | |||
end | |||
|
|||
Memetalk.run ARGV |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,44 @@ | |||
require 'yaml' | |||
require 'talker/client' | |||
require 'meme' | |||
require 'eventmachine' | |||
|
|||
module Memetalk | |||
|
|||
class << self | |||
|
|||
def list | |||
Meme::GENERATORS.keys | |||
end | |||
|
|||
def run argv = ARGV | |||
publish Meme.run(argv) + '.jpg' | |||
end | |||
|
|||
def publish link | |||
EM.run do | |||
Talker::Client.connect(room: room, token: token) do |client| | |||
client.on_connected do | |||
client.send_message link | |||
client.close | |||
end | |||
client.on_close do | |||
EM.stop | |||
end | |||
client.on_error do |error| | |||
$stdout.print error | |||
end | |||
end | |||
end | |||
end | |||
|
|||
private | |||
|
|||
def token | |||
@@token ||= YAML.load(File.read(File.join(File.expand_path('~'), '.memetalkrc')))["talker"]["token"] | |||
end | |||
def room | |||
@@room ||= YAML.load(File.read(File.join(File.expand_path('~'), '.memetalkrc')))["talker"]["room"] | |||
end | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,3 @@ | |||
module Memetalk | |||
VERSION = "0.0.1" | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,26 @@ | |||
# -*- encoding: utf-8 -*- | |||
$:.push File.expand_path("../lib", __FILE__) | |||
require "memetalk/version" | |||
|
|||
Gem::Specification.new do |s| | |||
s.name = "memetalk" | |||
s.version = Memetalk::VERSION | |||
s.platform = Gem::Platform::RUBY | |||
s.authors = ["Josep M. Bach"] | |||
s.email = ["josep.m.bach@gmail.com"] | |||
s.homepage = "http://github.com/txus/memetalk" | |||
s.summary = %q{Send auto-generated memes to Talkerapp rooms!} | |||
s.description = %q{Send auto-generated memes to Talkerapp rooms!} | |||
|
|||
s.rubyforge_project = "memetalk" | |||
|
|||
s.add_runtime_dependency 'talker' | |||
# s.add_runtime_dependency 'meme_generator' | |||
|
|||
s.add_development_dependency 'rspec' | |||
|
|||
s.files = `git ls-files`.split("\n") | |||
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") | |||
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } | |||
s.require_paths = ["lib"] | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,72 @@ | |||
require 'spec_helper' | |||
require 'eventmachine' | |||
require 'meme' | |||
|
|||
|
|||
describe Memetalk do | |||
describe '.list' do | |||
it 'returns the available meme list' do | |||
Meme::GENERATORS.stub(:keys).and_return ['Y_U_NO', 'PHILOSORAPTOR'] | |||
Memetalk.list.should == ['Y_U_NO', 'PHILOSORAPTOR'] | |||
end | |||
end | |||
describe '.run' do | |||
it 'delegates meme creation to Meme Generator and publishes it' do | |||
Memetalk.list | |||
link = double :link | |||
Meme.should_receive(:run).with(['Y_U_NO', 'TEST', 'WHY U NO GREEN']).and_return link | |||
Memetalk.should_receive(:publish).with link | |||
Memetalk.run 'Y_U_NO', 'TEST', 'WHY U NO GREEN' | |||
end | |||
end | |||
describe '.publish' do | |||
it 'publishes a link to talker' do | |||
room = double :room | |||
token = double :token | |||
client = double :client | |||
error = double :error | |||
link = double :link | |||
|
|||
EM.should_receive(:run).and_yield | |||
|
|||
Memetalk.stub(:token).and_return token | |||
Memetalk.stub(:room).and_return room | |||
Talker::Client.should_receive(:connect).with(room: room, token: token).and_yield client | |||
|
|||
# on connected callback | |||
client.should_receive(:on_connected).and_yield | |||
client.should_receive(:send_message).with link | |||
client.should_receive(:close) | |||
|
|||
# on close callback | |||
client.should_receive(:on_close).and_yield | |||
EM.should_receive(:stop) | |||
|
|||
# on error callback | |||
client.should_receive(:on_error).and_yield error | |||
$stdout.should_receive(:print).with error | |||
|
|||
Memetalk.publish link | |||
end | |||
end | |||
describe '.token' do | |||
it 'returns the token from ~/.memetalkrc' do | |||
File.should_receive(:read).and_return """ | |||
talker: | |||
token: 'a1e23f4567' | |||
""" | |||
Memetalk.send(:token).should == 'a1e23f4567' | |||
end | |||
end | |||
|
|||
describe '.room' do | |||
it 'returns the room from ~/.memetalkrc' do | |||
File.should_receive(:read).and_return """ | |||
talker: | |||
room: 1398 | |||
""" | |||
Memetalk.send(:room).should == 1398 | |||
end | |||
end | |||
|
|||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,2 @@ | |||
require 'rspec' | |||
require 'memetalk' |