Skip to content

Commit

Permalink
feat: update got
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Feb 2, 2020
1 parent aa9481e commit f11838b
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 13 deletions.
4 changes: 2 additions & 2 deletions packages/metascraper-iframe/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
],
"dependencies": {
"@metascraper/helpers": "^5.10.7",
"got": "~9.6.0",
"got": "~10.4.0",
"lodash": "~4.17.15",
"oembed-spec": "~1.2.0",
"oembed-spec": "~1.3.0",
"p-reflect": "~2.1.0"
},
"devDependencies": {
Expand Down
6 changes: 4 additions & 2 deletions packages/metascraper-iframe/src/from-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ const fromHTML = gotOpts => async ({ url, meta, htmlDom, ...opts }) => {
if (!oembedUrl) return null
const oembedUrlObj = new URL(oembedUrl)
forEach(opts, (value, key) => oembedUrlObj.searchParams.append(key, value))
const { value } = await pReflect(got(oembedUrlObj.toString(), gotOpts))
return get(value, 'body.html', null)
const { value } = await pReflect(
got(oembedUrlObj.toString(), gotOpts).json()
)
return get(value, 'html', null)
}

fromHTML.test = $ => !!jsonOembed($)
Expand Down
3 changes: 1 addition & 2 deletions packages/metascraper-iframe/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ const test = memoizeOne(
({ url, htmlDom: $ }) => htmlTest($) || providerTest(url)
)

module.exports = ({ gotOpts: _gotOpts } = {}) => {
const gotOpts = { json: true, retry: 0, ..._gotOpts }
module.exports = ({ gotOpts } = {}) => {
const rules = { iframe: [fromHTML(gotOpts), fromProvider(gotOpts)] }
rules.test = test
return rules
Expand Down
2 changes: 1 addition & 1 deletion packages/metascraper-iframe/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('metascraper-iframe', () => {
describe('opts', () => {
it('pass custom got options', async () => {
const cache = new Map()
const gotOpts = { json: true, retry: 0, cache }
const gotOpts = { cache }

const html = await readFile(resolve(__dirname, 'fixtures/genially.html'))
const url = 'https://view.genial.ly/5dc53cfa759d2a0f4c7db5f4'
Expand Down
2 changes: 1 addition & 1 deletion packages/metascraper-logo-favicon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
],
"dependencies": {
"@metascraper/helpers": "^5.10.7",
"got": "~9.6.0",
"got": "~10.4.0",
"lodash": "~4.17.15"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/metascraper-media-provider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"dependencies": {
"@metascraper/helpers": "^5.10.7",
"debug": "~4.1.1",
"got": "~9.6.0",
"got": "~10.4.0",
"lodash": "~4.17.15",
"luminati-tunnel": "~1.3.0",
"p-reflect": "~2.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ const createGuestToken = ({ userAgent, tunnel }) => {
const { body } = await got.post(
'https://api.twitter.com/1.1/guest/activate.json',
{
json: true,
retry: 0,
responseType: 'json',
agent,
headers: {
authorization: TWITTER_BEARER_TOKEN,
Expand All @@ -59,8 +58,7 @@ const createGetTwitterVideo = ({ userAgent, getGuestToken }) => {
const getData = async (apiUrl, url, token) => {
const { isFulfilled, value, reason } = await pReflect(
got(apiUrl, {
retry: 0,
json: true,
responseType: 'json',
headers: {
referer: url,
'x-guest-token': token,
Expand Down

0 comments on commit f11838b

Please sign in to comment.