del 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5a4e9193a7e58ecb7c4195cc44959af6ae915e8d189cb68367419af260419844
4
- data.tar.gz: cc390be8a96218d8d8d6ececf6c944f90c46e1d4a44940bfba6c448e59b93cc9
3
+ metadata.gz: c574a58daf5543a9f5d1f49c78d7fd78f67864eb1050e7188dcb4e14b7039c24
4
+ data.tar.gz: d55ed1168a7a9b1aaeb5a0acc6fa250660e91d0911620a6a9f58ac1a0f0dada4
5
5
  SHA512:
6
- metadata.gz: b9c261aa11e6a3c6aedb608ec33f4c7cf8b1095d000cf7ffd9e161b2ec48cc23a82e1debfa34e05339327cbedee4419a573730fd514a7a5ba78926085ae8b78a
7
- data.tar.gz: 409e76bd0714896bc2cf469b32664defda74df568a7062e41173ed1511e5b06f10088d81d290116186fb360bad0604f441a432d7fb80b1b85b5c2738c2df587a
6
+ metadata.gz: a7a6b876e15aa871a6269535dad1a5c2fbdd8271aa65bef32ae6b24f57bc300c482619351e03484aaff40cadbaa89a743242e6f653481105469a707c08ed9421
7
+ data.tar.gz: c9033ec43b82049cc6c5adbb1a77236f7c615929139a9b4493221840860aeb85000cdf13cb795d9e71f14c69e27ab65c10cc341af7b8a29cd456a2642afed6d0
data/exe/del CHANGED
@@ -3,7 +3,6 @@
3
3
  require "del"
4
4
  require "pathname"
5
5
 
6
- home = Pathname.new(Dir.home)
7
6
  Del.start(
8
- dotenv_file: ENV.fetch("DELRC", home.join(".delrc").to_s)
7
+ dotenv_file: ENV.fetch("DELRC", Pathname.new(Dir.home).join(".delrc"))
9
8
  )
@@ -2,14 +2,15 @@ module Del
2
2
  class Connection
3
3
  attr_reader :configuration, :rooms, :users
4
4
 
5
- def initialize(configuration:, users:, rooms:)
5
+ def initialize(configuration:)
6
6
  @configuration = configuration
7
- @rooms = rooms
8
- @users = users
7
+ @rooms = configuration[:rooms]
8
+ @users = configuration[:users]
9
9
  end
10
10
 
11
11
  def connect(robot)
12
12
  client.on_exception do |error, connection, error_source|
13
+ Del.logger.error(error)
13
14
  disconnect
14
15
  end
15
16
  client.connect(configuration[:host])
@@ -17,7 +18,7 @@ module Del
17
18
  client.auth(configuration[:password])
18
19
  roster = Jabber::Roster::Helper.new(client, false)
19
20
  roster.add_update_callback do |old_item, item|
20
- users.create(item) if item
21
+ users.upsert(item['jid'], item.attributes.to_h) if item
21
22
  end
22
23
  roster.get_roster
23
24
  roster.wait_for_roster
@@ -0,0 +1,7 @@
1
+ module Del
2
+ class DefaultRouter
3
+ def route(message)
4
+ Del.logger.debug(message)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,16 @@
1
+ module Del
2
+ class Repository
3
+ def initialize(storage = {})
4
+ @storage = storage
5
+ end
6
+
7
+ def find_by(id)
8
+ @storage[id]
9
+ end
10
+
11
+ def upsert(id, attributes = {})
12
+ Del.logger.debug([id, attributes].inspect)
13
+ @storage[id] = attributes
14
+ end
15
+ end
16
+ end
data/lib/del/robot.rb CHANGED
@@ -1,13 +1,13 @@
1
1
  module Del
2
2
  class Robot
3
- attr_reader :connection
3
+ attr_reader :connection, :router
4
+ attr_reader :users, :rooms
4
5
 
5
6
  def initialize(configuration:)
