1.8.4 • Published 3 years ago

wykop-v2-typescript v1.8.4

Weekly downloads
50
License
MIT
Repository
github
Last release
3 years ago

wykop-v2-typescript

npm version Maintainability Test Coverage Node.js CI dependencies Status

Simple, minimal wrapper for shitty wykop api v2

Instalation

yarn add wykop-v2-typescript
or
npm install wykop-v2-typescript

Wykop Api v2 documentation

https://www.wykop.pl/dla-programistow/apiv2/

Initialization

import wykop from "wykop-v2-typescript"

const wykop = new Wykop({
  appKey: string,
  appSecret: string,
  secure: boolean, // if set to true url will be prefixed with 'https', otherwise 'http'
  wykopUrl: string // base url for wykop (without trailing slash)
  }
  userkey: string // userkey uses for requests
)

Default options

{
  appKey: null,
  appSecret: null,
  secure: true,
  wykopUrl: a2.wykop.pl
}
userkey: undefined

Request parameters

wykop.request({
  methods: string[] // array with strings, will be parsed as string/string/
  ,
  namedParams: {
    [key: string]: string | number
  } // object with API parameters, will be parsed as key/value/key/value
  ,
  apiParams: string[] // array with strings, will be parsed as string/string/
  ,
  postParams: {
    [key: string]: string | number
  } // object will be send in body as key=value&key=value
  ,
  reorderParams: boolean = false // If your request returns that something doesn't exists try to set this to true
})

Example request (without logging user)

  • Without async/await
const wykop = new Wykop({
  appKey: 'asdnasdnad',
  appSecret: 'sdakdsajd',
});

wykop
  .request({
    methods: ['Entries', 'Hot'],
    namedParams: { page: 1, period: 6 },
  })
  .then((res) => {
    // Response from wykop
  })
  .catch((error) => {
    // Only if something went wrong 😁
  });
  • With async/await
// Dont forget to put this code in async function
const wykop = new Wykop({
  appKey: 'asdnasdnad',
  appSecret: 'sdakdsajd',
});

try {
  const response = await wykop.request({
    methods: ['Entries', 'Hot'],
    namedParams: { page: 1, period: 6 },
  });
  // Your code here
} catch (err) {
  // Only if something went wrong 😁
}

Example request (with userkey)

  • Without async/await
const wykop = new Wykop({
  appKey: 'asdnasdnad',
  appSecret: 'sdakdsajd',
});

wykop
  .request({
    methods: ['Login', 'Index'],
    postParams: { login: 'Vegann', accountkey: 'Token from wykop connect' },
  })
  .then(() => {
    // userkey will be stored in wykop.userkey you dont need to provide it once logged in
    return wykop.request({
      methods: ['Entries', 'Add'],
      postParams: { body: 'Body' },
    });
  })
  .then((res) => {
    // Response from wykop
  })
  .catch((error) => {
    // Only if something went wrong 😁
  });
  • With async/await
// Dont forget to put this code in async function
const wykop = new Wykop({
  appKey: 'asdnasdnad',
  appSecret: 'sdakdsajd',
});

try {
  await wykop.request({
    methods: ['Login', 'Index'],
    postParams: {
      login: 'Vegann',
      accountkey: 'Token from wykop connect',
    },
  });
  // userkey will be stored in wykop.userkey you dont need to provide it in next requests once logged in
  const res = await wykop.request({
    methods: ['Entries', 'Add'],
    postParams: { body: 'Body' },
  });
  // Response from wykop
} catch (err) {
  // Only if something went wrong 😁
}

Getting link for Wykop connect

  • Without redirect
const wykop = new Wykop({
  appKey: 'asdnasdnad',
  appSecret: 'sdakdsajd',
});

const { url } = wykop.wykopConnectLink();
  1. Put url in a tag
  • With redirect
const wykop = new Wykop({
  appKey: 'asdnasdnad',
  appSecret: 'sdakdsajd',
});

const { url, secure } = wykop.wykopConnectLink('http://localhost:8080');
  1. After user logs in to Wykop will redirect be to http://localhost:8080/?connectData=XXXXXXXXXX

  2. Then you can catch XXXXXXXXXX from url and decode user with:

JSON.parse(atob('XXXXXXXXXX'));
  1. Use secure for checking if correct user was returned
1.8.4

3 years ago

1.8.3

3 years ago

1.8.2

3 years ago

1.8.1

3 years ago

1.8.0

3 years ago

1.7.0

3 years ago

1.6.0

3 years ago

1.5.1

3 years ago

1.5.0

3 years ago

1.4.1

3 years ago

1.4.0

3 years ago

1.3.3

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.0

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago