-
-
Notifications
You must be signed in to change notification settings - Fork 222
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
Showing
17 changed files
with
160 additions
and
11 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
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
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
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
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
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
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require 'slack/real_time/models/base' | ||
require 'slack/real_time/models/user' |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module Slack | ||
module RealTime | ||
module Models | ||
class Base < Hash | ||
def initialize(attrs = {}) | ||
attrs.each do |k, v| | ||
self[k] = v | ||
end | ||
end | ||
end | ||
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module Slack | ||
module RealTime | ||
module Models | ||
class User < Base | ||
end | ||
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require 'slack/real_time/store/memory' | ||
require 'slack/real_time/store/handlers' |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require 'slack/real_time/store/handlers/user_change' | ||
require 'slack/real_time/store/handlers/team_join' |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Slack | ||
module RealTime | ||
module Store | ||
module Handlers | ||
module TeamJoin | ||
def self.call(client, data) | ||
client.users[data['user']['id']] = Models::User.new(data['user']) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
Slack::RealTime::Client.events['team_join'] = Slack::RealTime::Store::Handlers::TeamJoin |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Slack | ||
module RealTime | ||
module Store | ||
module Handlers | ||
module UserChange | ||
def self.call(client, data) | ||
client.users[data['user']['id']] = Models::User.new(data['user']) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
Slack::RealTime::Client.events['user_change'] = Slack::RealTime::Store::Handlers::UserChange |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module Slack | ||
module RealTime | ||
module Store | ||
class Memory | ||
attr_accessor :users | ||
|
||
def initialize(attrs = {}) | ||
@users = {} | ||
attrs['users'].each do |data| | ||
@users[data['id']] = Models::User.new(data) | ||
end | ||
end | ||
end | ||
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_start' } do | ||
include_context 'connected client' | ||
|
||
describe '#user_change' do | ||
it 'updates user in store' do | ||
expect(client.users['U07KECJ77']['name']).to eq 'aws' | ||
event = Slack::RealTime::Event.new( | ||
'type' => 'user_change', | ||
'user' => { | ||
'id' => 'U07KECJ77', 'name' => 'renamed' | ||
}) | ||
client.send(:dispatch, event) | ||
expect(client.users['U07KECJ77']['name']).to eq 'renamed' | ||
end | ||
end | ||
describe '#team_join' do | ||
it 'creates a user in store' do | ||
expect do | ||
event = Slack::RealTime::Event.new( | ||
'type' => 'team_join', | ||
'user' => { | ||
'id' => 'DEADBEEF', 'name' => 'added' | ||
}) | ||
client.send(:dispatch, event) | ||
end.to change(client.users, :count).by(1) | ||
expect(client.users['DEADBEEF']['name']).to eq 'added' | ||
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
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module Slack | ||
module RealTime | ||
class Event | ||
attr_accessor :data | ||
|
||
def initialize(data) | ||
@data = data.to_json | ||
end | ||
end | ||
end | ||
end |