2
2
3
3
const querystring = require ( 'querystring' )
4
4
5
- const request = require ( './picasaRequest ' )
5
+ const request = require ( './request ' )
6
6
7
- function Picasa ( clientId , redirectURI , clientSecret ) {
7
+ function Picasa ( clientId , redirectURI , clientSecret ) {
8
8
this . clientId = clientId
9
9
this . redirectURI = redirectURI
10
10
this . clientSecret = clientSecret
11
11
12
- this . request = request
12
+ this . executeRequest = request . executeRequest
13
+ this . picasaRequest = request . picasaRequest
13
14
}
14
15
15
16
Picasa . prototype . getPhotos = getPhotos
@@ -18,26 +19,7 @@ Picasa.prototype.getAuthURL = getAuthURL
18
19
Picasa . prototype . getAccessToken = getAccessToken
19
20
20
21
function getPhotos ( accessToken , options , callback ) {
21
- const host = 'https://picasaweb.google.com'
22
- const path = '/data/feed/api/user/default'
23
-
24
- const accessTokenParams = {
25
- alt : 'json' , // Fetch as JSON
26
- kind : 'photo' ,
27
- access_token : accessToken
28
- }
29
-
30
- if ( options . maxResults ) accessTokenParams [ 'max-results' ] = options . maxResults
31
-
32
- const accessTokenQuery = querystring . stringify ( accessTokenParams )
33
- const requestOptions = {
34
- url : `${ host } ${ path } ?${ accessTokenQuery } ` ,
35
- headers : {
36
- 'GData-Version' : '2'
37
- }
38
- }
39
-
40
- this . request ( 'get' , requestOptions , ( error , body ) => {
22
+ this . picasaRequest ( accessToken , 'get' , 'photo' , options , ( error , body ) => {
41
23
if ( error ) return callback ( error )
42
24
43
25
const photos = body . feed . entry . map ( entry => { return entry . content } )
@@ -80,7 +62,7 @@ function getAccessToken (code, callback) {
80
62
url : `${ host } ${ path } ?${ accessTokenQuery } `
81
63
}
82
64
83
- this . request ( 'post' , options , ( error , body ) => {
65
+ this . executeRequest ( 'post' , options , ( error , body ) => {
84
66
if ( error ) return callback ( error )
85
67
86
68
callback ( null , body . access_token )
0 commit comments