ruboty-tweetstream 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/lib/ruboty/handlers/tweetstream.rb +18 -18
 - data/lib/ruboty/tweetstream/stream.rb +19 -3
 - data/lib/ruboty/tweetstream/version.rb +1 -1
 - data/ruboty-tweetstream.gemspec +0 -2
 - metadata +2 -30
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 60de20eb65af9dbc59a729bc31db428057da2af6
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 14f205071ce869d0cf2cec8f399f428e6e8d30f7
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 99c38dfcc3152f26807419e29063e2e9a92eda341fad717cc993602a6cfce2303f12a4b9781de640eb235441467dccd2a92ed5efcf13199e6d993e686b5d1228
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: c40db43353d008dc945017183ca930379131a44c83ef022e51ac1f0cc2b67857ee63a2eb605d15bfc7a8fe57b80462d0b57ae3f8e0278fe0591c929f1c86ea6c
         
     | 
| 
         @@ -66,26 +66,26 @@ module Ruboty 
     | 
|
| 
       66 
66 
     | 
    
         
             
                  end
         
     | 
| 
       67 
67 
     | 
    
         | 
| 
       68 
68 
     | 
    
         
             
                  def list(message)
         
     | 
| 
       69 
     | 
    
         
            -
                     
     | 
| 
       70 
     | 
    
         
            -
             
     | 
| 
       71 
     | 
    
         
            -
                    if message[:all_flag]
         
     | 
| 
       72 
     | 
    
         
            -
                      stream_list = sorted_streams.map do |id, hash|
         
     | 
| 
       73 
     | 
    
         
            -
                        stream = "#{id}: @#{hash[:username]}"
         
     | 
| 
       74 
     | 
    
         
            -
                        stream << " (#{hash[:channel]})" unless hash[:channel].nil?
         
     | 
| 
       75 
     | 
    
         
            -
                        stream
         
     | 
| 
       76 
     | 
    
         
            -
                      end
         
     | 
| 
       77 
     | 
    
         
            -
                    else
         
     | 
| 
       78 
     | 
    
         
            -
                      stream_list = sorted_streams.map { |id, hash|
         
     | 
| 
       79 
     | 
    
         
            -
                        # Skip the channel that registered from other channel.
         
     | 
| 
       80 
     | 
    
         
            -
                        next unless hash[:channel] == message.channel
         
     | 
| 
       81 
     | 
    
         
            -
             
     | 
| 
       82 
     | 
    
         
            -
                        "#{id}: @#{hash[:username]}"
         
     | 
| 
       83 
     | 
    
         
            -
                      }.compact
         
     | 
| 
       84 
     | 
    
         
            -
                    end
         
     | 
| 
       85 
     | 
    
         
            -
             
     | 
| 
       86 
     | 
    
         
            -
                    if stream_list.empty?
         
     | 
| 
      
 69 
     | 
    
         
            +
                    if streams.empty?
         
     | 
| 
       87 
70 
     | 
    
         
             
                      message.reply("The stream doesn't exist.")
         
     | 
| 
       88 
71 
     | 
    
         
             
                    else
         
     | 
| 
      
 72 
     | 
    
         
            +
                      sorted_streams = streams.sort_by {|_id, hash| hash[:username]}
         
     | 
| 
      
 73 
     | 
    
         
            +
             
     | 
| 
      
 74 
     | 
    
         
            +
                      if message[:all_flag]
         
     | 
| 
      
 75 
     | 
    
         
            +
                        stream_list = sorted_streams.map do |id, hash|
         
     | 
| 
      
 76 
     | 
    
         
            +
                          stream = "#{id}: @#{hash[:username]}"
         
     | 
| 
      
 77 
     | 
    
         
            +
                          stream << " (#{hash[:channel]})" unless hash[:channel].nil?
         
     | 
| 
      
 78 
     | 
    
         
            +
                          stream
         
     | 
| 
      
 79 
     | 
    
         
            +
                        end
         
     | 
| 
      
 80 
     | 
    
         
            +
                      else
         
     | 
| 
      
 81 
     | 
    
         
            +
                        stream_list = sorted_streams.map { |id, hash|
         
     | 
| 
      
 82 
     | 
    
         
            +
                          # Skip the channel that registered from other channel.
         
     | 
| 
      
 83 
     | 
    
         
            +
                          next unless hash[:channel] == message.channel
         
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
                          "#{id}: @#{hash[:username]}"
         
     | 
| 
      
 86 
     | 
    
         
            +
                        }.compact
         
     | 
| 
      
 87 
     | 
    
         
            +
                      end
         
     | 
| 
      
 88 
     | 
    
         
            +
             
     | 
| 
       89 
89 
     | 
    
         
             
                      message.reply(stream_list.join("\n"), code: true)
         
     | 
| 
       90 
90 
     | 
    
         
             
                    end
         
     | 
| 
       91 
91 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -10,10 +10,11 @@ end 
     | 
|
| 
       10 
10 
     | 
    
         
             
            module Ruboty
         
     | 
| 
       11 
11 
     | 
    
         
             
              module Tweetstream
         
     | 
| 
       12 
12 
     | 
    
         
             
                class Stream
         
     | 
| 
       13 
     | 
    
         
            -
                  attr_reader :hash 
     | 
| 
      
 13 
     | 
    
         
            +
                  attr_reader :hash
         
     | 
| 
       14 
14 
     | 
    
         | 
| 
       15 
15 
     | 
    
         
             
                  def initialize(hash)
         
     | 
| 
       16 
16 
     | 
    
         
             
                    @hash = hash
         
     | 
| 
      
 17 
     | 
    
         
            +
                    @thread = nil
         
     | 
| 
       17 
18 
     | 
    
         | 
| 
       18 
19 
     | 
    
         
             
                    @client = Twitter::Streaming::Client.new do |config|
         
     | 
| 
       19 
20 
     | 
    
         
             
                      config.consumer_key        = CONSUMER_KEY
         
     | 
| 
         @@ -24,7 +25,7 @@ module Ruboty 
     | 
|
| 
       24 
25 
     | 
    
         
             
                  end
         
     | 
| 
       25 
26 
     | 
    
         | 
| 
       26 
27 
     | 
    
         
             
                  def start(robot)
         
     | 
| 
       27 
     | 
    
         
            -
                    @thread =  
     | 
| 
      
 28 
     | 
    
         
            +
                    @thread = interval_reconnect do
         
     | 
| 
       28 
29 
     | 
    
         
             
                      @client.filter(follow: hash[:twitter_id].to_s) do |object|
         
     | 
| 
       29 
30 
     | 
    
         
             
                        if object.is_a?(Twitter::Tweet) && object.is_pure_user_tweet?(hash[:username])
         
     | 
| 
       30 
