lib/response.rb in textmagic-0.2.0 vs lib/response.rb in textmagic-0.2.1

- old
+ new

@@ -56,25 +56,25 @@ end module Send #:nodoc: all def self.extended(base) - return unless base.is_a?(Hash) - base['message_id_hash'] = base.delete('message_id').invert if base['message_id'] - base['message_ids'] = base['message_id_hash'].values.sort if base['message_id_hash'] + return unless base.is_a?(Hash) && base['message_id'] + base['message_ids'] = base['message_id'].keys.sort + base.merge! base.delete('message_id').invert end - %w(message_id_hash message_ids sent_text parts_count).each do |method| + %w(message_ids sent_text parts_count).each do |method| module_eval <<-EOS def #{method} self['#{method}'] end EOS end def message_id(phone = nil) - phone ? message_id_hash[phone] : message_ids.first + phone ? self[phone] : self['message_ids'].first end end module MessageStatus #:nodoc: all @@ -102,16 +102,17 @@ module Receive #:nodoc: all def self.extended(base) return unless base.is_a?(Hash) && base['messages'] + base['message_ids'] = base['messages'].collect { |message| message['message_id'] }.sort base['messages'].each do |message| message['timestamp'] = Time.at(message['timestamp'].to_i) if message['timestamp'] message.extend Message end end - %w(messages unread).each do |method| + %w(messages message_ids unread).each do |method| module_eval <<-EOS, __FILE__, __LINE__ + 1 def #{method} self['#{method}'] end EOS