Class: OnePassword::Item
- Inherits:
-
Object
- Object
- OnePassword::Item
- Defined in:
- lib/one_password/item.rb
Constant Summary collapse
- INDEX_UUID =
0
- INDEX_TYPE =
1
- INDEX_NAME =
2
- INDEX_URL =
3
- INDEX_DATE =
4
- INDEX_FOLDER =
5
- INDEX_PASSWORD_STRENGTH =
6
- INDEX_TRASHED =
7
Instance Attribute Summary collapse
- #domain ⇒ String
- #encrypted ⇒ String
- #open_contents ⇒ String
- #profile ⇒ OnePassword::Profile readonly
- #security_level ⇒ String
- #title ⇒ String
- #trashed ⇒ String
- #type ⇒ String
- #updated_at ⇒ String
- #uuid ⇒ String
Instance Method Summary collapse
- #attributes ⇒ Object
- #attributes=(attrs) ⇒ Object
- #category ⇒ Object
- #created_at=(seconds) ⇒ Object
- #decrypt_data ⇒ Object
- #encryption_key ⇒ Object
- #file_name ⇒ Object
- #find_field_with_designation(designation) ⇒ Object
-
#initialize(profile, data) ⇒ Item
constructor
A new instance of Item.
- #load_encrypted_data ⇒ Object
- #login_password ⇒ Object
- #login_username ⇒ Object
- #matches?(text) ⇒ Boolean
- #system? ⇒ Boolean
- #trashed? ⇒ Boolean
- #wallet? ⇒ Boolean
Constructor Details
#initialize(profile, data) ⇒ Item
Returns a new instance of Item.
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/one_password/item.rb', line 34 def initialize(profile, data) @profile = profile self.attributes = { uuid: data[INDEX_UUID], type: data[INDEX_TYPE], title: data[INDEX_NAME], domain: data[INDEX_URL], updated_at: data[INDEX_DATE], trashed: data[INDEX_TRASHED] } end |
Instance Attribute Details
#domain ⇒ String
16 17 18 |
# File 'lib/one_password/item.rb', line 16 def domain @domain end |
#encrypted ⇒ String
16 17 18 |
# File 'lib/one_password/item.rb', line 16 def encrypted @encrypted end |
#open_contents ⇒ String
16 17 18 |
# File 'lib/one_password/item.rb', line 16 def open_contents @open_contents end |
#profile ⇒ OnePassword::Profile (readonly)
30 31 32 |
# File 'lib/one_password/item.rb', line 30 def profile @profile end |
#security_level ⇒ String
16 17 18 |
# File 'lib/one_password/item.rb', line 16 def security_level @security_level end |
#title ⇒ String
16 17 18 |
# File 'lib/one_password/item.rb', line 16 def title @title end |
#trashed ⇒ String
16 17 18 |
# File 'lib/one_password/item.rb', line 16 def trashed @trashed end |
#type ⇒ String
16 17 18 |
# File 'lib/one_password/item.rb', line 16 def type @type end |
#updated_at ⇒ String
16 17 18 |
# File 'lib/one_password/item.rb', line 16 def updated_at @updated_at end |
#uuid ⇒ String
16 17 18 |
# File 'lib/one_password/item.rb', line 16 def uuid @uuid end |
Instance Method Details
#attributes ⇒ Object
132 133 134 135 136 137 138 139 |
# File 'lib/one_password/item.rb', line 132 def attributes @attributes ||= {} fields = instance_variables.inject({}) do |result, ivar| result[ivar] = instance_variable_get(ivar) unless ivar == :@profile result end @attributes.merge(fields) end |
#attributes=(attrs) ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/one_password/item.rb', line 141 def attributes=(attrs) attrs.each do |name, value| if value.present? attribute = name.to_s.underscore writer = "#{attribute}=" if respond_to?(writer) send(writer, value) else @attributes ||= {} @attributes[attribute] = value end end end end |
#category ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/one_password/item.rb', line 66 def category @category ||= case type when SOFTWARE_LICENSES, WEBFORMS, NOTES, IDENTITIES, PASSWORDS type.to_sym else if type == FOLDERS :folders elsif wallet? WALLET else ACCOUNT.to_sym end end end |
#created_at=(seconds) ⇒ Object
50 51 52 |
# File 'lib/one_password/item.rb', line 50 def created_at=(seconds) @created_at = Time.at(seconds) end |
#decrypt_data ⇒ Object
106 107 108 109 110 111 112 113 |
# File 'lib/one_password/item.rb', line 106 def decrypt_data unless @decrypted @decrypted = true plain_text = Encryption.decrypt_using_key(encrypted, encryption_key) attrs = JSON.parse(plain_text) self.attributes = attrs end end |
#encryption_key ⇒ Object
93 94 95 |
# File 'lib/one_password/item.rb', line 93 def encryption_key profile.encryption_keys[security_level].decrypted_key end |
#file_name ⇒ Object
85 86 87 |
# File 'lib/one_password/item.rb', line 85 def file_name profile.directory.join("#{uuid}.1password") end |
#find_field_with_designation(designation) ⇒ Object
123 124 125 126 127 128 129 130 |
# File 'lib/one_password/item.rb', line 123 def find_field_with_designation(designation) fields = attributes['fields'] field = fields.find do |field| field['designation'] == designation end if fields field['value'] if field end |
#load_encrypted_data ⇒ Object
97 98 99 |
# File 'lib/one_password/item.rb', line 97 def load_encrypted_data self.attributes = JSON.parse(File.read(file_name)) end |
#login_password ⇒ Object
119 120 121 |
# File 'lib/one_password/item.rb', line 119 def login_password attributes['password'].presence || find_field_with_designation('password') end |
#login_username ⇒ Object
115 116 117 |
# File 'lib/one_password/item.rb', line 115 def login_username find_field_with_designation('username') end |
#matches?(text) ⇒ Boolean
81 82 83 |
# File 'lib/one_password/item.rb', line 81 def matches?(text) title.downcase.index(text) || domain.downcase.index(text) end |
#system? ⇒ Boolean
54 55 56 |
# File 'lib/one_password/item.rb', line 54 def system? @type =~ /^system/ end |
#trashed? ⇒ Boolean
62 63 64 |
# File 'lib/one_password/item.rb', line 62 def trashed? @trashed == 'Y' end |
#wallet? ⇒ Boolean
58 59 60 |
# File 'lib/one_password/item.rb', line 58 def wallet? @type =~ /^wallet\.(membership|financial|government)}/ end |