31 
     | 
    
         
             
                          Message.new(
         
     | 
| 
         @@ -35,8 +36,23 @@ module Ruboty 
     | 
|
| 
       35 
36 
     | 
    
         
             
                    end
         
     | 
| 
       36 
37 
     | 
    
         
             
                  end
         
     | 
| 
       37 
38 
     | 
    
         | 
| 
      
 39 
     | 
    
         
            +
                  # Twitter::Streaming disconnects over time
         
     | 
| 
      
 40 
     | 
    
         
            +
                  def interval_reconnect
         
     | 
| 
      
 41 
     | 
    
         
            +
                    parent = Thread.start do
         
     | 
| 
      
 42 
     | 
    
         
            +
                      loop do
         
     | 
| 
      
 43 
     | 
    
         
            +
                        child = Thread.start do
         
     | 
| 
      
 44 
     | 
    
         
            +
                          yield
         
     | 
| 
      
 45 
     | 
    
         
            +
                        end
         
     | 
| 
      
 46 
     | 
    
         
            +
                        sleep 3600 # Disconnect every hour
         
     | 
| 
      
 47 
     | 
    
         
            +
                        child.kill
         
     | 
| 
      
 48 
     | 
    
         
            +
                      end
         
     | 
| 
      
 49 
     | 
    
         
            +
                    end
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
                    parent
         
     | 
| 
      
 52 
     | 
    
         
            +
                  end
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
       38 
54 
     | 
    
         
             
                  def stop
         
     | 
| 
       39 
     | 
    
         
            -
                    thread.kill
         
     | 
| 
      
 55 
     | 
    
         
            +
                    @thread.kill
         
     | 
| 
       40 
56 
     | 
    
         
             
                  end
         
     | 
| 
       41 
57 
     | 
    
         
             
                end
         
     | 
| 
       42 
58 
     | 
    
         
             
              end
         
     | 
    
        data/ruboty-tweetstream.gemspec
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: ruboty-tweetstream
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.2.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - kaihar4
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date:  
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2015-02-12 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: ruboty
         
     | 
| 
         @@ -80,34 +80,6 @@ dependencies: 
     | 
|
| 
       80 
80 
     | 
    
         
             
                - - ">="
         
     | 
| 
       81 
81 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       82 
82 
     | 
    
         
             
                    version: '0'
         
     | 
| 
       83 
     | 
    
         
            -
            - !ruby/object:Gem::Dependency
         
     | 
| 
       84 
     | 
    
         
            -
              name: pry
         
     | 
| 
       85 
     | 
    
         
            -
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
       86 
     | 
    
         
            -
                requirements:
         
     | 
| 
       87 
     | 
    
         
            -
                - - ">="
         
     | 
| 
       88 
     | 
    
         
            -
                  - !ruby/object:Gem::Version
         
     | 
| 
       89 
     | 
    
         
            -
                    version: '0'
         
     | 
| 
       90 
     | 
    
         
            -
              type: :development
         
     | 
| 
       91 
     | 
    
         
            -
              prerelease: false
         
     | 
| 
       92 
     | 
    
         
            -
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
       93 
     | 
    
         
            -
                requirements:
         
     | 
| 
       94 
     | 
    
         
            -
                - - ">="
         
     | 
| 
       95 
     | 
    
         
            -
                  - !ruby/object:Gem::Version
         
     | 
| 
       96 
     | 
    
         
            -
                    version: '0'
         
     | 
| 
       97 
     | 
    
         
            -
            - !ruby/object:Gem::Dependency
         
     | 
| 
       98 
     | 
    
         
            -
              name: awesome_print
         
     | 
| 
       99 
     | 
    
         
            -
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
       100 
     | 
    
         
            -
                requirements:
         
     | 
| 
       101 
     | 
    
         
            -
                - - ">="
         
     | 
| 
       102 
     | 
    
         
            -
                  - !ruby/object:Gem::Version
         
     | 
| 
       103 
     | 
    
         
            -
                    version: '0'
         
     | 
| 
       104 
     | 
    
         
            -
              type: :development
         
     | 
| 
       105 
     | 
    
         
            -
              prerelease: false
         
     | 
| 
       106 
     | 
    
         
            -
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
       107 
     | 
    
         
            -
                requirements:
         
     | 
| 
       108 
     | 
    
         
            -
                - - ">="
         
     | 
| 
       109 
     | 
    
         
            -
                  - !ruby/object:Gem::Version
         
     | 
| 
       110 
     | 
    
         
            -
                    version: '0'
         
     | 
| 
       111 
83 
     | 
    
         
             
            description: Ruboty handler to stream specified user's tweet from Twitter.
         
     | 
| 
       112 
84 
     | 
    
         
             
            email:
         
     | 
| 
       113 
85 
     | 
    
         
             
            - kaihar4@gmail.com
         
     |