Class: CS::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/csapi/messages.rb

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ Message

attr_accessor *@vars



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

#dateObject



75
76
77
78
# File 'lib/csapi/messages.rb', line 75

def date
  fetch unless @fetched
  Date.parse(@date)
end

#fetchObject



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

Returns:

  • (Boolean)


85
86
87
88
# File 'lib/csapi/messages.rb', line 85

def is_sender?
  fetch unless @fetched
  @user_is_sender
end

#to_hObject



70
71
72
73
# File 'lib/csapi/messages.rb', line 70

def to_h
  fetch unless @fetched
  @data
end

#unread?Boolean

Returns:

  • (Boolean)


80
81
82
83
# File 'lib/csapi/messages.rb', line 80

def unread?
  fetch unless @fetched
  @is_unread
end