mastodon-cpp  0.104.0
Public Member Functions | List of all members
Mastodon::Easy::Attachment Class Reference

Class to hold attachments. More...

#include <attachment.hpp>

Inheritance diagram for Mastodon::Easy::Attachment:
Mastodon::Easy::Entity

Public Member Functions

virtual bool valid () const override
 Returns true if the Entity holds valid data. More...
 
double aspect () const
 Aspect of original image. More...
 
double aspect_small () const
 Aspect of preview image. More...
 
uint64_t bitrate () const
 Returns the bitrate of a video. More...
 
const string description () const
 Returns the image description. More...
 
Attachment description (const string &description)
 Sets the image description. More...
 
const std::chrono::duration< double > duration () const
 Returns the duration of a video in seconds. More...
 
const string file () const
 Gets file to upload. More...
 
Attachment file (const string &file)
 Sets file to upload. More...
 
const std::array< double, 2 > focus () const
 Returns the focus point (x, y) More...
 
Attachment focus (const std::array< double, 2 > &focus)
 Sets the focus point (x, y) More...
 
double framerate () const
 Returns the framerate of a video in frames per second. More...
 
uint64_t height () const
 Returns the height of the original image. More...
 
uint64_t height_small () const
 Returns the height of the preview image. More...
 
const string id () const
 Returns the ID of the attachment. More...
 
const string preview_url () const
 Returns the URL of the preview image. More...
 
const string remote_url () const
 Returns the remote URL of the original image. More...
 
const string size () const
 Returns the size of the original image. More...
 
const string size_small () const
 Returns the size of the preview image. More...
 
const string text_url () const
 Returns shorter URL for the image. More...
 
attachment_type type () const
 Returns attachment type. More...
 
const string url () const
 Returns URL of the locally hosted version of the image. More...
 
uint64_t width () const
 Returns the width of the original image. More...
 
uint64_t width_small () const
 Returns the width of the preview image. More...
 
 Entity (const string &json)
 Constructs an Entity object from a JSON string. More...
 
 Entity (const Json::Value &object)
 Constructs an Entity object from a JSON object. More...
 
 Entity ()
 Constructs an empty Entity object. More...
 
- Public Member Functions inherited from Mastodon::Easy::Entity
 Entity (const string &json)
 Constructs an Entity object from a JSON string. More...
 
 Entity (const Json::Value &object)
 Constructs an Entity object from a JSON object. More...
 
 Entity ()
 Constructs an empty Entity object. More...
 
virtual ~Entity ()
 Destroys the object. More...
 
 operator const Json::Value () const
 
void from_string (const string &json)
 Replaces the Entity with a new one from a JSON string. More...
 
const string to_string () const
 Returns the JSON of the Entity as string. More...
 
void from_object (const Json::Value &object)
 Replaces the Entity with a new one from a JSON object. More...
 
const Json::Value to_object () const
 Returns the JSON object of the Entity. More...
 
const string error () const
 Returns error string sent by the server. More...
 
bool was_set () const
 Returns true if the last requested value was set, false if it was unset. More...
 

Additional Inherited Members

- Protected Member Functions inherited from Mastodon::Easy::Entity
const Json::Value get (const string &key) const
 Returns the value of key as Json::Value. More...
 
const string get_string (const string &key) const
 Returns the value of key as std::string. More...
 
uint64_t get_uint64 (const string &key) const
 Returns the value of key as std::uint64_t. More...
 
double get_double (const string &key) const
 Returns the value of key as double. More...
 
bool get_bool (const string &key) const
 Returns the value of key as bool. More...
 
const Easy::time get_time (const string &key) const
 Returns the value of key as Easy::time. More...
 
const std::vector< string > get_vector (const string &key) const
 Returns the value of key as vector. More...
 
void set (const string &key, const Json::Value &value)
 Sets the value of key. More...
 
std::uint64_t stouint64 (const string &str) const
 Returns value of str as uint64_t.
 
bool check_valid (const std::vector< string > &attributes) const
 Checks if an Entity is valid. More...
 

Detailed Description

Class to hold attachments.

Since
before 0.11.0

Member Function Documentation

◆ aspect()

double Attachment::aspect ( ) const

Aspect of original image.

Since
before 0.11.0
38 {
39  return get_double("meta.original.aspect");
40 }
double get_double(const string &key) const
Returns the value of key as double.
Definition: entity.cpp:201

◆ aspect_small()

double Attachment::aspect_small ( ) const

Aspect of preview image.

Since
before 0.11.0
43 {
44  return get_double("meta.small.aspect");
45 }
double get_double(const string &key) const
Returns the value of key as double.
Definition: entity.cpp:201

◆ bitrate()

uint64_t Attachment::bitrate ( ) const

Returns the bitrate of a video.

Since
before 0.11.0
48 {
49  return get_uint64("meta.original.bitrate");
50 }
uint64_t get_uint64(const string &key) const
Returns the value of key as std::uint64_t.
Definition: entity.cpp:187

◆ description() [1/2]

const string Attachment::description ( ) const

Returns the image description.

Since
before 0.11.0
53 {
54  return get_string("description");
55 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:173

◆ description() [2/2]

Attachment Attachment::description ( const string &  description)

Sets the image description.

Since
0.17.0
58 {
59  set("description", Json::Value(description));
60  return *this;
61 }
const string description() const
Returns the image description.
Definition: attachment.cpp:52

◆ duration()

const std::chrono::duration< double > Attachment::duration ( ) const

Returns the duration of a video in seconds.

Since
before 0.11.0
64 {
65  const double sec = get_double("meta.original.duration");
66 
67  return std::chrono::duration<double>(sec);
68 }
double get_double(const string &key) const
Returns the value of key as double.
Definition: entity.cpp:201

◆ Entity() [1/3]

Easy::Entity::Entity

Constructs an empty Entity object.

Since
before 0.11.0
43 : _tree(Json::nullValue)
44 , _was_set(false)
45 {}

◆ Entity() [2/3]

Easy::Entity::Entity
explicit

Constructs an Entity object from a JSON string.

Parameters
jsonJSON string
Since
before 0.11.0
31 : _tree(Json::nullValue)
32 ,_was_set(false)
33 {
34  from_string(json);
35 }
void from_string(const string &json)
Replaces the Entity with a new one from a JSON string.
Definition: entity.cpp:55

◆ Entity() [3/3]

Easy::Entity::Entity
explicit

Constructs an Entity object from a JSON object.

Parameters
objectJSON object
Since
0.100.0
38 : _tree(object)
39 ,_was_set(false)
40 {}

◆ file() [1/2]

const string Attachment::file ( ) const

Gets file to upload.

Since
0.17.0
71 {
72  return get_string("file");
73 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:173

◆ file() [2/2]

Attachment Attachment::file ( const string &  file)

Sets file to upload.

Since
0.17.0
Parameters
fileFilename
76 {
77  set("file", Json::Value(file));
78  return *this;
79 }
const string file() const
Gets file to upload.
Definition: attachment.cpp:70

◆ focus() [1/2]

const std::array< double, 2 > Attachment::focus ( ) const

Returns the focus point (x, y)

Values are between -1.0 and 1.0.

Since
before 0.11.0
83 {
84  const Json::Value x = get("meta.focus.x");
85  const Json::Value y = get("meta.focus.y");
86  if (x.isDouble() && y.isDouble())
87  {
88  return
89  {{
90  x.asDouble(),
91  y.asDouble()
92  }};
93  }
94 
95  return {};
96 }

◆ focus() [2/2]

Attachment Attachment::focus ( const std::array< double, 2 > &  focus)

Sets the focus point (x, y)

Values are between -1.0 and 1.0.

Since
0.17.0
99 {
100  set("meta.focus.x", Json::Value(focus[0]));
101  set("meta.focus.y", Json::Value(focus[1]));
102  return *this;
103 }
const std::array< double, 2 > focus() const
Returns the focus point (x, y)
Definition: attachment.cpp:82

◆ framerate()

double Attachment::framerate ( ) const

Returns the framerate of a video in frames per second.

Since
before 0.11.0
106 {
107  string strframes = get_string("meta.original.frame_rate");
108 
109  if (!strframes.empty())
110  {
111  std::size_t pos = strframes.find('/');
112  if (pos != std::string::npos)
113  {
114  std::uint16_t frames = std::stoul(strframes.substr(0, pos));
115  std::uint16_t divider = std::stoul(strframes.substr(pos + 1));
116 
117  return frames / divider;
118  }
119  }
120 
121  return 0.0;
122 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:173

◆ height()

uint64_t Attachment::height ( ) const

Returns the height of the original image.

Since
before 0.11.0
125 {
126  return get_uint64("meta.original.height");
127 }
uint64_t get_uint64(const string &key) const
Returns the value of key as std::uint64_t.
Definition: entity.cpp:187

◆ height_small()

uint64_t Attachment::height_small ( ) const

Returns the height of the preview image.

Since
before 0.11.0
130 {
131  return get_uint64("meta.small.height");
132 }
uint64_t get_uint64(const string &key) const
Returns the value of key as std::uint64_t.
Definition: entity.cpp:187

◆ id()

const string Attachment::id ( ) const

Returns the ID of the attachment.

Since
before 0.11.0
135 {
136  return get_string("id");
137 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:173

◆ preview_url()

const string Attachment::preview_url ( ) const

Returns the URL of the preview image.

Since
before 0.11.0
140 {
141  return get_string("preview_url");
142 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:173

◆ remote_url()

const string Attachment::remote_url ( ) const

Returns the remote URL of the original image.

Since
before 0.11.0
145 {
146  return get_string("remote_url");
147 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:173

◆ size()

const string Attachment::size ( ) const

Returns the size of the original image.

Since
before 0.11.0
150 {
151  return get_string("meta.original.size");
152 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:173

◆ size_small()

const string Attachment::size_small ( ) const

Returns the size of the preview image.

Since
before 0.11.0
155 {
156  return get_string("meta.small.size");
157 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:173

◆ text_url()

const string Attachment::text_url ( ) const

Returns shorter URL for the image.

Since
before 0.11.0
160 {
161  return get_string("text_url");
162 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:173

◆ type()

Easy::attachment_type Attachment::type ( ) const

Returns attachment type.

Since
before 0.11.0
165 {
166  const string strtype = get_string("type");
167  if (strtype.compare("image") == 0)
168  return attachment_type::Image;
169  else if (strtype.compare("video") == 0)
170  return attachment_type::Video;
171  else if (strtype.compare("gifv") == 0)
172  return attachment_type::Gifv;
173  else if (strtype.compare("unknown") == 0)
174  return attachment_type::Unknown;
175 
176  ttdebug << "Could not get data: type\n";
177  return attachment_type::Undefined;
178 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:173

◆ url()

const string Attachment::url ( ) const

Returns URL of the locally hosted version of the image.

Since
before 0.11.0
181 {
182  return get_string("url");
183 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:173

◆ valid()

bool Attachment::valid ( ) const
overridevirtual

Returns true if the Entity holds valid data.

Since
before 0.11.0 (virtual since 0.18.2)

Implements Mastodon::Easy::Entity.

25 {
26  const std::vector<string> attributes =
27  {{
28  "id",
29  "type",
30  "url",
31  "preview_url"
32  }};
33 
34  return Entity::check_valid(attributes);
35 }
bool check_valid(const std::vector< string > &attributes) const
Checks if an Entity is valid.
Definition: entity.cpp:101

◆ width()

uint64_t Attachment::width ( ) const

Returns the width of the original image.

Since
before 0.11.0
186 {
187  return get_uint64("meta.original.width");
188 }
uint64_t get_uint64(const string &key) const
Returns the value of key as std::uint64_t.
Definition: entity.cpp:187

◆ width_small()

uint64_t Attachment::width_small ( ) const

Returns the width of the preview image.

Since
before 0.11.0
191 {
192  return get_uint64("meta.small.width");
193 }
uint64_t get_uint64(const string &key) const
Returns the value of key as std::uint64_t.
Definition: entity.cpp:187

The documentation for this class was generated from the following files: