talkbird 0.0.4 → 0.0.5

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: af5f49ac85bfdd9a94c8f8777524c3e159d35ee8be41d2671ef1f52144e61285
4
- data.tar.gz: 7c13764379479a00cf063db817f13d6e1d9c0f737aee1cbe8aa7c2d986084ddf
3
+ metadata.gz: 8d19f0c6015b1e3ae92ec3f845fd9b7e95ce6a50edfc19d831e4e6d1be24f8ce
4
+ data.tar.gz: 5db2f957f25ea0c3be235f8a397cfc055ed7f8ec173a90c385f6d2670a735e20
5
5
  SHA512:
6
- metadata.gz: cd87f26adaad2bcf56033bc85bbcdea36a5e0dc11e996bfe82afa0da5c37f2de36e991c5abd208cdbe566b2d3e40de6992409d5293beba17ed5ef6d6bb2c5a6f
7
- data.tar.gz: aa142f491722c132186fe04a8bd30934558e62533722898ce3541e55fbd0934b03af5fd59f2b5e0e93683d6faa1f96ca435c4fe4813359611577fdcf44c16c80
6
+ metadata.gz: 5b22a45c0cd569e2b156ecab22477fad98183e0c81e2e398594b647a6f75a6b172bbeaa3b2b9d388e19a407ce1fe413afa01c1ee89603e709ec345fcd607798b
7
+ data.tar.gz: 71b52c8ea2d004e4b722f2eec558580baccaef2264a8b81b13568342e6e413829f41e593855f0803f15871ba8f4fc2eacc784cd3d167a6ebb635fcb346ad5380
@@ -31,11 +31,12 @@ module Talkbird
31
31
  limit: 1
32
32
  }
33
33
  )
34
+ channels = result.body[:channels] || []
34
35
 
35
36
  # Since this is the result of a search, the response can be an empty
36
37
  # array, in which case the result should also be false.
37
- if result.is_a?(Result::Success) && !result.body[:channels].empty?
38
- Channel.build(result.body[:channels].first)
38
+ if result.is_a?(Result::Success) && !channels.empty?
39
+ Channel.build(channels.first)
39
40
  else
40
41
  false
41
42
  end
@@ -90,21 +91,15 @@ module Talkbird
90
91
  end
91
92
 
92
93
  def update(message)
93
- body = {
94
- user_id: message.sender.id,
95
- message: message.body,
96
- message_type: 'MESG',
97
- }
98
-
99
94
  Client.request(
100
95
  :post,
101
96
  "group_channels/#{id}/messages",
102
- body: body
97
+ body: message.to_h
103
98
  )
104
99
  end
105
100
 
106
101
  def to_s
107
- "#<Talkbird::Entity::Channel id=#{id} name=#>"
102
+ "#<Talkbird::Entity::Channel id=#{id} name=#{name} members=#{members}>"
108
103
  end
109
104
 
110
105
  end
@@ -9,6 +9,10 @@ module Talkbird
9
9
  attr_reader :receiver
10
10
  attr_reader :body
11
11
 
12
+ DEFAULTS = {
13
+ type: 'MESG'
14
+ }.freeze
15
+
12
16
  class << self
13
17
 
14
18
  def build(response)
@@ -17,10 +21,12 @@ module Talkbird
17
21
 
18
22
  end
19
23
 
20
- def initialize(from, to, body)
24
+ def initialize(from, to, body, options = {})
21
25
  @sender = User.find_or_create(from)
22
26
  @receiver = User.find_or_create(to)
23
27
  @body = body
28
+
29
+ @options = options
24
30
  end
25
31
 
26
32
  def deliver
@@ -30,6 +36,17 @@ module Talkbird
30
36
  channel.update(self)
31
37
  end
32
38
 
39
+ def to_h
40
+ options.merge(
41
+ user_id: sender.id,
42
+ message: body
43
+ )
44
+ end
45
+
46
+ def options
47
+ DEFAULTS.merge(@options)
48
+ end
49
+
33
50
  end
34
51
  end
35
52
  end
@@ -151,8 +151,8 @@ module Talkbird
151
151
  # @param text [String] The message body
152
152
  #
153
153
  # @return [Boolean]
154
- def message(to, text)
155
- Entity::Message.new(self, to, text).deliver
154
+ def message(to, text, opts = {})
155
+ Entity::Message.new(self, to, text, opts).deliver
156
156
  end
157
157
 
158
158
  def to_h
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Talkbird
4
4
 
5
- VERSION = '0.0.4'
5
+ VERSION = '0.0.5'
6
6
 
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: talkbird
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrei Maxim
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-05 00:00:00.000000000 Z
11
+ date: 2019-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport