1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
|
require "open_graph_reader/object"
module OpenGraphReader
# @see http://ogp.me/#metadata
class Og
include Object
namespace :og
# @!macro property
# @return [String]
string :type, required: true, downcase: true, default: "website"
# @!macro property
# @return [String]
string :title, required: true
# @!attribute [r] images
# @return [Array<Image>]
# @!macro property
# @return [Image]
url :image, required: true, collection: true
# @!macro property
# @return [String, nil]
url :url, required: true
# @!macro property
# @return [Audio, nil]
url :audio
# @!macro property
# @return [String, nil]
string :description
# @!macro property
# @return [String]
enum :determiner, ["", "a", "an", "the", "auto"], default: ""
# @!macro property
# @return [Locale, nil]
string :locale
# @!macro property
# @return [String, nil]
string :site_name
# @!macro property
# @return [Video, nil]
url :video
# @see http://ogp.me/#structured
class Image
include Object
namespace :og, :image
content :url, image: true
url :url
# @!macro property
# @return [String, nil]
url :secure_url
# @!macro property
# @return [String, nil]
string :type
# @!macro property
# @return [Integer, nil]
integer :width
# @!macro property
# @return [Integer, nil]
integer :height
# @return [String, nil]
def url
secure_url || properties[:url] || content
end
end
# @see http://ogp.me/#structured
class Audio
include Object
namespace :og, :audio
content :url
# This property is not listed on http://ogp.me, but commonly found
url :url
# @!macro property
# @return [String, nil]
url :secure_url
# @!macro property
# @return [String, nil]
string :type
# @return [String, nil]
def url
secure_url || properties[:url] || content
end
end
# @see http://ogp.me/#metadata
class Locale
include Object
namespace :og, :locale
content :string
# @!attribute [r] alternates
# @return [Array<String>]
# @!macro property
# @return [String, nil]
string :alternate, collection: true
end
# @see http://ogp.me/#structured
class Video
include Object
namespace :og, :video
content :url
# @!macro property
# @return [String, nil]
url :secure_url
# @!macro property
# @return [String, nil]
string :type
# @!macro property
# @return [Integer, nil]
integer :width
# @!macro property
# @return [Integer, nil]
integer :height
# @return [String, nil]
def url
secure_url || content
end
end
end
# @see http://ogp.me/#type_profile
class Profile
include Object
namespace :profile
content :url
# @!macro property
# @return [String, nil]
string :first_name
# @!macro property
# @return [String, nil]
string :last_name
# @!macro property
# @return [String, nil]
string :username
# @!macro property
# @return [String, nil]
enum :gender, %w(male female)
# @!macro property
# @return [String, nil]
# This one only exists because video had to define a video:actor:role,
# yay for designing a protocol with implementations in mind
string :role
end
# @see http://ogp.me/#type_article
class Article
include Object
namespace :article
# @!macro property
# @return [DateTime, nil]
datetime :published_time
# @!macro property
# @return [DateTime, nil]
datetime :modified_time
# @!macro property
# @return [DateTime, nil]
datetime :expiration_time
# @todo This one is a reference to another OpenGraph object. Support fetching it?
# @!attribute [r] authors
# @return [Array<Profile>]
# @!macro property
# @return [Profile, nil]
url :author, collection: true, to: Profile
# @!macro property
# @return [String, nil]
string :section
# @!attribute [r] tags
# @return [Array<String>]
# @!macro property
# @return [String, nil]
string :tag, collection: true
end
# @see http://ogp.me/#type_video
class Video
include Object
namespace :video
# @!attribute [r] actors
# @return [Array<Profile>]
# @!macro property
# @return [Profile, nil]
url :actor, to: Profile, verticals: %w(movie episode tv_show other), collection: true
# @!attribute [r] directors
# @return [Array<Profile>]
# @!macro property
# @return [Profile, nil]
url :director, to: Profile, verticals: %w(movie episode tv_show other), collection: true
# @!attribute [r] writers
# @return [Array<Profile>]
# @!macro property
# @return [Profile, nil]
url :writer, to: Profile, verticals: %w(movie episode tv_show other), collection: true
# @!macro property
# @return [Integer, nil]
integer :duration, verticals: %w(movie episode tv_show other)
# @!macro property
# @return [DateTime, nil]
datetime :release_date, verticals: %w(movie episode tv_show other)
# @!attribute [r] tags
# @return [Array<String>]
# @!macro property
# @return [String, nil]
string :tag, verticals: %w(movie episode tv_show other), collection: true
# @todo validate that target vertical is video.tv_show ?
# @!macro property
# @return [Sring, nil]
url :series, to: Video, verticals: %w(episode)
end
# @see http://ogp.me/#type_book
class Book
include Object
namespace :book
# @todo This one is a reference to another OpenGraph object. Support fetching it?
# @!attribute [r] authors
# @return [Array<Profile>]
# @!macro property
# @return [Profile, nil]
url :author, collection: true, to: Profile
# @!macro property
# @return [Sring, nil]
string :isbn
# @!macro property
# @return [DateTime, nil]
datetime :release_date
# @!attribute [r] tags
# @return [Array<String>]
# @!macro property
# @return [String, nil]
string :tag, collection: true
end
# @see http://ogp.me/#type_music
class Music
include Object
namespace :music
# @!macro property
# @return [Integer, nil]
integer :duration, verticals: %w(song)
# @todo validate that target vertical is music.album/music.song ?
# @!attribute [r] albums
# @return [Array<Music>]
# @macro property
# @return [Music, nil]
url :album, to: Music, verticals: %w(song), collection: true
# @macro property
# @return [Integer, nil]
integer :disc, verticals: %w(song album playlist)
# @macro property
# @return [Integer, nil]
integer :track, verticals: %w(song album playlist)
# @!attribute [r] musicians
# @return [Array<Profile>]
# @!macro property
# @return [Profile, nil]
url :musician, to: Profile, verticals: %w(song album), collection: true
# @macro property
# @return [Music, nil]
url :song, to: Music, verticals: %w(album playlist)
# @macro property
# @return [DateTime, nil]
datetime :release_date, verticals: %w(album)
# @macro property
# @return [Profile, nil]
url :creator, to: Profile, verticals: %w(playlist radio_station)
end
end
|