Commit 688eb432 by Francis Zhou

fix at_mobiles generated hash

parent 07d8eeec
# frozen_string_literal: true # frozen_string_literal: true
require 'json'
require 'base64' require 'base64'
require 'openssl' require 'openssl'
require 'dingtalk_sdk' require 'dingtalk_sdk'
...@@ -117,9 +116,9 @@ module DingtalkSdk ...@@ -117,9 +116,9 @@ module DingtalkSdk
} }
end end
def at_mobile(mobile) def at_mobiles(mobiles)
@is_at_all = false @is_at_all = false
@at_mobile_list = [*mobile].map(&:to_s).uniq @at_mobile_list = [*mobiles].map(&:to_s).uniq
end end
def at_all def at_all
...@@ -132,16 +131,12 @@ module DingtalkSdk ...@@ -132,16 +131,12 @@ module DingtalkSdk
h.merge! @mesg h.merge! @mesg
if @is_at_all if @is_at_all
h[:isAtAll] = true h[:at] = { isAtAll: true }
elsif @at_mobile_list.try(:size).try(:positive?) elsif @at_mobile_list.try(:size).try(:positive?)
h[:atMobiles] = @at_mobile_list h[:at] = { isAtAll: false, atMobiles: @at_mobile_list }
end end
end end
end end
def to_json(*_args)
JSON.generate to_h
end
end end
end end
end end
...@@ -38,18 +38,17 @@ RSpec.describe DingtalkSdk::Robot do ...@@ -38,18 +38,17 @@ RSpec.describe DingtalkSdk::Robot do
expect(mesg_h[:msgtype]).to eq('text') expect(mesg_h[:msgtype]).to eq('text')
expect(mesg_h[:text][:content]).to eq('hello world') expect(mesg_h[:text][:content]).to eq('hello world')
expect(mesg_h[:isAtAll]).to be_nil expect(mesg_h[:at]).to be_nil
expect(mesg_h[:atMobiles]).to be_nil
end end
it 'should compose message with at mobiles' do it 'should compose message with at mobiles' do
builder = DingtalkSdk::Robot::MessageBuilder.new builder = DingtalkSdk::Robot::MessageBuilder.new
builder.text text: 'hello world' builder.text text: 'hello world'
builder.at_mobile [123, 456] builder.at_mobiles [123, 456]
mesg_h = builder.to_h mesg_h = builder.to_h
expect(mesg_h[:isAtAll]).to be_nil expect(mesg_h[:at][:isAtAll]).to be_nil
expect(mesg_h[:atMobiles]).to eq(%w[123 456]) expect(mesg_h[:at][:atMobiles]).to eq(%w[123 456])
end end
end end
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment