Class: Manhunt::Message
- Inherits:
-
Object
- Object
- Manhunt::Message
- Includes:
- ActiveModel::Serializers::JSON, ActiveModel::Serializers::Xml
- Defined in:
- lib/manhunt/message.rb
Constant Summary collapse
- GUID_REGEX =
/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/
- PROFILE_NAME_REGEX =
/setWindow\('profile\/(\w+)','profile'\);/
- USER_ID_REGEX =
/modalOpen\('list\/modalAddBuddy',\{buddy:(\d+)\}\);/
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#from_id ⇒ Object
readonly
Returns the value of attribute from_id.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#online ⇒ Object
readonly
Returns the value of attribute online.
-
#row ⇒ Object
readonly
Returns the value of attribute row.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#subject ⇒ Object
readonly
Returns the value of attribute subject.
Class Method Summary collapse
- .compose(session, user_name, user_id, reply_message_id = nil) ⇒ Object
- .parse_header(format, row) ⇒ Object
- .parse_message(document, id) ⇒ Object
- .send_message(session, params) ⇒ Object
Instance Method Summary collapse
- #attributes ⇒ Object
-
#initialize(type, document, format = nil) ⇒ Message
constructor
A new instance of Message.
- #to_param ⇒ Object
Constructor Details
#initialize(type, document, format = nil) ⇒ Message
Returns a new instance of Message.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/manhunt/message.rb', line 36 def initialize(type, document, format = nil) @format = format @row = document case type when :header columns = (document/"td") @subject = (document/".subject").inner_text.strip @online = (document/".buddyOnline").any? @from = columns[@format.index(:from)].inner_text @state = :unread @state = :read if (document/".messageRead").any? @state = :replied if (document/".messageReplied").any? @id = GUID_REGEX.match((document/".subject a").first.attributes['href'])[0] @date = Time.at((columns[@format.index(:date)]/".LocalTime").first.attributes['gmt_time'].to_i) when :message @body = (document/"#msgTextDiv").inner_html @subject = (document/".headerColored").inner_text.strip @from = PROFILE_NAME_REGEX.match((document/"#readRecipProfLink a").first.attributes['onclick'])[1] @from_id = USER_ID_REGEX.match((document/"#buddyButton").first.attributes['onclick'])[1] end end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
9 10 11 |
# File 'lib/manhunt/message.rb', line 9 def body @body end |
#date ⇒ Object (readonly)
Returns the value of attribute date.
9 10 11 |
# File 'lib/manhunt/message.rb', line 9 def date @date end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
9 10 11 |
# File 'lib/manhunt/message.rb', line 9 def format @format end |
#from ⇒ Object (readonly)
Returns the value of attribute from.
9 10 11 |
# File 'lib/manhunt/message.rb', line 9 def from @from end |
#from_id ⇒ Object (readonly)
Returns the value of attribute from_id.
9 10 11 |
# File 'lib/manhunt/message.rb', line 9 def from_id @from_id end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
9 10 11 |
# File 'lib/manhunt/message.rb', line 9 def id @id end |
#online ⇒ Object (readonly)
Returns the value of attribute online.
9 10 11 |
# File 'lib/manhunt/message.rb', line 9 def online @online end |
#row ⇒ Object (readonly)
Returns the value of attribute row.
9 10 11 |
# File 'lib/manhunt/message.rb', line 9 def row @row end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
9 10 11 |
# File 'lib/manhunt/message.rb', line 9 def state @state end |
#subject ⇒ Object (readonly)
Returns the value of attribute subject.
9 10 11 |
# File 'lib/manhunt/message.rb', line 9 def subject @subject end |
Class Method Details
.compose(session, user_name, user_id, reply_message_id = nil) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/manhunt/message.rb', line 27 def self.compose(session, user_name, user_id, = nil) if url = "/mail/compose/recipientId/#{user_id}/messageId/#{}/username/#{user_name}" end compose = session.get_document(url) { :subject => (compose/"#subject").first.attributes['value'], :body => (compose/"#body").first.inner_html, :raw => compose } end |
.parse_header(format, row) ⇒ Object
15 16 17 |
# File 'lib/manhunt/message.rb', line 15 def self.parse_header(format, row) ManhuntMessage.new(:header, row, format) end |
.parse_message(document, id) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/manhunt/message.rb', line 19 def self.(document, id) = ManhuntMessage.new(:message, document) .instance_eval do @id = id end end |
.send_message(session, params) ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/manhunt/message.rb', line 60 def self.(session, params) url = "/mail/send" = { 'body' => params[:body], 'subject' => params[:subject], 'recipientId' => params[:send_to_id], 'username' => params[:send_to] } ['replyMessageId'] = params[:reply_message_id] if params[:reply_message_id] session.post_nil(url, ) end |
Instance Method Details
#attributes ⇒ Object
11 12 13 |
# File 'lib/manhunt/message.rb', line 11 def attributes { 'subject' => subject, 'from' => from, 'state' => state, 'id' => id, 'body' => body, 'date' => date, 'online' => online } end |
#to_param ⇒ Object
70 71 72 |
# File 'lib/manhunt/message.rb', line 70 def to_param id end |