Class: RocketSMS::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/rocket_sms/message.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Message

Returns a new instance of Message.



6
7
8
9
# File 'lib/rocket_sms/message.rb', line 6

def initialize(params)
  @params = OpenStruct.new(params)
  @params.pass ||= 0
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object



25
26
27
# File 'lib/rocket_sms/message.rb', line 25

def method_missing(sym, *args, &block)
  @params.send(sym, *args, &block)
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



4
5
6
# File 'lib/rocket_sms/message.rb', line 4

def params
  @params
end

Class Method Details

.from_json(json) ⇒ Object



19
20
21
22
23
# File 'lib/rocket_sms/message.rb', line 19

def self.from_json(json)
  params = MultiJson.load(json, symbolize_keys: true)
  msg = Message.new(params)
  return msg
end

Instance Method Details

#add_passObject



15
16
17
# File 'lib/rocket_sms/message.rb', line 15

def add_pass
  @params.pass += 1
end

#to_jsonObject



11
12
13
# File 'lib/rocket_sms/message.rb', line 11

def to_json
  MultiJson.dump(@params.marshal_dump)
end