ishikawa (owner)

Revisions

gist: 209729 Download_button fork
public
Public Clone URL: git://gist.github.com/209729.git
Embed All Files: show embed
albums.xml #
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
<?xml version="1.0" encoding="UTF-8" ?>
<Module>
  <ModulePrefs title="Fun with Albums" >
    <Require feature="opensocial-0.8" />
    <Optional feature="content-rewrite">
      <Param name="expires">86400</Param>
      <Param name="include-urls"></Param>
      <Param name="exclude-urls">.*</Param>
    </Optional>
  </ModulePrefs>
  <Content type="html">
  <![CDATA[
 
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.0.3/prototype.js"></script>
<script type="text/javascript">
 
var Formatter = Class.create({
_append: function(content) {
this.element.insert(content);
},
head3: function() {
this._append('<h3>' + $A(arguments).join("") + '</h3>');
},
img1: function(url) {
this._append('<p><img src="' + url + '"></p>');
},
description: function(message) {
this._append('<p class="description">' + message + '</p>');
},
clear: function() {
this.element.update("");
},
initialize: function(element) {
this.element = $(element);
}
});
 
function request_albums() {
var request = opensocial.newDataRequest();
 
var params = {};
var offset_input = $('offset_input');
var limit_input = $('limit_input');
 
if (offset_input.present()) {
params[opensocial.DataRequest.AlbumRequestFields.FIRST] = parseInt(offset_input.getValue(), "10");
}
if (limit_input.present()) {
params[opensocial.DataRequest.AlbumRequestFields.MAX] = parseInt(limit_input.getValue(), "10");
}
 
request.add(request.newFetchAlbumsRequest(opensocial.IdSpec.PersonId.VIEWER, params), "albums");
request.send(function(data) {
var response = data.get("albums");
 
if (response.hadError()) {
alert(response.getErrorCode() + ": " + response.getErrorMessage());
} else {
var format = new Formatter($('console'));
var albums = response.getData();
 
format.clear();
albums.each(function(album) {
var id = album.getField(opensocial.Album.Field.ID);
var title = album.getField(opensocial.Album.Field.TITLE);
var count = album.getField(opensocial.Album.Field.MEDIA_ITEM_COUNT);
var description = album.getField(opensocial.Album.Field.DESCRIPTION);
var thumb = album.getField(opensocial.Album.Field.THUMBNAIL_URL);
 
format.head3(new Template("#{id}: #{title} (#{count})").evaluate({
id: id,
title: title,
count: count || -1
}));
 
if (thumb != null) format.img1(thumb);
format.description(description);
});
}
});
}
 
function request_photos() {
var input = $("album_id_input");
 
if (!input.present()) {
alert("Album ID is empty");
return;
}
 
var album_id = parseInt(input.getValue(), "10");
var request = opensocial.newDataRequest();
 
var params = {};
var offset_input = $('offset_input');
var limit_input = $('limit_input');
 
if (offset_input.present()) {
params[opensocial.DataRequest.MediaItemRequestFields.FIRST] = parseInt(offset_input.getValue(), "10");
}
if (limit_input.present()) {
params[opensocial.DataRequest.MediaItemRequestFields.MAX] = parseInt(limit_input.getValue(), "10");
}
 
request.add(request.newFetchMediaItemsRequest(opensocial.IdSpec.PersonId.VIEWER, album_id, params), "mediaItems");
request.send(function(data) {
var response = data.get("mediaItems");
 
if (response.hadError()) {
alert(response.getErrorCode() + ": " + response.getErrorMessage());
} else {
var format = new Formatter($('console'));
var medias = response.getData();
 
format.clear();
medias.each(function(media) {
var v = {
url: media.getField(opensocial.MediaItem.Field.URL),
title: media.getField(opensocial.MediaItem.Field.TITLE),
thumbnailURL: media.getField(opensocial.MediaItem.Field.THUMBNAIL_URL),
description: media.getField(opensocial.MediaItem.Field.DESCRIPTION),
fileSize: media.getField(opensocial.MediaItem.Field.FILE_SIZE),
albumId: media.getField(opensocial.MediaItem.Field.ALBUM_ID),
id: media.getField(opensocial.MediaItem.Field.ID)
};
 
format.head3(new Template("#{id}: #{title} (#{size})").evaluate({
id: v.id,
title: v.title,
size: v.fileSize || -1
}));
 
if (v.thumbnailURL != null) format.img1(v.thumbnailURL);
format.description(v.description);
});
}
});
 
}
 
function init() {
}
 
gadgets.util.registerOnLoadHandler(init);
</script>
 
<div id="main">
 
<form id="forms">
<input type="button" value="Albums" onclick="javascript: request_albums(); return false;" /><br />
<input id="album_id_input" type="text" value="" size="10" />
<input type="button" value="Photos" onclick="javascript: request_photos(); return false;" /><br />
offset: <input id="offset_input" type="text" value="" size="8" />&nbsp;
limit: <input id="limit_input" type="text" value="" size="8" />
</form>
 
<div id="console"></div>
</div>
 
]]>
  </Content>
</Module>