Class: Noteshred::Note

Inherits:
Object
  • Object
show all
Defined in:
lib/noteshred/note.rb

Constant Summary collapse

SHRED_AFTER_READING =

Shred Methods

1
SHRED_LATER =
2

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#contentObject

Returns the value of attribute content.



4
5
6
# File 'lib/noteshred/note.rb', line 4

def content
  @content
end

#encrypted_contentObject

Returns the value of attribute encrypted_content.



4
5
6
# File 'lib/noteshred/note.rb', line 4

def encrypted_content
  @encrypted_content
end

#encrypted_content_ivObject

Returns the value of attribute encrypted_content_iv.



4
5
6
# File 'lib/noteshred/note.rb', line 4

def encrypted_content_iv
  @encrypted_content_iv
end

#encrypted_content_saltObject

Returns the value of attribute encrypted_content_salt.



4
5
6
# File 'lib/noteshred/note.rb', line 4

def encrypted_content_salt
  @encrypted_content_salt
end

#hintObject

Returns the value of attribute hint.



4
5
6
# File 'lib/noteshred/note.rb', line 4

def hint
  @hint
end

#passwordObject

Returns the value of attribute password.



4
5
6
# File 'lib/noteshred/note.rb', line 4

def password
  @password
end

#password_hashObject

Returns the value of attribute password_hash.



4
5
6
# File 'lib/noteshred/note.rb', line 4

def password_hash
  @password_hash
end

#recipientsObject

Returns the value of attribute recipients.



4
5
6
# File 'lib/noteshred/note.rb', line 4

def recipients
  @recipients
end

#shred_byObject

Returns the value of attribute shred_by.



4
5
6
# File 'lib/noteshred/note.rb', line 4

def shred_by
  @shred_by
end

#shred_methodObject

Returns the value of attribute shred_method.



4
5
6
# File 'lib/noteshred/note.rb', line 4

def shred_method
  @shred_method
end

#titleObject

Returns the value of attribute title.



4
5
6
# File 'lib/noteshred/note.rb', line 4

def title
  @title
end

#versionObject

Returns the value of attribute version.



4
5
6
# File 'lib/noteshred/note.rb', line 4

def version
  @version
end

Class Method Details

.share(token, recipients, comments) ⇒ Object



70
71
72
73
74
75
76
77
78
79
# File 'lib/noteshred/note.rb', line 70

def self.share(token,recipients,comments)
  # Receive comma seperated list of recipients
  if recipients.nil?
    raise ArgumentError.new('Recipients are required')
  end
  if token.nil?
    raise ArgumentError.new('Token is required')
  end
  Noteshred::API.post("/notes/#{token}/share", {:dest_email => recipients, :comments => comments})
end

Instance Method Details

#createObject



21
22
23
24
25
26
# File 'lib/noteshred/note.rb', line 21

def create
  # For creating notes that are encrypted on the server
  validate_content
  validate_options
  Noteshred::API.post('/notes', Noteshred::Tools.hashify(self))
end

#decryptObject



60
61
62
63
64
65
66
67
68
# File 'lib/noteshred/note.rb', line 60

def decrypt
  validate_encrypted_content
  self.content                = Noteshred::Crypto::V4.decrypt(self.encrypted_content, self.password, self.encrypted_content_salt, self.encrypted_content_iv)
  self.encrypted_content_iv   = nil
  self.encrypted_content_salt = nil
  self.encrypted_content      = nil
  self.password_hash          = nil
  return self
end

#encryptObject



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/noteshred/note.rb', line 47

def encrypt
  validate_content
  crypt = Noteshred::Crypto::V4.encrypt(self.content, self.password)
  self.encrypted_content      = crypt[:content]
  self.encrypted_content_iv   = crypt[:iv]
  self.encrypted_content_salt = crypt[:salt]
  self.version                = crypt[:version]
  self.password_hash          = BCrypt::Password.create(self.password)
  self.content                = nil
  self.password               = nil
  return self
end

#pull(token, pass) ⇒ Object



38
39
40
41
42
43
44
45
# File 'lib/noteshred/note.rb', line 38

def pull(token,pass)
  # For pulling raw encrypted notes from the server
  # TODO: Implement server side portion
  if token.nil? || password.nil?
    raise ArgumentError.new('token and password params are required')
  end
  Noteshred::API.get('/notes/pull', {:password => pass, :token => token})
end

#pushObject



28
29
30
31
32
33
34
35
36
# File 'lib/noteshred/note.rb', line 28

def push
  # For creating notes that are encrypted by the gem first then pushed to the server
  validate_options
  if self.encrypted_content_salt.nil? || encrypted_content_iv.nil?
    raise ArgumentError.new('No encrypted content found. Must call .encrypt before pushing')
  end

  Noteshred::API.post('/notes/push', Noteshred::Tools.hashify(self))
end