Skip to content

Commit

Permalink
fix dead credentials better.
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmdick committed Dec 5, 2013
1 parent 49398e5 commit fa85522
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
29 changes: 25 additions & 4 deletions StippleAPI.lua
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ function StippleAPI.getApiKeyAndSecret()
return apiKey
end

function StippleAPI.resetApiKey()
prefs.apiKey = ''
StippleAPI.getApiKeyAndSecret()
end

--------------------------------------------------------------------------------

function StippleAPI.makeApiSignature( params )
Expand Down Expand Up @@ -211,7 +216,12 @@ function StippleAPI.getRestMethod( propertyTable, params )

-- Mac has different implementation with that on Windows when the server refuses the request.
if hdrs.status ~= 200 then
LrErrors.throwUserError( formatError( hdrs.status ) )
if hdrs.status == 401 then
StippleAPI.resetApiKey()

else
LrErrors.throwUserError( formatError( hdrs.status ) )
end
end

appearsAlive = true
Expand Down Expand Up @@ -350,6 +360,17 @@ function StippleAPI.uploadPhoto( propertyTable, params )
tostring( json.status )))
end
end
--------------------------------------------------------------------------------

function StippleAPI.getSetPhotos( propertyTable, params )
local response = StippleAPI.getRestMethod( nil, { url = params.url or 'sets/' .. params.setId })
if response.data and response.data.set and response.data.set.photos and #response.data.set.photos < 1 then
return
end
for _,photo in pairs(response.data.set.photos) do
tryAddPhoto(photo)
end
end

--------------------------------------------------------------------------------

Expand Down Expand Up @@ -406,12 +427,12 @@ end
--------------------------------------------------------------------------------

function StippleAPI.listPhotosFromPhotoset( propertyTable, params )
local response, ids = {}, {}
local response, photos = {}, {}
response = StippleAPI.getRestMethod(nil, {url = 'sets/' .. params.photosetId})
for _,photo in pairs(response.data.set.photos) do
table.insert(ids,photo.id)
table.insert(photos,photo)
end
return ids
return photos
end

--------------------------------------------------------------------------------
Expand Down
11 changes: 4 additions & 7 deletions StippleExportServiceProvider.lua
Original file line number Diff line number Diff line change
Expand Up @@ -535,15 +535,10 @@ function exportServiceProvider.processRenderedPhotos( functionContext, exportCon

-- Get a list of photos already in this photoset so we know which ones we can replace and which have
-- to be re-uploaded entirely.
local photosetPhotoIds = photosetId and StippleAPI.listPhotosFromPhotoset( exportSettings, { photosetId = photosetId } )
local photosetPhotos = photosetId and StippleAPI.listPhotosFromPhotoset( exportSettings, { photosetId = photosetId } )

local photosetPhotosSet = {} -- Turn it into a set for quicker access later.

if photosetPhotoIds then
for _, id in ipairs( photosetPhotoIds ) do
photosetPhotosSet[ id ] = true
end
end

local couldNotPublishBecauseFreeAccount = {}
local stipplePhotoIdsForRenditions = {}
Expand Down Expand Up @@ -593,7 +588,9 @@ function exportServiceProvider.processRenderedPhotos( functionContext, exportCon
id = stipplePhotoId,
filePath = pathOrMessage,
photo = {
caption = description, source_page = "Stipple Lightroom Plugin" },
caption = description,
source_page = ""
},
claim = 1, -- always claim the photo
}
)
Expand Down

0 comments on commit fa85522

Please sign in to comment.