Class: Ayadn::Annotations
- Inherits:
-
Object
- Object
- Ayadn::Annotations
- Defined in:
- lib/ayadn/annotations.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
Instance Method Summary collapse
- #base ⇒ Object
- #files(dic) ⇒ Object
-
#initialize(dic) ⇒ Annotations
constructor
A new instance of Annotations.
- #movie(dic) ⇒ Object
- #nowplaying(dic) ⇒ Object
- #nowplaying_silent(dic) ⇒ Object
- #tvshow(dic) ⇒ Object
- #vimeo(dic) ⇒ Object
- #youtube(dic) ⇒ Object
Constructor Details
#initialize(dic) ⇒ Annotations
Returns a new instance of Annotations.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/ayadn/annotations.rb', line 9 def initialize(dic) dic[:options] = {} if dic[:options].nil? @content = base() @content += files(dic) if dic[:options][:embed] @content += youtube(dic) if dic[:options][:youtube] @content += vimeo(dic) if dic[:options][:vimeo] @content += (dic) if dic[:options][:nowplaying] @content += movie(dic) if dic[:options][:movie] @content += tvshow(dic) if dic[:options][:tvshow] end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
7 8 9 |
# File 'lib/ayadn/annotations.rb', line 7 def content @content end |
Instance Method Details
#base ⇒ Object
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 |
# File 'lib/ayadn/annotations.rb', line 20 def base [ { "type" => "com.ayadn.user", "value" => { "+net.app.core.user" => { "user_id" => Settings.config[:identity][:handle], "format" => "basic" }, "env" => { "platform" => Settings.config[:platform], "ruby" => Settings.config[:ruby], "locale" => Settings.config[:locale] } } }, { "type" => "com.ayadn.client", "value" => { "url" => "http://ayadn-app.net", "author" => { "name" => "Eric Dejonckheere", "username" => "ericd", "id" => "69904", "email" => "[email protected]" }, "version" => Settings.config[:version] } } ] end |
#files(dic) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/ayadn/annotations.rb', line 52 def files(dic) files = FileOps.make_paths(dic[:options][:embed]) data = FileOps.upload_files(files) data.map do |obj| { "type" => "net.app.core.oembed", "value" => { "+net.app.core.file" => { "file_id" => obj['data']['id'], "file_token" => obj['data']['file_token'], "format" => "oembed" } } } end end |
#movie(dic) ⇒ Object
133 134 135 136 137 138 139 140 141 |
# File 'lib/ayadn/annotations.rb', line 133 def movie(dic) [{ "type" => "com.ayadn.movie", "value" => { "title" => dic[:title], "source" => dic[:source] } }] end |
#nowplaying(dic) ⇒ Object
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 |
# File 'lib/ayadn/annotations.rb', line 163 def (dic) return (dic) if dic[:options][:no_url] == true || dic[:visible] == false [{ "type" => "com.ayadn.nowplaying", "value" => { "title" => dic[:title], "artist" => dic[:artist], "artwork" => dic[:artwork], "link" => dic[:link], "source" => dic[:source] } }, { "type" => "net.app.core.oembed", "value" => { "version" => "1.0", "type" => "photo", "width" => dic[:width], "height" => dic[:height], "title" => dic[:title], "url" => dic[:artwork], "embeddable_url" => dic[:artwork], "provider_url" => "https://itunes.apple.com", "provider_name" => "iTunes", "thumbnail_url" => dic[:artwork_thumb], "thumbnail_width" => dic[:width_thumb], "thumbnail_height" => dic[:height_thumb] } }] end |
#nowplaying_silent(dic) ⇒ Object
153 154 155 156 157 158 159 160 161 |
# File 'lib/ayadn/annotations.rb', line 153 def (dic) [{ "type" => "com.ayadn.nowplaying", "value" => { "status" => "no-url", "source" => dic[:source] } }] end |
#tvshow(dic) ⇒ Object
143 144 145 146 147 148 149 150 151 |
# File 'lib/ayadn/annotations.rb', line 143 def tvshow(dic) [{ "type" => "com.ayadn.tvshow", "value" => { "title" => dic[:title], "source" => dic[:source] } }] end |
#vimeo(dic) ⇒ Object
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 |
# File 'lib/ayadn/annotations.rb', line 101 def vimeo(dic) dic[:link] = dic[:options][:vimeo][0] req_url = "http://vimeo.com/api/oembed.json?url=#{dic[:link]}" dic.merge!(JSON.parse(CNX.download(req_url))) [{ "type" => "net.app.core.oembed", "value" => { "version" => "1.0", "type" => "video", "provider_name" => "Vimeo", "provider_url" => "http://vimeo.com/", "width" => dic['width'], "height" => dic['height'], "title" => dic['title'], "author_name" => dic['author_name'], "author_url" => dic['author_url'], "embeddable_url" => dic[:link], "html" => dic['html'], "thumbnail_url" => dic['thumbnail_url'], "thumbnail_height" => dic['thumbnail_height'], "thumbnail_width" => dic['thumbnail_width'] } }, { "type" => "com.ayadn.vimeo", "value" => { "title" => dic['title'], "link" => dic[:link] } }] end |
#youtube(dic) ⇒ Object
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 |
# File 'lib/ayadn/annotations.rb', line 69 def youtube(dic) dic['link'] = dic[:options][:youtube][0] req_url = "http://www.youtube.com/oembed?url=#{dic['link']}&format=json" dic.merge!(JSON.parse(CNX.download(req_url))) [{ "type" => "net.app.core.oembed", "value" => { "version" => "1.0", "type" => "video", "provider_name" => "YouTube", "provider_url" => "http://youtube.com/", "width" => dic['width'], "height" => dic['height'], "title" => dic['title'], "author_name" => dic['author_name'], "author_url" => dic['author_url'], "embeddable_url" => dic['link'], "html" => dic['html'], "thumbnail_url" => dic['thumbnail_url'], "thumbnail_height" => dic['thumbnail_height'], "thumbnail_width" => dic['thumbnail_width'] } }, { "type" => "com.ayadn.youtube", "value" => { "title" => dic['title'], "link" => dic['link'] } }] end |