Class: Cipher

Inherits:
Dry::Struct
  • Object
show all
Defined in:
lib/schemas.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_dynamic!(d) ⇒ Object



3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
# File 'lib/schemas.rb', line 3135

def self.from_dynamic!(d)
  d = Types::Hash[d]
  new(
    attachments:           d["attachments"]&.map { |x| Attachment.from_dynamic!(x) },
    card:                  d["card"] ? Card.from_dynamic!(d["card"]) : nil,
    collection_ids:        d.fetch("collectionIds"),
    creation_date:         d.fetch("creationDate"),
    deleted_date:          d["deletedDate"],
    edit:                  d.fetch("edit"),
    favorite:              d.fetch("favorite"),
    fields:                d["fields"]&.map { |x| Field.from_dynamic!(x) },
    folder_id:             d["folderId"],
    id:                    d["id"],
    identity:              d["identity"] ? Identity.from_dynamic!(d["identity"]) : nil,
    key:                   d["key"],
    local_data:            d["localData"] ? LocalData.from_dynamic!(d["localData"]) : nil,
    login:                 d["login"] ? Login.from_dynamic!(d["login"]) : nil,
    cipher_name:           d.fetch("name"),
    notes:                 d["notes"],
    organization_id:       d["organizationId"],
    organization_use_totp: d.fetch("organizationUseTotp"),
    password_history:      d["passwordHistory"]&.map { |x| PasswordHistory.from_dynamic!(x) },
    reprompt:              d.fetch("reprompt"),
    revision_date:         d.fetch("revisionDate"),
    secure_note:           d["secureNote"] ? SecureNote.from_dynamic!(d["secureNote"]) : nil,
    cipher_type:           d.fetch("type"),
    view_password:         d.fetch("viewPassword"),
  )
end

.from_json!(json) ⇒ Object



3165
3166
3167
# File 'lib/schemas.rb', line 3165

def self.from_json!(json)
  from_dynamic!(JSON.parse(json))
end

Instance Method Details

#to_dynamicObject



3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
# File 'lib/schemas.rb', line 3169

def to_dynamic
  {
    "attachments"         => attachments&.map { |x| x.to_dynamic },
    "card"                => card&.to_dynamic,
    "collectionIds"       => collection_ids,
    "creationDate"        => creation_date,
    "deletedDate"         => deleted_date,
    "edit"                => edit,
    "favorite"            => favorite,
    "fields"              => fields&.map { |x| x.to_dynamic },
    "folderId"            => folder_id,
    "id"                  => id,
    "identity"            => identity&.to_dynamic,
    "key"                 => key,
    "localData"           => local_data&.to_dynamic,
    "login"               => &.to_dynamic,
    "name"                => cipher_name,
    "notes"               => notes,
    "organizationId"      => organization_id,
    "organizationUseTotp" => organization_use_totp,
    "passwordHistory"     => password_history&.map { |x| x.to_dynamic },
    "reprompt"            => reprompt,
    "revisionDate"        => revision_date,
    "secureNote"          => secure_note&.to_dynamic,
    "type"                => cipher_type,
    "viewPassword"        => view_password,
  }
end

#to_json(options = nil) ⇒ Object



3198
3199
3200
# File 'lib/schemas.rb', line 3198

def to_json(options = nil)
  JSON.generate(to_dynamic, options)
end