simonreed-lyrebird 0.1.0.2.4 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -7,20 +7,49 @@ Twitter Gateway, allows your app to respond to natural language questions from T
7
7
  * HTTParty http://github.com/jnunemaker/httparty/ - For accessing the Twitter web service.
8
8
 
9
9
  = SYNOPSIS
10
+ class LyresController
11
+ def index(response,history={},tweet_params={})
12
+
13
+ response.register_response(tweet_params) # Register the response that it can be persistent between tweets.
14
+
15
+ return "LyresController INDEX called" # Return text which will be used for the body of your response tweet.
16
+ end
17
+
18
+ def show(response,history={},tweet_params={})
19
+
20
+ response.register_response(tweet_params)
21
+
22
+ return "LyresController SHOW called"
23
+ end
24
+
25
+ end
26
+
10
27
  require 'rubygems'
11
28
  require 'lyre_bird'
12
29
 
13
30
  routes = [
14
- { 'str' => "Do you have a :item for me" }
15
- ]
31
+ { 'str' => "Do you have a :item for me" },
32
+ {
33
+ 'str' => ":item in :location",
34
+ 'class' => 'LyresController', # Specify class to be called when this route is matched.
35
+ 'method' => 'show'
36
+ }
37
+ ]
38
+
39
+ lyre = LyreBird::Base.new('<TWITTER_USERNAME>','<TWITTER_PASSWORD>', {
40
+ :routes => routes,
41
+ :since_filename => File.dirname(__FILE__) + '/listenSince.txt', # STRING - File used to store since_id,
42
+ :defaults => {
43
+ :class => 'LyresController', # The default class you want to call when a response is successful
44
+ :method => 'index' # The default method you want to call when a response is successful
45
+ }
46
+
47
+ })
16
48
 
17
- lyre = LyreBird::Base.new(:username => 'username', :password => 'password', :routes => routes)
18
49
  lyre.check() # Check for new messages.
19
50
 
20
51
  == Install
21
52
 
22
- sudo gem sources -a http://gems.github.com
23
-
24
- sudo gem install simonreed-lyrebird
53
+ sudo gem sources -a http://gems.github.com
25
54
 
26
- require ''
55
+ sudo gem install simonreed-lyrebird
data/bin/lyre_bird CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'rubygems'
2
- require 'lib/lyre_bird'
2
+ require 'lyre_bird'
3
3
 
4
4
  routes = [
5
5
  { 'str' => "Do you have a :item for me" },
@@ -22,7 +22,7 @@ $lyre_debug = ( debug.match(/^(Y|y|yes|Yes|YES)/)) ? true : false
22
22
  puts if $lyre_debug
23
23
  puts "Running in debug mode" if $lyre_debug
24
24
 
25
- @lb = LyreBird::Base.new(:username => 'username', :password => 'password', :routes => routes, :since_filename => File.dirname(__FILE__) + '/listenSince.txt')
25
+ @lb = LyreBird::Base.new('username','password', { :routes => routes, :since_filename => File.dirname(__FILE__) + '/listenSince.txt'})
26
26
 
27
27
  while true
28
28
  puts
@@ -6,7 +6,6 @@ module LyreBird
6
6
 
7
7
  def initialize(options={})
8
8
  self.tweet = options[:tweet]
9
- puts "@#{$lyrebird_username} "
10
9
  self.response = self.respond(:text => self.tweet['text'].gsub("@#{$lyrebird_username} ",''))
11
10
  end
12
11
 
@@ -57,7 +57,7 @@ module LyreBird
57
57
  puts
58
58
  puts "From @#{self.request_tweet['user']['screen_name']} - \"#{self.request_tweet['text']}\""
59
59
  puts
60
- puts "Reply - \"#{msg}\""
60
+ puts "Reply - \"@#{self.request_tweet['user']['screen_name']} #{msg}\""
61
61
  puts
62
62
  puts "-" * 50
63
63
  puts
@@ -73,7 +73,7 @@ module LyreBird
73
73
 
74
74
 
75
75
  if live
76
- $twitter.post(msg)
76
+ $twitter.post("@#{self.request_tweet['user']['screen_name']} #{msg}")
77
77
  end
78
78
  end
79
79
  end
@@ -17,8 +17,8 @@ module LyreBird
17
17
  options.merge!({:basic_auth => @auth})
18
18
  url = "/statuses/#{which}.json?"
19
19
  url += "since_id=#{since_id}" unless since_id.nil?
20
- puts "Requesting #{url} from Twitter API"
21
- self.class.get(url, options)
20
+ puts "Requesting #{url} from Twitter API using #{@auth.inspect}"
21
+ self.class.get(url, options)
22
22
  end
23
23
 
24
24
  # which can be :friends, :user or :public
@@ -29,6 +29,7 @@ module LyreBird
29
29
  end
30
30
 
31
31
  def post(text)
32
+ puts "POSTING TO TWITTER - " + text if $lyre_debug
32
33
  options = { :query => {:status => text}, :basic_auth => @auth }
33
34
  self.class.post('/statuses/update.json', options)
34
35
  end
data/lib/lyre_bird.rb CHANGED
@@ -15,9 +15,12 @@ module LyreBird
15
15
  def initialize(username=nil,password=nil,options={})
16
16
  $responses = {}
17
17
  $no_responses = []
18
+
18
19
  self.username = username || 'username'
19
20
  $lyrebird_username = self.username
20
21
  self.password = password || 'password'
22
+ $lyrebird_password = self.password
23
+
21
24
  self.since_filename = options[:since_filename] || "lyre_bird_listen_since.txt"
22
25
  $lyrebird_routes = options[:routes] || []
23
26
  $lyrebird_default_class = (options[:defaults] and options[:defaults][:class]) ? options[:defaults][:class] : 'LyresController'
@@ -54,22 +57,26 @@ module LyreBird
54
57
 
55
58
  def check(options={})
56
59
 
57
- options = {:live=>true}.merge(options)
60
+ options = {:live=>true, :post=>true}.merge(options)
58
61
  responses = []
59
62
 
60
63
  if options[:messages]
61
64
  puts "DOING AN OFFLINE LYREBIRD CHECK"
62
65
  mentions = options[:messages]
63
66
  else
64
- $twitter = LyreBird::Twitter.new(self.username,self.password)
67
+ $twitter = LyreBird::Twitter.new($lyrebird_username,$lyrebird_password)
65
68
  since = options[:since] || get_since()
66
69
  mentions = $twitter.mentions(:mentions,{ :since_id => since })
67
70
  end
68
-
69
- puts "Mentions - " + mentions
70
- mentions = mentions.sort {|a,b| a['id']<=>b['id']}
71
+
72
+ if mentions.is_a?(Hash)
73
+ puts "Twitter ERROR - #{mentions["error"]}"
74
+ return
75
+ else
76
+ mentions = mentions.sort {|a,b| a.id<=>b.id}
77
+ end
71
78
  mentions.each do | tweet |
72
- puts "Tweet - #{tweet.keys.to_yaml}" if $lyre_debug
79
+
73
80
  req = LyreBird::Request.new(:tweet => tweet)
74
81
  if options[:post]
75
82
  req.response.post(options[:live])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simonreed-lyrebird
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.2.4
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Reed