Skip to content

Commit 59843f2

Browse files
committed
1 parent 82ffdf7 commit 59843f2

11 files changed

Lines changed: 2480 additions & 1547 deletions

File tree

Flickr4Java/src/com/flickr4java/flickr/Flickr.java

Lines changed: 615 additions & 605 deletions
Large diffs are not rendered by default.

Flickr4Java/src/com/flickr4java/flickr/Flickr.java.bak

Lines changed: 605 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.flickr4java.flickr.cameras;
2+
3+
public class Brand {
4+
5+
private String id;
6+
7+
private String name;
8+
9+
public String getName() {
10+
return name;
11+
}
12+
13+
public void setName(String name) {
14+
this.name = name;
15+
}
16+
17+
public String getId() {
18+
return id;
19+
}
20+
21+
public void setId(String id) {
22+
this.id = id;
23+
}
24+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.flickr4java.flickr.cameras;
2+
3+
public class Camera {
4+
5+
private String id;
6+
7+
private Details details;
8+
9+
private String smallImage;
10+
11+
private String largeImage;
12+
13+
private String name;
14+
15+
public String getSmallImage() {
16+
return smallImage;
17+
}
18+
19+
public void setSmallImage(String smallImage) {
20+
this.smallImage = smallImage;
21+
}
22+
23+
public String getLargeImage() {
24+
return largeImage;
25+
}
26+
27+
public void setLargeImage(String largeImage) {
28+
this.largeImage = largeImage;
29+
}
30+
31+
public String getId() {
32+
return id;
33+
}
34+
35+
public void setId(String id) {
36+
this.id = id;
37+
}
38+
39+
public Details getDetails() {
40+
return details;
41+
}
42+
43+
public void setDetails(Details details) {
44+
this.details = details;
45+
}
46+
47+
public String getName() {
48+
return name;
49+
}
50+
51+
public void setName(String name) {
52+
this.name = name;
53+
}
54+
55+
}
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
/**
2+
* @author acaplan
3+
*/
4+
package com.flickr4java.flickr.cameras;
5+
6+
import java.util.ArrayList;
7+
import java.util.HashMap;
8+
import java.util.List;
9+
import java.util.Map;
10+
11+
import org.apache.log4j.Logger;
12+
import org.w3c.dom.Element;
13+
import org.w3c.dom.NodeList;
14+
15+
import com.flickr4java.flickr.Flickr;
16+
import com.flickr4java.flickr.FlickrException;
17+
import com.flickr4java.flickr.Response;
18+
import com.flickr4java.flickr.Transport;
19+
import com.flickr4java.flickr.util.XMLUtilities;
20+
21+
/**
22+
* Interface for flickr.collections.* methods.
23+
*
24+
* @author callmeal
25+
* @version $Id$ Copyright (c) 2012 allanc
26+
*/
27+
public class CamerasInterface {
28+
private static final String METHOD_GET_BRANDS = "flickr.cameras.getBrands";
29+
30+
private static final String METHOD_GET_BRAND_MODELS = "flickr.cameras.getBrandModels";
31+
32+
/**
33+
* Logger for log4j.
34+
*/
35+
@SuppressWarnings("unused")
36+
private static Logger _log = Logger.getLogger(CamerasInterface.class);
37+
38+
private final String apiKey;
39+
40+
private final String sharedSecret;
41+
42+
private final Transport transportAPI;
43+
44+
public CamerasInterface(String apiKey, String sharedSecret, Transport transportAPI) {
45+
this.apiKey = apiKey;
46+
this.sharedSecret = sharedSecret;
47+
this.transportAPI = transportAPI;
48+
}
49+
50+
/**
51+
* Returns all the brands of cameras that Flickr knows about.
52+
*
53+
* This method does not require authentication.
54+
*
55+
*
56+
* @return List of Brands
57+
* @throws FlickrException
58+
*/
59+
public List<Brand> getBrands() throws FlickrException {
60+
Map<String, Object> parameters = new HashMap<String, Object>();
61+
parameters.put("method", METHOD_GET_BRANDS);
62+
parameters.put(Flickr.API_KEY, apiKey);
63+
64+
Response response = transportAPI.get(transportAPI.getPath(), parameters, sharedSecret);
65+
if (response.isError()) {
66+
throw new FlickrException(response.getErrorCode(), response.getErrorMessage());
67+
}
68+
69+
List<Brand> lst = new ArrayList<Brand>();
70+
Element mElement = response.getPayload();
71+
NodeList brandElements = mElement.getElementsByTagName("brand");
72+
for (int i = 0; i < brandElements.getLength(); i++) {
73+
Element brandElement = (Element) brandElements.item(i);
74+
Brand brand = new Brand();
75+
brand.setId(brandElement.getAttribute("id"));
76+
brand.setName(brandElement.getAttribute("name"));
77+
lst.add(brand);
78+
}
79+
80+
return lst;
81+
}
82+
83+
/**
84+
* Returns all the brands of cameras that Flickr knows about.
85+
*
86+
* This method does not require authentication.
87+
*
88+
*
89+
* @return List of Brands
90+
* @throws FlickrException
91+
*/
92+
public List<Camera> getBrandModels(String strBrand) throws FlickrException {
93+
Map<String, Object> parameters = new HashMap<String, Object>();
94+
parameters.put("method", METHOD_GET_BRAND_MODELS);
95+
parameters.put(Flickr.API_KEY, apiKey);
96+
parameters.put("brand", strBrand);
97+
98+
Response response = transportAPI.get(transportAPI.getPath(), parameters, sharedSecret);
99+
if (response.isError()) {
100+
throw new FlickrException(response.getErrorCode(), response.getErrorMessage());
101+
}
102+
103+
List<Camera> lst = new ArrayList<Camera>();
104+
Element mElement = response.getPayload();
105+
NodeList cameraElements = mElement.getElementsByTagName("camera");
106+
for (int i = 0; i < cameraElements.getLength(); i++) {
107+
Element cameraElement = (Element) cameraElements.item(i);
108+
Camera cam = new Camera();
109+
cam.setId(cameraElement.getAttribute("id"));
110+
cam.setName(XMLUtilities.getChildValue(cameraElement, "name"));
111+
112+
NodeList detailsNodes = cameraElement.getElementsByTagName("details");
113+
int n = detailsNodes.getLength();
114+
if (n == 1) {
115+
Element detailElement = (Element) detailsNodes.item(0);
116+
Details detail = new Details();
117+
cam.setDetails(detail);
118+
detail.setMegapixels(XMLUtilities.getChildValue(detailElement, "megapixels"));
119+
detail.setZoom(XMLUtilities.getChildValue(detailElement, "zoom"));
120+
detail.setLcdSize(XMLUtilities.getChildValue(detailElement, "lcd_screen_size"));
121+
detail.setStorageType(XMLUtilities.getChildValue(detailElement, "memory_type"));
122+
}
123+
124+
NodeList imageNodes = cameraElement.getElementsByTagName("images");
125+
n = imageNodes.getLength();
126+
if (n == 1) {
127+
Element imageElement = (Element) imageNodes.item(0);
128+
cam.setSmallImage(XMLUtilities.getChildValue(imageElement, "small"));
129+
cam.setLargeImage(XMLUtilities.getChildValue(imageElement, "large"));
130+
}
131+
132+
lst.add(cam);
133+
}
134+
135+
return lst;
136+
}
137+
138+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.flickr4java.flickr.cameras;
2+
3+
public class Details {
4+
private String megapixels;
5+
6+
private String zoom;
7+
8+
private String lcdSize;
9+
10+
private String storageType;
11+
12+
public String getMegapixels() {
13+
return megapixels;
14+
}
15+
16+
public void setMegapixels(String megapixels) {
17+
this.megapixels = megapixels;
18+
}
19+
20+
public String getZoom() {
21+
return zoom;
22+
}
23+
24+
public void setZoom(String zoom) {
25+
this.zoom = zoom;
26+
}
27+
28+
public String getLcdSize() {
29+
return lcdSize;
30+
}
31+
32+
public void setLcdSize(String lcdSize) {
33+
this.lcdSize = lcdSize;
34+
}
35+
36+
public String getStorageType() {
37+
return storageType;
38+
}
39+
40+
public void setStorageType(String storageType) {
41+
this.storageType = storageType;
42+
}
43+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.flickr4java.flickr.test;
2+
3+
import static junit.framework.Assert.assertNotNull;
4+
import static junit.framework.Assert.assertTrue;
5+
6+
import java.util.Collection;
7+
8+
import org.junit.Test;
9+
10+
import com.flickr4java.flickr.Flickr;
11+
import com.flickr4java.flickr.FlickrException;
12+
import com.flickr4java.flickr.cameras.Brand;
13+
import com.flickr4java.flickr.cameras.Camera;
14+
import com.flickr4java.flickr.cameras.CamerasInterface;
15+
16+
public class CamerasInterfaceTest extends Flickr4JavaTest {
17+
18+
@Test
19+
public void testGetBrands() throws FlickrException {
20+
21+
// not implementing much for tests here - flickr doesn't give us much to go on.
22+
CamerasInterface camInterface = flickr.getCamerasInterface();
23+
Collection<Brand> brands = camInterface.getBrands();
24+
assertNotNull(brands);
25+
assertTrue(brands.size() > 0);
26+
}
27+
28+
@Test
29+
public void testGetBrandModels() throws FlickrException {
30+
31+
// not implementing much for tests here - flickr doesn't give us much to go on.
32+
// the interface may not be final - the documented xml nodes don't correspond to what is in the xml
33+
CamerasInterface camInterface = flickr.getCamerasInterface();
34+
Flickr.debugStream = true;
35+
Collection<Camera> cams = camInterface.getBrandModels("Canon");
36+
assertNotNull(cams);
37+
assertTrue(cams.size() > 0);
38+
for (Camera cam : cams) {
39+
assertNotNull(cam.getId());
40+
assertNotNull(cam.getName());
41+
/*
42+
* assertNotNull(cam.getSmallImage()); assertNotNull(cam.getLargeImage()); assertNotNull(cam.getDetails().getMegapixels());
43+
* assertNotNull(cam.getDetails().getZoom()); assertNotNull(cam.getDetails().getLcdSize()); assertNotNull(cam.getDetails().getStorageType());
44+
*/}
45+
}
46+
47+
}

0 commit comments

Comments
 (0)