Skip to content

Commit

Permalink
Updates to pass latest linter (patch)
Browse files Browse the repository at this point in the history
  • Loading branch information
zrrrzzt committed Jul 29, 2019
1 parent cda989d commit 51c2be8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 33 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ lib-cov

# Coverage directory used by tools like istanbul
coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
Expand Down
56 changes: 23 additions & 33 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,31 @@ const { google } = require('googleapis')
const validUrl = require('valid-url')
const getResults = require('./lib/get-result')

module.exports = options => {
return new Promise(async (resolve, reject) => {
if (!options.key && !options.nokey) {
const error = new Error('Missing required param: key')
return reject(error)
}
module.exports = async options => {
if (!options.key && !options.nokey) {
const error = new Error('Missing required param: key')
throw error
}

if (!options.url) {
const error = new Error('Missing required param: url')
return reject(error)
}
if (!options.url) {
const error = new Error('Missing required param: url')
throw error
}

if (options.url && !validUrl.isWebUri(options.url)) {
const error = new Error('Invalid url')
return reject(error)
}
if (options.url && !validUrl.isWebUri(options.url)) {
const error = new Error('Invalid url')
throw error
}

const apiVersion = options.apiversion || 'v4'
const apiVersion = options.apiversion || 'v4'

if (options.useweb) {
const pagespeedUrl = `https://www.googleapis.com/pagespeedonline/${apiVersion}/runPagespeed`
try {
const data = await getResults({ apiUrl: pagespeedUrl, qs: options })
return resolve(data)
} catch (error) {
return reject(error)
}
} else {
const pagespeedonline = google.pagespeedonline(apiVersion)
try {
const { data } = await pagespeedonline.pagespeedapi.runpagespeed(options)
return resolve(data)
} catch (error) {
return reject(error)
}
}
})
if (options.useweb) {
const pagespeedUrl = `https://www.googleapis.com/pagespeedonline/${apiVersion}/runPagespeed`
const data = await getResults({ apiUrl: pagespeedUrl, qs: options })
return data
} else {
const pagespeedonline = google.pagespeedonline(apiVersion)
const { data } = await pagespeedonline.pagespeedapi.runpagespeed(options)
return data
}
}

0 comments on commit 51c2be8

Please sign in to comment.