lita-campfire 0.1.3 → 0.1.4
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/Gemfile.lock +1 -1
 - data/README.md +3 -2
 - data/lib/lita/adapters/campfire.rb +16 -3
 - data/lib/lita/adapters/campfire/callback.rb +4 -4
 - data/lib/lita/adapters/campfire/connector.rb +17 -12
 - data/lita-campfire.gemspec +1 -1
 - data/spec/lita/adapters/campfire/callback_spec.rb +19 -10
 - data/spec/lita/adapters/campfire/connector_spec.rb +76 -51
 - data/spec/lita/adapters/campfire_spec.rb +24 -4
 - metadata +2 -3
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 711b381aa5f58bc007ea46b6e7dca13f856fe4ad
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 503b935c87bc152db95400c2c52aa2629d640334
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: a9c7cf1f3614b76e0487aeded9bfc31a5d89d624d28b2e8b5da90074a519e637d2c4886c933432b1edbb648a9f1246f43c55767030c10c3c4b6e7a7f6782d53b
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 89750d635765c465bb5d871c27951e40e16852d629a3d325d4b6d343798fd66af5a2c1937fcbaa7e61635e04e46d8dece6b4f782da4b9e8c9b095977132fd7c1
         
     | 
    
        data/Gemfile.lock
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | 
         @@ -1,7 +1,6 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # Campfire adapter for Lita
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
      
 3 
     | 
    
         
            +
            [](http://badge.fury.io/rb/lita-campfire)
         
     | 
| 
       5 
4 
     | 
    
         
             
            [](http://travis-ci.org/josacar/lita-campfire)
         
     | 
| 
       6 
5 
     | 
    
         
             
            [](https://coveralls.io/r/josacar/lita-campfire)
         
     | 
| 
       7 
6 
     | 
    
         
             
            [](https://codeclimate.com/github/josacar/lita-campfire)
         
     | 
| 
         @@ -36,6 +35,7 @@ Values needed to work like apikey can be found on 'My info' link when logged, su 
     | 
|
| 
       36 
35 
     | 
    
         
             
            ### Optional attributes
         
     | 
| 
       37 
36 
     | 
    
         | 
| 
       38 
37 
     | 
    
         
             
            * `debug` (Boolean) - If `true`, turns on the underlying Campfire library's (tinder) logger, which is fairly verbose. Default: `false`.
         
     | 
| 
      
 38 
     | 
    
         
            +
            * `tinder_options` (Hash) - If set passes the options to tinder listen method when called
         
     | 
| 
       39 
39 
     | 
    
         | 
| 
       40 
40 
     | 
    
         
             
            **Note** You must set also `config.robot.name` and `config.robot.mention_name` to work.
         
     | 
| 
       41 
41 
     | 
    
         | 
| 
         @@ -59,6 +59,7 @@ Lita.configure do |config| 
     | 
|
| 
       59 
59 
     | 
    
         
             
              config.adapter.apikey = ENV["CAMPFIRE_APIKEY"]
         
     | 
| 
       60 
60 
     | 
    
         
             
              config.adapter.rooms = ENV["CAMPFIRE_ROOMS"].split(',')
         
     | 
| 
       61 
61 
     | 
    
         
             
              config.adapter.debug = false
         
     | 
| 
      
 62 
     | 
    
         
            +
              config.adapter.tinder_options = { timeout: 30, user_agent: 'lita-campfire' }
         
     | 
| 
       62 
63 
     | 
    
         | 
| 
       63 
64 
     | 
    
         
             
              config.redis.url = ENV["REDISTOGO_URL"]
         
     | 
| 
       64 
65 
     | 
    
         
             
              config.http.port = ENV["PORT"]
         
     | 
| 
         @@ -2,18 +2,24 @@ module Lita 
     | 
|
| 
       2 
2 
     | 
    
         
             
              module Adapters
         
     | 
| 
       3 
3 
     | 
    
         
             
                class Campfire < Adapter
         
     | 
| 
       4 
4 
     | 
    
         
             
                  require_configs :subdomain, :apikey, :rooms
         
     | 
| 
      
 5 
     | 
    
         
            +
                  OPTIONAL_CONFIG_OPTIONS = %i(debug tinder_options)
         
     | 
| 
       5 
6 
     | 
    
         | 
| 
       6 
7 
     | 
    
         
             
                  attr_reader :connector
         
     | 
| 
       7 
8 
     | 
    
         | 
| 
       8 
9 
     | 
    
         
             
                  def initialize(robot)
         
     | 
| 
       9 
10 
     | 
    
         
             
                    super
         
     | 
| 
       10 
11 
     | 
    
         | 
| 
       11 
     | 
    
         
            -
                     
     | 
| 
       12 
     | 
    
         
            -
                      robot,
         
     | 
| 
      
 12 
     | 
    
         
            +
                    options = {
         
     | 
| 
       13 
13 
     | 
    
         
             
                      subdomain: config.subdomain,
         
     | 
| 
       14 
14 
     | 
    
         
             
                      apikey: config.apikey,
         
     | 
| 
       15 
15 
     | 
    
         
             
                      rooms: rooms,
         
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
      
 16 
     | 
    
         
            +
                    }
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
                    options.merge!(optional_config_options)
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                    @connector = Connector.new(
         
     | 
| 
      
 21 
     | 
    
         
            +
                      robot,
         
     | 
| 
      
 22 
     | 
    
         
            +
                      options
         
     | 
| 
       17 
23 
     | 
    
         
             
                    )
         
     | 
| 
       18 
24 
     | 
    
         
             
                  end
         
     | 
| 
       19 
25 
     | 
    
         | 
| 
         @@ -50,6 +56,13 @@ module Lita 
     | 
|
| 
       50 
56 
     | 
    
         
             
                  def disconnect
         
     | 
| 
       51 
57 
     | 
    
         
             
                    connector.disconnect
         
     | 
| 
       52 
58 
     | 
    
         
             
                  end
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
      
 60 
     | 
    
         
            +
                  def optional_config_options
         
     | 
| 
      
 61 
     | 
    
         
            +
                    OPTIONAL_CONFIG_OPTIONS.each_with_object({}) do |config_option, options|
         
     | 
| 
      
 62 
     | 
    
         
            +
                      config_option_value = config.public_send(config_option)
         
     | 
| 
      
 63 
     | 
    
         
            +
                      options[config_option] = config_option_value if config_option_value
         
     | 
| 
      
 64 
     | 
    
         
            +
                    end
         
     | 
| 
      
 65 
     | 
    
         
            +
                  end
         
     | 
| 
       53 
66 
     | 
    
         
             
                end
         
     | 
| 
       54 
67 
     | 
    
         | 
| 
       55 
68 
     | 
    
         
             
                Lita.register_adapter(:campfire, Campfire)
         
     | 
| 
         @@ -14,8 +14,8 @@ module Lita 
     | 
|
| 
       14 
14 
     | 
    
         
             
                      end
         
     | 
| 
       15 
15 
     | 
    
         
             
                    end
         
     | 
| 
       16 
16 
     | 
    
         | 
| 
       17 
     | 
    
         
            -
                    def listen
         
     | 
| 
       18 
     | 
    
         
            -
                      @room.listen do |event|
         
     | 
| 
      
 17 
     | 
    
         
            +
                    def listen(options={})
         
     | 
| 
      
 18 
     | 
    
         
            +
                      @room.listen(options) do |event|
         
     | 
| 
       19 
19 
     | 
    
         
             
                        receive event
         
     | 
| 
       20 
20 
     | 
    
         
             
                      end
         
     | 
| 
       21 
21 
     | 
    
         
             
                    end
         
     | 
| 
         @@ -74,7 +74,7 @@ module Lita 
     | 
|
| 
       74 
74 
     | 
    
         
             
                      def _receive(event)
         
     | 
| 
       75 
75 
     | 
    
         
             
                        text    = event.body
         
     | 
| 
       76 
76 
     | 
    
         
             
                        user    = @callback.create_user(event.user)
         
     | 
| 
       77 
     | 
    
         
            -
                        source  = Source.new(user, event.room_id.to_s)
         
     | 
| 
      
 77 
     | 
    
         
            +
                        source  = Source.new(user: user, room: event.room_id.to_s)
         
     | 
| 
       78 
78 
     | 
    
         
             
                        message = Message.new(@robot, text, source)
         
     | 
| 
       79 
79 
     | 
    
         
             
                        @robot.receive message
         
     | 
| 
       80 
80 
     | 
    
         
             
                      end
         
     | 
| 
         @@ -94,4 +94,4 @@ module Lita 
     | 
|
| 
       94 
94 
     | 
    
         
             
                  end
         
     | 
| 
       95 
95 
     | 
    
         
             
                end
         
     | 
| 
       96 
96 
     | 
    
         
             
              end
         
     | 
| 
       97 
     | 
    
         
            -
            end
         
     | 
| 
      
 97 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -3,24 +3,33 @@ module Lita 
     | 
|
| 
       3 
3 
     | 
    
         
             
                class Campfire < Adapter
         
     | 
| 
       4 
4 
     | 
    
         
             
                  class Connector
         
     | 
| 
       5 
5 
     | 
    
         
             
                    def initialize(robot, opts)
         
     | 
| 
       6 
     | 
    
         
            -
                      @robot 
     | 
| 
       7 
     | 
    
         
            -
                      @subdomain 
     | 
| 
       8 
     | 
    
         
            -
                      @apikey 
     | 
| 
       9 
     | 
    
         
            -
                      @rooms 
     | 
| 
       10 
     | 
    
         
            -
                      @debug 
     | 
| 
      
 6 
     | 
    
         
            +
                      @robot          = robot
         
     | 
| 
      
 7 
     | 
    
         
            +
                      @subdomain      = opts.fetch(:subdomain)
         
     | 
| 
      
 8 
     | 
    
         
            +
                      @apikey         = opts.fetch(:apikey)
         
     | 
| 
      
 9 
     | 
    
         
            +
                      @rooms          = opts.fetch(:rooms)
         
     | 
| 
      
 10 
     | 
    
         
            +
                      @debug          = opts.fetch(:debug) { false }
         
     | 
| 
      
 11 
     | 
    
         
            +
                      @tinder_options = opts.fetch(:tinder_options) { Hash.new }
         
     | 
| 
       11 
12 
     | 
    
         
             
                    end
         
     | 
| 
       12 
13 
     | 
    
         | 
| 
       13 
14 
     | 
    
         
             
                    def connect
         
     | 
| 
       14 
15 
     | 
    
         
             
                      @campfire = Tinder::Campfire.new(@subdomain, token: @apikey)
         
     | 
| 
       15 
16 
     | 
    
         
             
                    end
         
     | 
| 
       16 
17 
     | 
    
         | 
| 
      
 18 
     | 
    
         
            +
                    def disconnect
         
     | 
| 
      
 19 
     | 
    
         
            +
                      Lita.logger.info("Disconnecting from Campfire.")
         
     | 
| 
      
 20 
     | 
    
         
            +
                      rooms.each do |room_id|
         
     | 
| 
      
 21 
     | 
    
         
            +
                        room = fetch_room(room_id)
         
     | 
| 
      
 22 
     | 
    
         
            +
                        room.leave
         
     | 
| 
      
 23 
     | 
    
         
            +
                      end
         
     | 
| 
      
 24 
     | 
    
         
            +
                    end
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
       17 
26 
     | 
    
         
             
                    def join_rooms
         
     | 
| 
       18 
27 
     | 
    
         
             
                      rooms.each do |room_id|
         
     | 
| 
       19 
28 
     | 
    
         
             
                        room = fetch_room(room_id)
         
     | 
| 
       20 
29 
     | 
    
         
             
                        room.join
         
     | 
| 
       21 
30 
     | 
    
         
             
                        callback = Callback.new(@robot, room)
         
     | 
| 
       22 
31 
     | 
    
         
             
                        callback.register_users
         
     | 
| 
       23 
     | 
    
         
            -
                        callback.listen
         
     | 
| 
      
 32 
     | 
    
         
            +
                        callback.listen(@tinder_options)
         
     | 
| 
       24 
33 
     | 
    
         
             
                      end
         
     | 
| 
       25 
34 
     | 
    
         
             
                    end
         
     | 
| 
       26 
35 
     | 
    
         | 
| 
         @@ -36,12 +45,8 @@ module Lita 
     | 
|
| 
       36 
45 
     | 
    
         
             
                      end
         
     | 
| 
       37 
46 
     | 
    
         
             
                    end
         
     | 
| 
       38 
47 
     | 
    
         | 
| 
       39 
     | 
    
         
            -
                    def  
     | 
| 
       40 
     | 
    
         
            -
                       
     | 
| 
       41 
     | 
    
         
            -
                      rooms.each do |room_id|
         
     | 
| 
       42 
     | 
    
         
            -
                        room = fetch_room(room_id)
         
     | 
| 
       43 
     | 
    
         
            -
                        room.leave
         
     | 
| 
       44 
     | 
    
         
            -
                      end
         
     | 
| 
      
 48 
     | 
    
         
            +
                    def set_topic(room_id, topic)
         
     | 
| 
      
 49 
     | 
    
         
            +
                      fetch_room(room_id).topic = topic
         
     | 
| 
       45 
50 
     | 
    
         
             
                    end
         
     | 
| 
       46 
51 
     | 
    
         | 
| 
       47 
52 
     | 
    
         
             
                    private
         
     | 
    
        data/lita-campfire.gemspec
    CHANGED
    
    | 
         @@ -1,6 +1,6 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            Gem::Specification.new do |spec|
         
     | 
| 
       2 
2 
     | 
    
         
             
              spec.name          = "lita-campfire"
         
     | 
| 
       3 
     | 
    
         
            -
              spec.version       = "0.1. 
     | 
| 
      
 3 
     | 
    
         
            +
              spec.version       = "0.1.4"
         
     | 
| 
       4 
4 
     | 
    
         
             
              spec.authors       = ["Jose Luis Salas", "Zac Stewart"]
         
     | 
| 
       5 
5 
     | 
    
         
             
              spec.email         = ["josacar@gmail.com", "zgstewart@gmail.com"]
         
     | 
| 
       6 
6 
     | 
    
         
             
              spec.description   = %q{A Campfire adapter for Lita.}
         
     | 
| 
         @@ -3,19 +3,19 @@ require 'spec_helper' 
     | 
|
| 
       3 
3 
     | 
    
         
             
            describe Campfire::Callback do
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
5 
     | 
    
         
             
              class DummyRoom < Struct.new(:id, :message, :users)
         
     | 
| 
       6 
     | 
    
         
            -
                def listen
         
     | 
| 
      
 6 
     | 
    
         
            +
                def listen(options={})
         
     | 
| 
       7 
7 
     | 
    
         
             
                  yield message
         
     | 
| 
       8 
8 
     | 
    
         
             
                end
         
     | 
| 
       9 
9 
     | 
    
         
             
              end
         
     | 
| 
       10 
10 
     | 
    
         | 
| 
       11 
     | 
    
         
            -
              let(:event)         {  
     | 
| 
      
 11 
     | 
    
         
            +
              let(:event)         { instance_double('Event') }
         
     | 
| 
       12 
12 
     | 
    
         
             
              let(:campfire_user) { { id: 1, name: 'Bender Bending Rodriguez' } }
         
     | 
| 
       13 
     | 
    
         
            -
              let(:message)       {  
     | 
| 
       14 
     | 
    
         
            -
              let(:robot)         {  
     | 
| 
      
 13 
     | 
    
         
            +
              let(:message)       { instance_double(Lita::Message) }
         
     | 
| 
      
 14 
     | 
    
         
            +
              let(:robot)         { instance_double(Lita::Robot, mention_name: 'Robot') }
         
     | 
| 
       15 
15 
     | 
    
         
             
              let(:room)          { DummyRoom.new(1, event, users) }
         
     | 
| 
       16 
     | 
    
         
            -
              let(:source)        {  
     | 
| 
      
 16 
     | 
    
         
            +
              let(:source)        { instance_double(Lita::Source) }
         
     | 
| 
       17 
17 
     | 
    
         
             
              let(:text)          { "Yes it's the apocalypse alright. I always though is have a hand in it." }
         
     | 
| 
       18 
     | 
    
         
            -
              let(:user)          {  
     | 
| 
      
 18 
     | 
    
         
            +
              let(:user)          { instance_double(Lita::User) }
         
     | 
| 
       19 
19 
     | 
    
         
             
              let(:users)         { [ {id: 2, name: 'Bender'}, {id: 3, name: 'Washbucket'} ] }
         
     | 
| 
       20 
20 
     | 
    
         | 
| 
       21 
21 
     | 
    
         
             
              subject { described_class.new(robot, room) }
         
     | 
| 
         @@ -27,7 +27,7 @@ describe Campfire::Callback do 
     | 
|
| 
       27 
27 
     | 
    
         
             
                %w( TextMessage PasteMessage ).each do |message_type|
         
     | 
| 
       28 
28 
     | 
    
         
             
                  describe "with a #{message_type}" do
         
     | 
| 
       29 
29 
     | 
    
         
             
                    let(:event) do
         
     | 
| 
       30 
     | 
    
         
            -
                       
     | 
| 
      
 30 
     | 
    
         
            +
                      instance_double('Event',
         
     | 
| 
       31 
31 
     | 
    
         
             
                             type:     message_type,
         
     | 
| 
       32 
32 
     | 
    
         
             
                             body:     text,
         
     | 
| 
       33 
33 
     | 
    
         
             
                             user:     campfire_user,
         
     | 
| 
         @@ -36,7 +36,7 @@ describe Campfire::Callback do 
     | 
|
| 
       36 
36 
     | 
    
         | 
| 
       37 
37 
     | 
    
         
             
                    it 'passes the message to Robot#receive' do
         
     | 
| 
       38 
38 
     | 
    
         
             
                      expect(Lita::User).to receive(:create).with(1, name: 'Bender Bending Rodriguez').and_return(user)
         
     | 
| 
       39 
     | 
    
         
            -
                      expect(Lita::Source).to receive(:new).with(user, '1').and_return(source)
         
     | 
| 
      
 39 
     | 
    
         
            +
                      expect(Lita::Source).to receive(:new).with(user: user, room: '1').and_return(source)
         
     | 
| 
       40 
40 
     | 
    
         
             
                      expect(Lita::Message).to receive(:new).with(robot, text, source).and_return(message)
         
     | 
| 
       41 
41 
     | 
    
         
             
                      expect(robot).to receive(:receive).with(message)
         
     | 
| 
       42 
42 
     | 
    
         
             
                      subject.listen
         
     | 
| 
         @@ -45,7 +45,7 @@ describe Campfire::Callback do 
     | 
|
| 
       45 
45 
     | 
    
         
             
                end
         
     | 
| 
       46 
46 
     | 
    
         | 
| 
       47 
47 
     | 
    
         
             
                describe 'EnterMessage' do
         
     | 
| 
       48 
     | 
    
         
            -
                  let(:event) {  
     | 
| 
      
 48 
     | 
    
         
            +
                  let(:event) { instance_double('Event', type: 'EnterMessage', user: campfire_user) }
         
     | 
| 
       49 
49 
     | 
    
         | 
| 
       50 
50 
     | 
    
         
             
                  it 'creates a user' do
         
     | 
| 
       51 
51 
     | 
    
         
             
                    expect(Lita::User).to receive(:create).with(1, name: 'Bender Bending Rodriguez').and_return(user)
         
     | 
| 
         @@ -53,6 +53,15 @@ describe Campfire::Callback do 
     | 
|
| 
       53 
53 
     | 
    
         
             
                  end
         
     | 
| 
       54 
54 
     | 
    
         
             
                end
         
     | 
| 
       55 
55 
     | 
    
         | 
| 
      
 56 
     | 
    
         
            +
                describe 'when options are set in connector' do
         
     | 
| 
      
 57 
     | 
    
         
            +
                  let(:room) { double(:room) }
         
     | 
| 
      
 58 
     | 
    
         
            +
                  it 'passes options to underlying tinder' do
         
     | 
| 
      
 59 
     | 
    
         
            +
                    tinder_options = { timeout: 30 }
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
      
 61 
     | 
    
         
            +
                    expect(room).to receive(:listen).with(tinder_options)
         
     | 
| 
      
 62 
     | 
    
         
            +
                    subject.listen(tinder_options)
         
     | 
| 
      
 63 
     | 
    
         
            +
                  end
         
     | 
| 
      
 64 
     | 
    
         
            +
                end
         
     | 
| 
       56 
65 
     | 
    
         
             
              end
         
     | 
| 
       57 
66 
     | 
    
         | 
| 
       58 
67 
     | 
    
         
             
              describe '#register_users' do
         
     | 
| 
         @@ -66,4 +75,4 @@ describe Campfire::Callback do 
     | 
|
| 
       66 
75 
     | 
    
         
             
                end
         
     | 
| 
       67 
76 
     | 
    
         
             
              end
         
     | 
| 
       68 
77 
     | 
    
         | 
| 
       69 
     | 
    
         
            -
            end
         
     | 
| 
      
 78 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -1,17 +1,19 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'spec_helper'
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            describe Campfire::Connector do
         
     | 
| 
       4 
     | 
    
         
            -
              let(:robot) {  
     | 
| 
      
 4 
     | 
    
         
            +
              let(:robot) { instance_double(Lita::Robot) }
         
     | 
| 
       5 
5 
     | 
    
         
             
              let(:subdomain) { 'mycampfire' }
         
     | 
| 
       6 
6 
     | 
    
         
             
              let(:apikey) { '2e9f45bb934c0fa13e9f19ee0901c316fda9fc1' }
         
     | 
| 
       7 
7 
     | 
    
         
             
              let(:rooms) { %w( 12345 ) }
         
     | 
| 
       8 
8 
     | 
    
         
             
              let(:options) { { subdomain: subdomain, apikey: apikey, rooms: rooms } }
         
     | 
| 
       9 
     | 
    
         
            -
              let(:campfire) {  
     | 
| 
      
 9 
     | 
    
         
            +
              let(:campfire) { instance_double(Tinder::Campfire) }
         
     | 
| 
      
 10 
     | 
    
         
            +
              let(:room) { instance_double(Tinder::Room) }
         
     | 
| 
       10 
11 
     | 
    
         | 
| 
       11 
12 
     | 
    
         
             
              subject { described_class.new(robot, options) }
         
     | 
| 
       12 
13 
     | 
    
         | 
| 
       13 
14 
     | 
    
         
             
              before do
         
     | 
| 
       14 
15 
     | 
    
         
             
                allow(Tinder::Campfire).to receive(:new).and_return(campfire)
         
     | 
| 
      
 16 
     | 
    
         
            +
                allow(campfire).to receive(:find_room_by_id).and_return(room)
         
     | 
| 
       15 
17 
     | 
    
         
             
              end
         
     | 
| 
       16 
18 
     | 
    
         | 
| 
       17 
19 
     | 
    
         
             
              describe '#connect' do
         
     | 
| 
         @@ -21,78 +23,101 @@ describe Campfire::Connector do 
     | 
|
| 
       21 
23 
     | 
    
         
             
                end
         
     | 
| 
       22 
24 
     | 
    
         
             
              end
         
     | 
| 
       23 
25 
     | 
    
         | 
| 
       24 
     | 
    
         
            -
               
     | 
| 
       25 
     | 
    
         
            -
                 
     | 
| 
       26 
     | 
    
         
            -
                   
     | 
| 
      
 26 
     | 
    
         
            +
              context 'when connected to campfire' do
         
     | 
| 
      
 27 
     | 
    
         
            +
                before do
         
     | 
| 
      
 28 
     | 
    
         
            +
                  subject.connect
         
     | 
| 
      
 29 
     | 
    
         
            +
                end
         
     | 
| 
      
 30 
     | 
    
         
            +
                let(:callback) { instance_double(Campfire::Callback) }
         
     | 
| 
       27 
31 
     | 
    
         | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
      
 32 
     | 
    
         
            +
                describe '#disconnect' do
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
                  it "leaves joined rooms" do
         
     | 
| 
      
 35 
     | 
    
         
            +
                    expect(room).to receive(:leave)
         
     | 
| 
      
 36 
     | 
    
         
            +
                    subject.disconnect
         
     | 
| 
       31 
37 
     | 
    
         
             
                  end
         
     | 
| 
      
 38 
     | 
    
         
            +
                end
         
     | 
| 
       32 
39 
     | 
    
         | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
      
 40 
     | 
    
         
            +
                describe 'when tinder options are set' do
         
     | 
| 
      
 41 
     | 
    
         
            +
                  let(:tinder_options) { { timeout: 30 } }
         
     | 
| 
      
 42 
     | 
    
         
            +
                  let(:options) do
         
     | 
| 
      
 43 
     | 
    
         
            +
                    {
         
     | 
| 
      
 44 
     | 
    
         
            +
                      subdomain: subdomain,
         
     | 
| 
      
 45 
     | 
    
         
            +
                      apikey: apikey,
         
     | 
| 
      
 46 
     | 
    
         
            +
                      rooms: rooms,
         
     | 
| 
      
 47 
     | 
    
         
            +
                      tinder_options: tinder_options
         
     | 
| 
      
 48 
     | 
    
         
            +
                    }
         
     | 
| 
      
 49 
     | 
    
         
            +
                  end
         
     | 
| 
       37 
50 
     | 
    
         | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
                     
     | 
| 
       40 
     | 
    
         
            -
                     
     | 
| 
      
 51 
     | 
    
         
            +
                  it 'passes options to underlying tinder lib' do
         
     | 
| 
      
 52 
     | 
    
         
            +
                    allow(campfire).to receive(:find_room_by_id).and_return(room)
         
     | 
| 
      
 53 
     | 
    
         
            +
                    subject.connect
         
     | 
| 
      
 54 
     | 
    
         
            +
                    allow(Campfire::Callback).to receive(:new).and_return(callback)
         
     | 
| 
       41 
55 
     | 
    
         | 
| 
      
 56 
     | 
    
         
            +
                    allow(room).to receive(:join)
         
     | 
| 
      
 57 
     | 
    
         
            +
                    allow(callback).to receive(:register_users)
         
     | 
| 
      
 58 
     | 
    
         
            +
                    expect(callback).to receive(:listen).with(tinder_options)
         
     | 
| 
       42 
59 
     | 
    
         
             
                    subject.join_rooms
         
     | 
| 
       43 
60 
     | 
    
         
             
                  end
         
     | 
| 
       44 
61 
     | 
    
         
             
                end
         
     | 
| 
       45 
62 
     | 
    
         | 
| 
       46 
     | 
    
         
            -
                describe  
     | 
| 
       47 
     | 
    
         
            -
                   
     | 
| 
       48 
     | 
    
         
            -
                     
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
      
 63 
     | 
    
         
            +
                describe '#join_rooms' do
         
     | 
| 
      
 64 
     | 
    
         
            +
                  describe 'when I have access to the room' do
         
     | 
| 
      
 65 
     | 
    
         
            +
                    it 'joins each room, registers the users and listens for messages' do
         
     | 
| 
      
 66 
     | 
    
         
            +
                      expect(Campfire::Callback).to receive(:new).
         
     | 
| 
      
 67 
     | 
    
         
            +
                        with(robot, room).
         
     | 
| 
      
 68 
     | 
    
         
            +
                        and_return(callback)
         
     | 
| 
       51 
69 
     | 
    
         | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
      
 70 
     | 
    
         
            +
                      expect(room).to receive(:join)
         
     | 
| 
      
 71 
     | 
    
         
            +
                      expect(callback).to receive(:listen)
         
     | 
| 
      
 72 
     | 
    
         
            +
                      expect(callback).to receive(:register_users)
         
     | 
| 
      
 73 
     | 
    
         
            +
             
     | 
| 
      
 74 
     | 
    
         
            +
                      subject.join_rooms
         
     | 
| 
      
 75 
     | 
    
         
            +
                    end
         
     | 
| 
       54 
76 
     | 
    
         
             
                  end
         
     | 
| 
       55 
     | 
    
         
            -
                end
         
     | 
| 
       56 
     | 
    
         
            -
              end
         
     | 
| 
       57 
77 
     | 
    
         | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
      
 78 
     | 
    
         
            +
                  describe "when I don't have access to the room" do
         
     | 
| 
      
 79 
     | 
    
         
            +
                    before do
         
     | 
| 
      
 80 
     | 
    
         
            +
                      allow(campfire).to receive(:find_room_by_id).and_return(nil)
         
     | 
| 
      
 81 
     | 
    
         
            +
                    end
         
     | 
| 
       60 
82 
     | 
    
         | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
      
 83 
     | 
    
         
            +
                    it 'raises an exception' do
         
     | 
| 
      
 84 
     | 
    
         
            +
                      expect { subject.join_rooms }.to raise_error(Campfire::RoomNotAvailable)
         
     | 
| 
      
 85 
     | 
    
         
            +
                    end
         
     | 
| 
      
 86 
     | 
    
         
            +
                  end
         
     | 
| 
       64 
87 
     | 
    
         
             
                end
         
     | 
| 
       65 
88 
     | 
    
         | 
| 
       66 
     | 
    
         
            -
                 
     | 
| 
       67 
     | 
    
         
            -
                   
     | 
| 
      
 89 
     | 
    
         
            +
                describe '#send_messages' do
         
     | 
| 
      
 90 
     | 
    
         
            +
                  context 'with a one line message' do
         
     | 
| 
      
 91 
     | 
    
         
            +
                    let(:message) { "I'm gonna drink 'til I reboot." }
         
     | 
| 
       68 
92 
     | 
    
         | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
       70 
     | 
    
         
            -
             
     | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
      
 93 
     | 
    
         
            +
                    it 'speaks each message into room' do
         
     | 
| 
      
 94 
     | 
    
         
            +
                      expect(room).to receive(:speak).with(message)
         
     | 
| 
      
 95 
     | 
    
         
            +
                      subject.send_messages room, [ message ]
         
     | 
| 
      
 96 
     | 
    
         
            +
                    end
         
     | 
| 
       72 
97 
     | 
    
         
             
                  end
         
     | 
| 
       73 
     | 
    
         
            -
                end
         
     | 
| 
       74 
98 
     | 
    
         | 
| 
       75 
     | 
    
         
            -
             
     | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
      
 99 
     | 
    
         
            +
                  context 'with a multi line message' do
         
     | 
| 
      
 100 
     | 
    
         
            +
                    let(:message) { "I'm gonna drink 'til I reboot.\nNow I'm too drunk" }
         
     | 
| 
       77 
101 
     | 
    
         | 
| 
       78 
     | 
    
         
            -
             
     | 
| 
       79 
     | 
    
         
            -
             
     | 
| 
       80 
     | 
    
         
            -
             
     | 
| 
      
 102 
     | 
    
         
            +
                    it 'pastes each message into room' do
         
     | 
| 
      
 103 
     | 
    
         
            +
                      expect(room).to receive(:paste).with(message)
         
     | 
| 
      
 104 
     | 
    
         
            +
                      subject.send_messages room, [ message ]
         
     | 
| 
      
 105 
     | 
    
         
            +
                    end
         
     | 
| 
       81 
106 
     | 
    
         
             
                  end
         
     | 
| 
       82 
107 
     | 
    
         
             
                end
         
     | 
| 
       83 
     | 
    
         
            -
              end
         
     | 
| 
       84 
108 
     | 
    
         | 
| 
       85 
     | 
    
         
            -
             
     | 
| 
       86 
     | 
    
         
            -
             
     | 
| 
       87 
     | 
    
         
            -
             
     | 
| 
       88 
     | 
    
         
            -
             
     | 
| 
       89 
     | 
    
         
            -
             
     | 
| 
       90 
     | 
    
         
            -
                   
     | 
| 
       91 
     | 
    
         
            -
             
     | 
| 
      
 109 
     | 
    
         
            +
                describe '#set_topic' do
         
     | 
| 
      
 110 
     | 
    
         
            +
                  before do
         
     | 
| 
      
 111 
     | 
    
         
            +
                    allow(Lita.logger).to receive(:info)
         
     | 
| 
      
 112 
     | 
    
         
            +
                    allow(campfire).to receive(:find_room_by_id).and_return(room)
         
     | 
| 
      
 113 
     | 
    
         
            +
                    subject.connect
         
     | 
| 
      
 114 
     | 
    
         
            +
                  end
         
     | 
| 
      
 115 
     | 
    
         
            +
                  let(:topic) { 'Let it be wadus' }
         
     | 
| 
       92 
116 
     | 
    
         | 
| 
       93 
     | 
    
         
            -
             
     | 
| 
       94 
     | 
    
         
            -
             
     | 
| 
       95 
     | 
    
         
            -
             
     | 
| 
      
 117 
     | 
    
         
            +
                  it 'sets toom topic' do
         
     | 
| 
      
 118 
     | 
    
         
            +
                    expect(room).to receive(:topic=).with(topic)
         
     | 
| 
      
 119 
     | 
    
         
            +
                    subject.set_topic(room, topic)
         
     | 
| 
      
 120 
     | 
    
         
            +
                  end
         
     | 
| 
       96 
121 
     | 
    
         
             
                end
         
     | 
| 
       97 
122 
     | 
    
         
             
              end
         
     | 
| 
       98 
123 
     | 
    
         
             
            end
         
     | 
| 
         @@ -13,8 +13,8 @@ describe Lita::Adapters::Campfire do 
     | 
|
| 
       13 
13 
     | 
    
         | 
| 
       14 
14 
     | 
    
         
             
              subject { described_class.new(robot) }
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
       16 
     | 
    
         
            -
              let(:robot) {  
     | 
| 
       17 
     | 
    
         
            -
              let(:connector) {  
     | 
| 
      
 16 
     | 
    
         
            +
              let(:robot) { instance_double(Lita::Robot) }
         
     | 
| 
      
 17 
     | 
    
         
            +
              let(:connector) { instance_double(Lita::Adapters::Campfire::Connector) }
         
     | 
| 
       18 
18 
     | 
    
         | 
| 
       19 
19 
     | 
    
         
             
              it "registers with Lita" do
         
     | 
| 
       20 
20 
     | 
    
         
             
                expect(Lita.adapters[:campfire]).to eql(described_class)
         
     | 
| 
         @@ -26,6 +26,26 @@ describe Lita::Adapters::Campfire do 
     | 
|
| 
       26 
26 
     | 
    
         
             
                expect { subject }.to raise_error(SystemExit)
         
     | 
| 
       27 
27 
     | 
    
         
             
              end
         
     | 
| 
       28 
28 
     | 
    
         | 
| 
      
 29 
     | 
    
         
            +
              context 'passing optional variables' do
         
     | 
| 
      
 30 
     | 
    
         
            +
                optional_config = described_class::OPTIONAL_CONFIG_OPTIONS
         
     | 
| 
      
 31 
     | 
    
         
            +
                optional_config.each do |option|
         
     | 
| 
      
 32 
     | 
    
         
            +
                  it "does not set #{option} hash value if option is not set" do
         
     | 
| 
      
 33 
     | 
    
         
            +
                    expect(described_class::Connector).not_to receive(:new).with(robot, hash_including(option.to_sym))
         
     | 
| 
      
 34 
     | 
    
         
            +
                    subject
         
     | 
| 
      
 35 
     | 
    
         
            +
                  end
         
     | 
| 
      
 36 
     | 
    
         
            +
                end
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
                it 'can receive hash with tinder options' do
         
     | 
| 
      
 39 
     | 
    
         
            +
                  tinder_options = { timeout: 30, auto_reconnect: false }
         
     | 
| 
      
 40 
     | 
    
         
            +
                  Lita.configure do |config|
         
     | 
| 
      
 41 
     | 
    
         
            +
                    config.adapter.tinder_options = tinder_options
         
     | 
| 
      
 42 
     | 
    
         
            +
                  end
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
                  expect(described_class::Connector).to receive(:new).with(robot, hash_including(:tinder_options => tinder_options))
         
     | 
| 
      
 45 
     | 
    
         
            +
                  subject
         
     | 
| 
      
 46 
     | 
    
         
            +
                end
         
     | 
| 
      
 47 
     | 
    
         
            +
              end
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
       29 
49 
     | 
    
         
             
              describe '#run' do
         
     | 
| 
       30 
50 
     | 
    
         
             
                before do
         
     | 
| 
       31 
51 
     | 
    
         
             
                  allow(subject.connector).to receive(:connect)
         
     | 
| 
         @@ -59,7 +79,7 @@ describe Lita::Adapters::Campfire do 
     | 
|
| 
       59 
79 
     | 
    
         | 
| 
       60 
80 
     | 
    
         
             
              describe '#send_messages' do
         
     | 
| 
       61 
81 
     | 
    
         
             
                it 'sends messages to rooms' do
         
     | 
| 
       62 
     | 
    
         
            -
                  source =  
     | 
| 
      
 82 
     | 
    
         
            +
                  source = instance_double(Lita::Source, room: "room_id")
         
     | 
| 
       63 
83 
     | 
    
         
             
                  expect(subject.connector).to receive(:send_messages).with(
         
     | 
| 
       64 
84 
     | 
    
         
             
                    'room_id',
         
     | 
| 
       65 
85 
     | 
    
         
             
                    ["Hello!"]
         
     | 
| 
         @@ -70,7 +90,7 @@ describe Lita::Adapters::Campfire do 
     | 
|
| 
       70 
90 
     | 
    
         | 
| 
       71 
91 
     | 
    
         
             
              describe "#set_topic" do
         
     | 
| 
       72 
92 
     | 
    
         
             
                it "sets a new topic for a room" do
         
     | 
| 
       73 
     | 
    
         
            -
                  source =  
     | 
| 
      
 93 
     | 
    
         
            +
                  source = instance_double(Lita::Source, room: "room_id")
         
     | 
| 
       74 
94 
     | 
    
         
             
                  expect(subject.connector).to receive(:set_topic).with(
         
     | 
| 
       75 
95 
     | 
    
         
             
                    "room_id",
         
     | 
| 
       76 
96 
     | 
    
         
             
                    "Topic"
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: lita-campfire
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.1. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.1.4
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Jose Luis Salas
         
     | 
| 
         @@ -9,7 +9,7 @@ authors: 
     | 
|
| 
       9 
9 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       10 
10 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       11 
11 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       12 
     | 
    
         
            -
            date: 2014-01- 
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2014-01-12 00:00:00.000000000 Z
         
     | 
| 
       13 
13 
     | 
    
         
             
            dependencies:
         
     | 
| 
       14 
14 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       15 
15 
     | 
    
         
             
              name: lita
         
     | 
| 
         @@ -163,4 +163,3 @@ test_files: 
     | 
|
| 
       163 
163 
     | 
    
         
             
            - spec/lita/adapters/campfire/connector_spec.rb
         
     | 
| 
       164 
164 
     | 
    
         
             
            - spec/lita/adapters/campfire_spec.rb
         
     | 
| 
       165 
165 
     | 
    
         
             
            - spec/spec_helper.rb
         
     | 
| 
       166 
     | 
    
         
            -
            has_rdoc: 
         
     |