babili 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
  SHA1:
3
- metadata.gz: 6954bc37e3d4e05bc3eb8f6bc005330b7fcac76f
4
- data.tar.gz: 535fd17e9a122105b24e11f8f0ab2c559fb8fc24
3
+ metadata.gz: c33fccaa691748ae5049724230cd6c736c6b26e3
4
+ data.tar.gz: c070c8d1472af4aa32d1d2306e7249df96ca4cca
5
5
  SHA512:
6
- metadata.gz: 9f291b413da667dac15267bdcdbc1f5b366b0057eff36490e2ceb8056974e36e341cfcab6b2d0f6af9bb8e9fe73ffc103e07593c5fba4451441821639168bb24
7
- data.tar.gz: 7cd849262b6d3b195f9c7b36396663c1c219df62b09bd57e84d034a00a45ccaedaba2b616ed43e1a56182b17f149d135bf7f1d9967489cc1f731948d7b8380a9
6
+ metadata.gz: 58de0eee0618e82bd8c3242843ccf6531b1ce31bc62ec8adcf3933d3123c919171dad2a7973ff1132d6c80f86108ee6b0586e06b85dd381f9cdbce99e4251cab
7
+ data.tar.gz: 3ea0f1d4ed0b976caa6696220c1526c528bbb913fc747296855f779ef44d15f27de8bbe1c36be90335a6884c1c1e449b268680a45aeceb6f3b842fade4302278
@@ -5,6 +5,29 @@ module Babili
5
5
  "platform/rooms/:room_id/messages"
6
6
  end
7
7
 
8
+ def self.all_for_room(room_id)
9
+ create_path = path.gsub(":room_id", room_id)
10
+ messages = []
11
+ previous_first_seen_message_id = false
12
+ first_seen_message_id = nil
13
+ while previous_first_seen_message_id != first_seen_message_id
14
+ previous_first_seen_message_id = first_seen_message_id
15
+ if first_seen_message_id
16
+ raw_messages = Babili::Client.get(create_path + "?firstSeenMessageId=#{first_seen_message_id}")
17
+ else
18
+ raw_messages = Babili::Client.get(create_path)
19
+ end
20
+
21
+ return messages if raw_messages["data"].empty?
22
+ messages.concat(raw_messages["data"].map do |raw_message|
23
+ message = new(raw_message["attributes"])
24
+ message.id = raw_message["id"]
25
+ message
26
+ end)
27
+ first_seen_message_id = raw_messages["data"].first["id"]
28
+ end
29
+ end
30
+
8
31
  def self.create(params = {})
9
32
  room_id = params.delete(:room_id)
10
33
  create_path = path.gsub(":room_id", room_id)
@@ -21,6 +21,10 @@ module Babili
21
21
  rooms.concat(raw_rooms["data"].map do |raw_room|
22
22
  room = new(raw_room["attributes"])
23
23
  room.id = raw_room["id"]
24
+ room.users = raw_room["relationships"]["users"]["data"].map do |raw_user|
25
+ user = Babili::Platform::User.new({id: raw_user["id"]})
26
+ user
27
+ end
24
28
  room
25
29
  end)
26
30
  first_seen_room_id = raw_rooms["data"].last["id"]
@@ -59,6 +63,10 @@ module Babili
59
63
  room
60
64
  end
61
65
 
66
+ def messages
67
+ Babili::Platform::Message.all_for_room(self.id)
68
+ end
69
+
62
70
  def delete
63
71
  path = self.class.path + "/#{id}"
64
72
  raw_room = Babili::Client.delete(path)["data"]
@@ -66,16 +74,6 @@ module Babili
66
74
  room.id = raw_room["id"]
67
75
  room
68
76
  end
69
-
70
- def users
71
- path = self.class.path + "/#{id}/users"
72
- raw_users = Babili::Client.get(path)
73
- raw_users["data"].map do |raw_user|
74
- user = Babili::Platform::User.new(raw_user["attributes"])
75
- user.id = raw_user["id"]
76
- user
77
- end
78
- end
79
77
  end
80
78
  end
81
79
  end
@@ -1,3 +1,3 @@
1
1
  module Babili
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: babili
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
  - Spin42
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-02 00:00:00.000000000 Z
11
+ date: 2016-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client