Class: OKCupid::Mailbox::Conversation

Inherits:
Object
  • Object
show all
Defined in:
lib/lonely_coder/mailbox.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs) ⇒ Conversation

Returns a new instance of Conversation.



71
72
73
74
75
# File 'lib/lonely_coder/mailbox.rb', line 71

def initialize(attrs)
  attrs.each do |attr, value|
    self.send("#{attr}=", value)
  end
end

Instance Attribute Details

#from_profile_usernameObject

Returns the value of attribute from_profile_username.



41
42
43
# File 'lib/lonely_coder/mailbox.rb', line 41

def from_profile_username
  @from_profile_username
end

#messagesObject

Returns the value of attribute messages.



41
42
43
# File 'lib/lonely_coder/mailbox.rb', line 41

def messages
  @messages
end

Class Method Details

.by_id(id, browser) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/lonely_coder/mailbox.rb', line 43

def self.by_id(id, browser)
  html = browser.get("/messages?readmsg=true&threadid=#{id}&folder=1")
  from_profile_username = html.search('li.to_me:first a').attribute('title').text
   
  messages = []
  
  html.search('#thread  > li').each do |message_html|
    css_class = message_html.attribute('class')
    css_id    = message_html.attribute('id')
    
    # matches 'from_me' and 'to_me' classes.
    if (css_class && css_class.text.match(/_me/))
      if(css_id && css_id.text == 'compose')
        next
      else
        messages << Message.from_html(message_html)
      end
    else
      next
    end
  end
  
  self.new({
    from_profile_username: from_profile_username,
    messages: messages
  })
end