Module: TextMagic::API::Response
- Defined in:
- lib/textmagic/response.rb
Class Method Summary collapse
- .account(hash) ⇒ Object
- .check_number(hash, single) ⇒ Object
- .message_status(hash, single) ⇒ Object
- .receive(hash) ⇒ Object
- .send(hash, single) ⇒ Object
Class Method Details
.account(hash) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/textmagic/response.rb', line 11 def account(hash) response = OpenStruct.new(hash) response.balance = response.balance.to_f response.balance = response.balance.to_i if (response.balance % 1).zero? response end |
.check_number(hash, single) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/textmagic/response.rb', line 66 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 |
.message_status(hash, single) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/textmagic/response.rb', line 32 def (hash, single) response = {} hash.each do |, | status = ["status"].dup = class << status; self; end .send :attr_accessor, :text, :credits_cost, :reply_number, :status, :created_time, :completed_time status.text = ["text"] status.credits_cost = ["credits_cost"] status.reply_number = ["reply_number"] status.status = ["status"] status.created_time = Time.at(["created_time"].to_i) if ["created_time"] status.completed_time = Time.at(["completed_time"].to_i) if ["completed_time"] response[] = status end single ? response.values.first : response end |
.receive(hash) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/textmagic/response.rb', line 49 def receive(hash) response = hash["messages"].collect do || = "#{["from"]}: #{["text"]}" = class << ; self; end .send :attr_accessor, :timestamp, :message_id, :text, :from .text = ["text"] .from = ["from"] . = ["message_id"] . = Time.at(["timestamp"].to_i) end = class << response; self; end .send :attr_accessor, :unread response.unread = hash["unread"] response end |
.send(hash, single) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/textmagic/response.rb', line 18 def send(hash, single) response = if single hash["message_id"].keys.first.dup else hash["message_id"].invert end = class << response; self; end .send :attr_accessor, :sent_text, :parts_count, :message_id response.sent_text = hash["sent_text"] response.parts_count = hash["parts_count"] response. = hash["message_id"] response end |