lib/textmagic/response.rb in textmagic-0.6.0 vs lib/textmagic/response.rb in textmagic-0.7.0
- old
+ new
@@ -2,35 +2,36 @@
module TextMagic
class API
- class Response
+ module Response
- def self.account(hash)
+ module_function
+
+ def account(hash)
response = OpenStruct.new(hash)
response.balance = response.balance.to_f
- response.balance = response.balance.to_i if response.balance % 1 == 0
+ response.balance = response.balance.to_i if (response.balance % 1).zero?
response
end
- def self.send(hash, single)
- response = nil
- if single
- response = hash["message_id"].keys.first.dup
+ def send(hash, single)
+ response = if single
+ hash["message_id"].keys.first.dup
else
- response = hash["message_id"].invert
+ hash["message_id"].invert
end
metaclass = class << response; self; end
metaclass.send :attr_accessor, :sent_text, :parts_count, :message_id
response.sent_text = hash["sent_text"]
response.parts_count = hash["parts_count"]
response.message_id = hash["message_id"]
response
end
- def self.message_status(hash, single)
+ def message_status(hash, single)
response = {}
hash.each do |message_id, message_hash|
status = message_hash["status"].dup
metaclass = class << status; self; end
metaclass.send :attr_accessor, :text, :credits_cost, :reply_number, :status, :created_time, :completed_time
@@ -43,11 +44,11 @@
response[message_id] = status
end
single ? response.values.first : response
end
- def self.receive(hash)
+ def receive(hash)
response = hash["messages"].collect do |message_hash|
message = "#{message_hash["from"]}: #{message_hash["text"]}"
metaclass = class << message; self; end
metaclass.send :attr_accessor, :timestamp, :message_id, :text, :from
message.text = message_hash["text"]
@@ -60,15 +61,18 @@
metaclass.send :attr_accessor, :unread
response.unread = hash["unread"]
response
end
- def self.check_number(hash, single)
+ def check_number(hash, single)
response = {}
hash.each do |phone, check_hash|
response[phone] = OpenStruct.new(check_hash)
end
single ? response.values.first : response
end
+
end
+
end
+
end