6
- @connection = Connection.new(
7
- configuration: configuration,
8
- users: users,
9
- rooms: rooms,
10
- )
7
+ @connection = Connection.new(configuration: configuration)
8
+ @router = configuration[:router]
9
+ @users = configuration[:users]
10
+ @rooms = configuration[:rooms]
11
11
  end
12
12
 
13
13
  def get_funky!
@@ -18,21 +18,11 @@ module Del
18
18
  end
19
19
 
20
20
  def receive(message)
21
- send_message(message.from, message.body)
21
+ router.route(message)
22
22
  end
23
23
 
24
24
  def send_message(jid, message)
25
25
  connection.deliver(jid, message)
26
26
  end
27
-
28
- private
29
-
30
- def users
31
- @users ||= UserRepository.new
32
- end
33
-
34
- def rooms
35
- @rooms ||= RoomRepository.new
36
- end
37
27
  end
38
28
  end
data/lib/del/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Del
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/del.rb CHANGED
@@ -1,20 +1,20 @@
1
1
  require "dotenv"
2
+ require "logger"
2
3
  require "xmpp4r"
3
4
  require "xmpp4r/muc/helper/mucbrowser"
4
5
  require "xmpp4r/muc/helper/simplemucclient"
5
6
  require "xmpp4r/roster/helper/roster"
6
7
 
7
8
  require "del/connection"
9
+ require "del/default_router"
8
10
  require "del/robot"
9
- require "del/room_repository"
10
- require "del/user"
11
- require "del/user_repository"
11
+ require "del/repository"
12
12
  require "del/version"
13
13
 
14
14
  module Del
15
15
  def self.start(dotenv_file:)
16
16
  puts "Loading... #{dotenv_file}"
17
- Dotenv.load(dotenv_file)
17
+ Dotenv.load(dotenv_file.to_s)
18
18
  puts "It's fire! 🔥"
19
19
  del = Robot.new(configuration: configuration)
20
20
  del.get_funky!
@@ -28,8 +28,16 @@ module Del
28
28
  @configuration ||= {
29
29
  host: ENV.fetch("DEL_HOST"),
30
30
  jid: ENV.fetch("DEL_JID"),
31
+ logger: Logger.new(STDOUT),
31
32
  muc_domain: ENV.fetch("DEL_MUC_DOMAIN"),
32
33
  password: ENV.fetch("DEL_PASSWORD"),
34
+ rooms: Repository.new,
35
+ router: DefaultRouter.new,
36
+ users: Repository.new,
33
37
  }
34
38
  end
39
+
40
+ def self.logger
41
+ @logger ||= configuration[:logger]
42
+ end
35
43
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: del
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - mo
@@ -101,10 +101,9 @@ files:
101
101
  - exe/del
102
102
  - lib/del.rb
103
103
  - lib/del/connection.rb
104
+ - lib/del/default_router.rb
105
+ - lib/del/repository.rb
104
106
  - lib/del/robot.rb
105
- - lib/del/room_repository.rb
106
- - lib/del/user.rb
107
- - lib/del/user_repository.rb
108
107
  - lib/del/version.rb
109
108
  homepage: https://www.mokhan.ca
110
109
  licenses:
@@ -1,11 +0,0 @@
1
- module Del
2
- class RoomRepository
3
- def initialize
4
- @rooms = Set.new
5
- end
6
-
7
- def upsert(room)
8
- @rooms << room
9
- end
10
- end
11
- end
data/lib/del/user.rb DELETED
@@ -1,7 +0,0 @@
1
- module Del
2
- class User
3
- def initialize(attributes)
4
- @attributes = attributes
5
- end
6
- end
7
- end
@@ -1,11 +0,0 @@
1
- module Del
2
- class UserRepository
3
- def initialize
4
- @users = Set.new
5
- end
6
-
7
- def create(item)
8
- @users << User.new(item.attributes)
9
- end
10
- end
11
- end