Class: Ayadn::Annotations

Inherits:
Object
  • Object
show all
Defined in:
lib/ayadn/annotations.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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 += nowplaying(dic) if dic[:options][:nowplaying]
  @content += movie(dic) if dic[:options][:movie]
  @content += tvshow(dic) if dic[:options][:tvshow]
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



7
8
9
# File 'lib/ayadn/annotations.rb', line 7

def content
  @content
end

Instance Method Details

#baseObject



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
# 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"
        }
      }
    },
    {
    "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



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/ayadn/annotations.rb', line 47

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



128
129
130
131
132
133
134
135
136
# File 'lib/ayadn/annotations.rb', line 128

def movie(dic)
  [{
    "type" => "com.ayadn.movie",
      "value" => {
        "title" => dic[:title],
        "source" => dic[:source]
      }
  }]
end

#nowplaying(dic) ⇒ Object



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
# File 'lib/ayadn/annotations.rb', line 158

def nowplaying(dic)
  return nowplaying_silent(dic) if dic[:options][:no_url]
  [{
    "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



148
149
150
151
152
153
154
155
156
# File 'lib/ayadn/annotations.rb', line 148

def nowplaying_silent(dic)
  [{
    "type" => "com.ayadn.nowplaying",
      "value" => {
        "status" => "no-url",
        "source" => dic[:source]
      }
  }]
end

#tvshow(dic) ⇒ Object



138
139
140
141
142
143
144
145
146
# File 'lib/ayadn/annotations.rb', line 138

def tvshow(dic)
  [{
    "type" => "com.ayadn.tvshow",
      "value" => {
        "title" => dic[:title],
        "source" => dic[:source]
      }
  }]
end

#vimeo(dic) ⇒ Object



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
# File 'lib/ayadn/annotations.rb', line 96

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



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
# File 'lib/ayadn/annotations.rb', line 64

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