Skip to content

Commit

Permalink
Plugin converted to new API
Browse files Browse the repository at this point in the history
  • Loading branch information
netpro2k committed Nov 27, 2011
0 parents commit cc644db
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
Gemfile.lock
4 changes: 4 additions & 0 deletions Gemfile
@@ -0,0 +1,4 @@
source "http://rubygems.org"

# Specify your gem's dependencies in siriproxy-thermostat.gemspec
gemspec
1 change: 1 addition & 0 deletions Rakefile
@@ -0,0 +1 @@
require "bundler/gem_tasks"
12 changes: 12 additions & 0 deletions config-info.yml
@@ -0,0 +1,12 @@
#Example configuration options that can be placed in your main SiriProxy config.yml

##########################
#NOTICE: Modifying these options in this file has no effect. You must put them in SiriProxy's config.yml!
##########################

- name: 'Twitter'
git: 'git://github.com/netpro2k/SiriProxy-Twitter.git'
consumer_key: "YOUR_KEY"
consumer_secret: "YOUR_SECRET"
oauth_token: "YOUR_TOKEN"
oauth_token_secret: "YOUR_TOKEN_SECRET"
48 changes: 48 additions & 0 deletions lib/siriproxy-twitter.rb
@@ -0,0 +1,48 @@
require 'twitter'

class SiriProxy::Plugin::Twitter < SiriProxy::Plugin
def initialize(config = {})
@config = config

::Twitter.configure do |config|
config.consumer_key = @config['consumer_key']
config.consumer_secret = @config['consumer_secret']
config.oauth_token = @config['oauth_token']
config.oauth_token_secret = @config['oauth_token_secret']
end

@twitterClient = ::Twitter::Client.new
end

listen_for /tweet (.+)/i do |tweetText|
say "Here is your tweet:"

# send a "Preview" of the Tweet
object = SiriAddViews.new
object.make_root(last_ref_id)
answer = SiriAnswer.new("Tweet", [
SiriAnswerLine.new('logo','http://cl.ly/1l040J1A392n0M1n1g35/content'), # this just makes things looks nice, but is obviously specific to my username
SiriAnswerLine.new(tweetText)
])
object.views << SiriAnswerSnippet.new([answer])
send_object object

if confirm "Ready to send it?"
say "Posting to twitter..."
Thread.new {
begin
@twitterClient.update(tweetText)
say "Ok it has been posted."
rescue Exception
pp $!
say "Sorry, I encountered an error: #{$!}"
ensure
request_completed
end
}
else
say "Ok I won't send it."
request_completed
end
end
end
26 changes: 26 additions & 0 deletions siriproxy-twitter.gemspec
@@ -0,0 +1,26 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)

Gem::Specification.new do |s|
s.name = "siriproxy-twitter"
s.version = "0.0.1"
s.authors = ["netpro2k"]
s.email = ["netpro2k@gmail.com"]
s.homepage = "http://netpro2k.com"
s.summary = %q{Teach Siri how to tweet}
s.description = %q{This is a very simple plugin for posting to twitter from siri}

s.rubyforge_project = "siriproxy-twitter"

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"]

s.add_runtime_dependency "twitter"

s.add_development_dependency "rspec"
s.add_development_dependency "guard-rspec"
s.add_development_dependency "rake"

end

0 comments on commit cc644db

Please sign in to comment.