Sha256: 55d568edcd7b028913caf9c7f82841ee9d92a74ff78b170a5a636b110f9d8b4c
Contents?: true
Size: 1.4 KB
Versions: 2
Compression:
Stored size: 1.4 KB
Contents
module SmsTraffic class Client class DeliverReply < Client::Reply OK_REPLY = 'OK'.freeze unless const_defined?(:OK_REPLY) def ok? fetch_value(hash, :result) == OK_REPLY end def error? !ok? end def result fetch_value(hash, :result) end def code fetch_value(hash, :code) end def description fetch_value(hash, :description) end def message_infos fetch_value(hash, :message_infos) end def sms_id(phone = nil) message_info = fetch_value(message_infos, :message_info) return fetch_value(message_info, :sms_id) if message_info.is_a?(Hash) raise ArgumentError, 'phone is required' unless phone fetch_value(find_message_info(phone), :sms_id) end def sms_ids message_info = fetch_value(message_infos, :message_info) return [fetch_value(message_info, :sms_id)] if message_info.size == 1 message_info.each_with_object({}) do |info, hash| hash[fetch_value(info, :phone)] = fetch_value(info, :sms_id) end end def error_description "#{result}: code: #{code}, description: #{description}" if error? end private def find_message_info(phone) fetch_value(message_infos, :message_info).find { |info| fetch_value(info, :phone) == phone } end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
sms_traffic_sdk-0.0.2 | lib/sms_traffic/client/deliver_reply.rb |
sms_traffic_sdk-0.0.1 | lib/sms_traffic/client/deliver_reply.rb |