Class: Bitmessage::ApiClient::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/bitmessage/api_client.rb

Constant Summary collapse

ENCODING_IGNORE =
0
ENCODING_TRIVIAL =
1
ENCODING_SIMPLE =
2
FOLDER_UNKNOWN =
:unknown
FOLDER_INBOX =
:inbox
FOLDER_OUTBOX =
:outbox

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Message

Returns a new instance of Message.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/bitmessage/api_client.rb', line 38

def initialize hash
  self.folder = FOLDER_UNKNOWN
  self.msgid = hash['msgid']
  self.to = hash['toAddress']
  self.from = hash['fromAddress']
  self.subject = Base64.decode64(hash['subject'])
  self.message = Base64.decode64(hash['message'])
  self.encoding = hash['encodingType'].to_i

  if hash.keys.include?('receivedTime')
    self.folder = FOLDER_INBOX
    self.received_at = Time.at(hash['receivedTime'].to_i)
    self.read = hash['read'] == 0 ? false : true
  elsif hash.keys.include?('ackData')
    self.folder = FOLDER_OUTBOX
    self.last_action_at = Time.at(hash['lastActionTime'].to_i)
    self.status = hash['status']
    self.ack_data = hash['ackData']
  end
end

Instance Attribute Details

#ack_dataObject

outbox attributes



36
37
38
# File 'lib/bitmessage/api_client.rb', line 36

def ack_data
  @ack_data
end

#encodingObject

common attributes



32
33
34
# File 'lib/bitmessage/api_client.rb', line 32

def encoding
  @encoding
end

#folderObject

common attributes



32
33
34
# File 'lib/bitmessage/api_client.rb', line 32

def folder
  @folder
end

#fromObject

common attributes



32
33
34
# File 'lib/bitmessage/api_client.rb', line 32

def from
  @from
end

#last_action_atObject

outbox attributes



36
37
38
# File 'lib/bitmessage/api_client.rb', line 36

def last_action_at
  @last_action_at
end

#messageObject

common attributes



32
33
34
# File 'lib/bitmessage/api_client.rb', line 32

def message
  @message
end

#msgidObject

common attributes



32
33
34
# File 'lib/bitmessage/api_client.rb', line 32

def msgid
  @msgid
end

#readObject

inbox attributes



34
35
36
# File 'lib/bitmessage/api_client.rb', line 34

def read
  @read
end

#received_atObject

inbox attributes



34
35
36
# File 'lib/bitmessage/api_client.rb', line 34

def received_at
  @received_at
end

#statusObject

outbox attributes



36
37
38
# File 'lib/bitmessage/api_client.rb', line 36

def status
  @status
end

#subjectObject

common attributes



32
33
34
# File 'lib/bitmessage/api_client.rb', line 32

def subject
  @subject
end

#toObject

common attributes



32
33
34
# File 'lib/bitmessage/api_client.rb', line 32

def to
  @to
end

Instance Method Details

#to_sObject



59
60
61
# File 'lib/bitmessage/api_client.rb', line 59

def to_s
  self.msgid
end