Class: CS::Message
- Inherits:
-
Object
show all
- Defined in:
- lib/csapi/messages.rb
Instance Method Summary
collapse
Constructor Details
#initialize(url) ⇒ Message
60
61
62
63
|
# File 'lib/csapi/messages.rb', line 60
def initialize(url)
@url = url
@fetched = false
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth) ⇒ Object
90
91
92
93
94
95
96
97
|
# File 'lib/csapi/messages.rb', line 90
def method_missing meth
if vars.include? meth
fetch unless @fetched
@data[meth.to_s]
else
raise ArgumentError.new
end
end
|
Instance Method Details
#date ⇒ Object
75
76
77
78
|
# File 'lib/csapi/messages.rb', line 75
def date
fetch unless @fetched
Date.parse(@date)
end
|
#fetch ⇒ Object
65
66
67
68
|
# File 'lib/csapi/messages.rb', line 65
def fetch
req = HTTP.get(@url)
@data = JSON.parse req.body
end
|
#is_sender? ⇒ Boolean
85
86
87
88
|
# File 'lib/csapi/messages.rb', line 85
def is_sender?
fetch unless @fetched
@user_is_sender
end
|
#to_h ⇒ Object
70
71
72
73
|
# File 'lib/csapi/messages.rb', line 70
def to_h
fetch unless @fetched
@data
end
|
#unread? ⇒ Boolean
80
81
82
83
|
# File 'lib/csapi/messages.rb', line 80
def unread?
fetch unless @fetched
@is_unread
end
|