-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlickrManager.java
More file actions
96 lines (79 loc) · 2.78 KB
/
Copy pathFlickrManager.java
File metadata and controls
96 lines (79 loc) · 2.78 KB
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
package photorainbow;
import FlickrNet.Flickr;
import FlickrNet.OAuthAccessToken;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.List;
public class FlickrManager implements APIManager {
private static final Logger log = Logger.getLogger(FlickrManager.class.getName());
/* Constants */
private static final String API_KEY = "6c24e7c523faa6feee78c696b8ea31e2";
private static final String SHARED_SECRET = "88b95e7cc030a4cf";
/* Instance fields */
private String url;
private OAuthRequestToken requestToken;
private OAuthAccessToken flickrToken;
private Flickr instance;
/* Constructors */
public FlickrManager() {
instance = new Flickr(API_KEY, SHARED_SECRET);
}
/* Accessors and Mutators */
public String getUrl() {
return this.url;
}
public void setUrl(String url) {
this.url = url;
}
public OAuthAccessToken getOAuthToken() {
return this.flickrToken;
}
public void getOAuthToken(OAuthAccessToken flickrToken) {
this.flickrToken = flickrToken;
}
public Flickr getInstance() {
return this.instance;
}
public void setInstance(Flickr flickr) {
this.instance = flickr;
}
/* APIManager interface method implementations */
public void authenticate() {
requestToken = instance.getOAuthRequestToken("oob");
url = instance.getOAuthCalculateAuthorizationUrl(requestToken.getToken(), AuthLevel.WRITE);
}
public boolean isAuthenticated() {
return getOAuthToken() != null;
}
/**
* Get all images from Flickr store.
* If large size variant exists for image (we want to ignore thumbnails), create a new image using the large size URL
* And add the image to metadata collection
* Also add color data to the metadata collection for the image
**/
public ImageDataStore storeMedia() {
List<Image> images = new List<Image>();
ImageDataStore iODObj = new ImageDataStore();
ImageColorData iCDObj = new ImageColorData();
PhotoCollection photocollection = instance.getPeoplePhotos();
for (Photo p : photocollection) {
if (p.getLargeUrl() != null) {
Image userImage = new Image(p.getLargeUrl());
iCDObj.getColorData(userImage);
images.add(userImage);
}
}
iODObj.setImages(images);
iODObj.setImgObjColorData(iCDObj);
return iODObj;
}
/* Other Public methods */
public void completeAuth(String code) {
try {
setOAuthToken(iInstance.getOAuthAccessToken(requestToken, code));
}
catch (FlickrApiException ex) {
log.log(Level.ERROR, ex.printStackTrace());
}
}
}