pusher-chatkit-server 1.7.1 → 1.9.0

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: 21f7fc77c0c7aa5f1e6d7eb1a082fdea41d1066a
4
- data.tar.gz: 92cce307542e7a91a739b288711dcc7854e608b5
3
+ metadata.gz: 8f1360ff9feccb4f766894cdab7fdd2e5b70df22
4
+ data.tar.gz: 7d55dd3ce6c62b4e9f16afed095c0a1cc0344342
5
5
  SHA512:
6
- metadata.gz: 7fd5f0ae30b9fefef2ea92eed46140692e144dd4e13838baca12a10e339a17f225c3e20165b99a90b8f3b31cf8cd5f8555506ec534f590bad0634b7d4203bed4
7
- data.tar.gz: b93862eea058fbcbf4ba0ffd4c99a123d8dd663d642d3a4a151968a5fa4121d5420b0357a865c193acd5e43d8ee08e6ba6e9bde9a7e040bd39a88e7c871adef4
6
+ metadata.gz: fbd3b994d6dde617c0901f048fe37fcca0af44239882c0f727d7482bf1e6e8e96c4b7b58d33b256c4a2c03236ca59da39ecc91e09ca9c6046dbaffc898e9be72
7
+ data.tar.gz: 362a87278223cfbb96a88027e81f97c13c72b74ff6b5b152290566672f441b419c3dabaf04b34dcd976f6477fc0519b3f5ab1b5a7c54ea543015ea9053a41734
@@ -531,6 +531,126 @@ module Chatkit
531
531
  })
532
532
  end
533
533
 
534
+ def edit_simple_message(room_id, message_id, options)
535
+ verify({text: "You must provide some text for the message",
536
+ }, options)
537
+
538
+ options[:parts] = [{type: "text/plain",
539
+ content: options[:text]
540
+ }]
541
+
542
+ edit_multipart_message(room_id, message_id, options)
543
+ end
544
+
545
+ def edit_multipart_message(room_id, message_id, options)
546
+ verify({
547
+ sender_id: "You must provide the ID of the user editing the message",
548
+ parts: "You must provide a parts array",
549
+ }, options)
550
+ verify({
551
+ room_id: "You must provide the ID of the room in which the message to edit belongs",
552
+ message_id: "You must provide the ID of the message to edit",
553
+ }, {room_id: room_id, message_id: message_id})
554
+ if !options['room_id'].nil?
555
+ raise Chatkit::UnexpectedParameterError.new("a messages room id cannot be edited")
556
+ end
557
+ if !options['message_id'].nil?
558
+ raise Chatkit::UnexpectedParameterError.new("a messages id cannot be edited")
559
+ end
560
+
561
+ if not options[:parts].length > 0
562
+ raise Chatkit::MissingParameterError.new("parts array must have at least one item")
563
+ end
564
+
565
+ # this assumes the token lives long enough to finish all S3 uploads
566
+ token = generate_su_token({ user_id: options[:sender_id] })[:token]
567
+
568
+ request_parts = options[:parts].map { |part|
569
+ verify({type: "Each part must define a type"}, part)
570
+
571
+ if !part[:content].nil?
572
+ {
573
+ type: part[:type],
574
+ content: part[:content]
575
+ }
576
+ elsif !part[:url].nil?
577
+ {
578
+ type: part[:type],
579
+ url: part[:url]
580
+ }
581
+ elsif !part[:file].nil?
582
+ attachment_id = upload_attachment(token, room_id, part)
583
+ {
584
+ type: part[:type],
585
+ attachment: {id: attachment_id},
586
+ }.reject{ |_,v| v.nil? }
587
+ else
588
+ raise Chatkit::MissingParameterError.new("Each part must have one of :file, :content or :url")
589
+ end
590
+ }
591
+
592
+ api_request({
593
+ method: "PUT",
594
+ path: "/rooms/#{CGI::escape room_id}/messages/#{message_id}",
595
+ body: {parts: request_parts},
596
+ jwt: token
597
+ })
598
+ end
599
+
600
+ def edit_message(room_id, message_id, options)
601
+ if room_id.nil?
602
+ raise Chatkit::MissingParameterError.new("You must provide the ID of the room in which the message to edit belongs")
603
+ end
604
+
605
+ if message_id.nil?
606
+ raise Chatkit::MissingParameterError.new("You must provide the ID of the message to edit")
607
+ end
608
+
609
+ if options[:sender_id].nil?
610
+ raise Chatkit::MissingParameterError.new("You must provide the ID of the user editing the message")
611
+ end
612
+
613
+ if options[:text].nil?
614
+ raise Chatkit::MissingParameterError.new("You must provide some text for the message")
615
+ end
616
+
617
+ if !options['room_id'].nil?
618
+ raise Chatkit::UnexpectedParameterError.new("a messages room id cannot be edited")
619
+ end
620
+ if !options['message_id'].nil?
621
+ raise Chatkit::UnexpectedParameterError.new("a messages id cannot be edited")
622
+ end
623
+
624
+
625
+ attachment = options[:attachment]
626
+
627
+ unless attachment.nil?
628
+ if attachment[:resource_link].nil?
629
+ raise Chatkit::MissingParameterError.new("You must provide a resource_link for the message attachment")
630
+ end
631
+
632
+ valid_file_types = ['image', 'video', 'audio', 'file']
633
+
634
+ if attachment[:type].nil? || !valid_file_types.include?(attachment[:type])
635
+ raise Chatkit::MissingParameterError.new(
636
+ "You must provide a valid type for the message attachment, i.e. one of: #{valid_file_types.join(', ')}"
637
+ )
638
+ end
639
+ end
640
+
641
+ payload = {
642
+ text: options[:text],
643
+ attachment: options[:attachment]
644
+ }
645
+
646
+ api_v2_request({
647
+ method: "PUT",
648
+ path: "/rooms/#{CGI::escape room_id}/messages/#{message_id}",
649
+ body: payload,
650
+ jwt: generate_su_token({ user_id: options[:sender_id] })[:token]
651
+ })
652
+ end
653
+
534
654
  # Roles and permissions API
535
655
 
536
656
  def create_global_role(options)
@@ -0,0 +1,16 @@
1
+ require_relative './error'
2
+
3
+ module Chatkit
4
+ class UnexpectedParameterError < Chatkit::Error
5
+ attr_accessor :message
6
+
7
+ def initialize(message)
8
+ @message = message
9
+ end
10
+
11
+ def to_s
12
+ "Chatkit::UnexpectedParameterError - #{@message}"
13
+ end
14
+
15
+ end
16
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pusher-chatkit-server
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.1
4
+ version: 1.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pusher
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-28 00:00:00.000000000 Z
11
+ date: 2019-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pusher-platform
@@ -35,6 +35,7 @@ files:
35
35
  - lib/chatkit/error.rb
36
36
  - lib/chatkit/missing_parameter_error.rb
37
37
  - lib/chatkit/response_error.rb
38
+ - lib/chatkit/unexpected_parameter_error.rb
38
39
  - lib/chatkit/upload_error.rb
39
40
  homepage:
40
41
  licenses:
@@ -56,7 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
56
57
  version: '0'
57
58
  requirements: []
58
59
  rubyforge_project:
59
- rubygems_version: 2.6.14
60
+ rubygems_version: 2.5.2
60
61
  signing_key:
61
62
  specification_version: 4
62
63
  summary: Pusher Chatkit Ruby SDK