Class: DropboxApi::Metadata::Base
- Inherits:
-
Object
- Object
- DropboxApi::Metadata::Base
- Defined in:
- lib/dropbox_api/metadata/base.rb
Direct Known Subclasses
AddFileMemberResult, AddMember, BasicAccount, CommitInfo, Deleted, Dimensions, File, FileLinkMetadata, FileMemberAction, FileRequest, Folder, FolderLinkMetadata, FolderSharingInfo, LinkPermissions, Location, MediaInfo, MediaMetadata, Member, MemberPermission, MetadataV2, Name, NamespaceId, ParentFolderAccessInfo, PhotoMetadata, RootInfo, SearchMatchFieldOptions, SearchMatchV2, SearchOptions, SharedFolder, SharedFolderPolicy, SharedLink, SpaceAllocation, SpaceUsage, Tag, Team, TeamMemberInfo, TeamRootInfo, ThumbnailBatchResultData, UploadSessionCursor, UserRootInfo, VideoMetadata, WriteMode
Class Attribute Summary collapse
-
.fields ⇒ Object
readonly
Returns the value of attribute fields.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(metadata) ⇒ Base
constructor
Takes in a hash containing all the attributes required to initialize the object.
- #serialized_field(field_name) ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(metadata) ⇒ Base
Takes in a hash containing all the attributes required to initialize the object.
Each hash entry should have a key which identifies a field and its value, so a valid call would be something like this:
DropboxApi::Metadata::File.new({
"name" => "a.jpg",
"path_lower" => "/a.jpg",
"path_display" => "/a.jpg",
"id" => "id:evvfE6q6cK0AAAAAAAAB2w",
"client_modified" => "2016-10-19T17:17:34Z",
"server_modified" => "2016-10-19T17:17:34Z",
"rev" => "28924061bdd",
"size" => 396317
})
34 35 36 37 38 |
# File 'lib/dropbox_api/metadata/base.rb', line 34 def initialize() self.class.fields.keys.each do |field_name| self[field_name] = [field_name.to_s] end end |
Class Attribute Details
.fields ⇒ Object (readonly)
Returns the value of attribute fields.
5 6 7 |
# File 'lib/dropbox_api/metadata/base.rb', line 5 def fields @fields end |
Class Method Details
.field(name, type, *options) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/dropbox_api/metadata/base.rb', line 7 def field(name, type, *) @fields ||= {} @fields[name] = DropboxApi::Metadata::Field.new(type, ) attr_reader name end |
Instance Method Details
#serialized_field(field_name) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/dropbox_api/metadata/base.rb', line 46 def serialized_field(field_name) value = send field_name case value when Time value.utc.strftime('%FT%TZ') when DropboxApi::Metadata::Base value.to_hash else value end end |
#to_hash ⇒ Object
40 41 42 43 44 |
# File 'lib/dropbox_api/metadata/base.rb', line 40 def to_hash Hash[self.class.fields.keys.map do |field_name| [field_name.to_s, serialized_field(field_name)] end.select { |k, v| !v.nil? }] end |