1.8.4 • Published 5 years ago
wykop-v2-typescript v1.8.4
wykop-v2-typescript
Simple, minimal wrapper for shitty wykop api v2
Instalation
yarn add wykop-v2-typescript
ornpm 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: undefinedRequest 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();- Put 
urlinatag 
- With redirect
 
const wykop = new Wykop({
  appKey: 'asdnasdnad',
  appSecret: 'sdakdsajd',
});
const { url, secure } = wykop.wykopConnectLink('http://localhost:8080');After user logs in to Wykop will redirect be to
http://localhost:8080/?connectData=XXXXXXXXXXThen you can catch
XXXXXXXXXXfrom url and decode user with:
JSON.parse(atob('XXXXXXXXXX'));- Use 
securefor checking if correct user was returned 
1.8.4
5 years ago
1.8.3
5 years ago
1.8.2
5 years ago
1.8.1
5 years ago
1.8.0
5 years ago
1.7.0
5 years ago
1.6.0
5 years ago
1.5.1
5 years ago
1.5.0
5 years ago
1.4.1
5 years ago
1.4.0
5 years ago
1.3.3
5 years ago
1.3.2
5 years ago
1.3.1
5 years ago
1.2.1
5 years ago
1.2.0
5 years ago
1.1.0
5 years ago
1.0.4
5 years ago
1.0.3
5 years ago
1.0.2
6 years ago
1.0.1
6 years ago
1.0.0
6 years ago