lib/talkbird/entity/channel.rb in talkbird-0.0.2 vs lib/talkbird/entity/channel.rb in talkbird-0.0.3

- old
+ new

@@ -25,16 +25,23 @@ limit: 1 } ) if result.is_a?(Result::Success) - Channel.new(result.body[:channels].first) + Channel.build(result.body[:channels].first) else false end end + # Build a channel based on the current payload. + # + # @return [Channel, Boolean] + def build(payload) + !payload.empty? && Channel.new(payload) + end + def create(from, to, opts = {}) body = DEFAULTS.merge(opts) body[:channel_url] = opts.fetch(:id) { SecureRandom.uuid } body[:user_ids] = [from, to] @@ -64,27 +71,33 @@ def id @data[:channel_url] end + def name + @data[:name] + end + + def members + @data[:members].map { |hsh| Entity::User.new(hsh) } + end + def update(message) body = { user_id: message.sender.id, message: message.body, message_type: 'MESG', } - result = Client.request( + Client.request( :post, "group_channels/#{id}/messages", body: body ) + end - if result.is_a?(Result::Success) - Entity::Message.build(result.body) - else - false - end + def to_s + "#<Talkbird::Entity::Channel id=#{id}>" end end end end