react-native-google-shortener

1.1.0 • Public • Published

Build Status

Google URL Shortener

This package is supposed to communicate between API of Google URL Shortener to your app.

Installation

You can run this package to use the package

npm install --save react-native-google-shortener

How to use the package

The first thing you need to do is set the Google API key. You can obtain to your Google Developer Console.

const { setKey, shorten, expand } = require('react-native-google-shortener');
 
setKey('your google api key');

Shorten URL

Then, to shorten your long URL, you can use this code.

shorten('https://mgufron.com').then(response => {
  console.log('shorten url', response.id);
  console.log('long url', response.longUrl);
})

Expand Shortened URL

// first argument should shortened url
expand('https://goo.gl/').then(response => {
  console.log(response.id);
  console.log(response.longUrl);
});

Full example code would be something like this

const { setKey, shorten } = require('react-native-google-shortener');
setKey('your google api key');
shorten('https://mgufron.com').then(response => {
  // do your thing
  console.log('shorten url', response.id);
  console.log('long url', response.longUrl);
});
expand('https://goo.gl/alskd').then(response => {
  console.log(response.id);
  console.log(response.longUrl);
  console.log(response.status);
});
// include projection or analytics
expand('https://goo.gl/alkaslk').then(response => {
  console.log(response.id);
  console.log(response.longUrl);
  console.log(response.status);
  console.log(response.analytics);
})

Contribution

I love feedback so you can put your feedback to Issues or make a pull request to this package. I love to get any comments regarding my work. Happy Coding.

Package Sidebar

Install

npm i react-native-google-shortener

Weekly Downloads

1

Version

1.1.0

License

MIT

Last publish

Collaborators

  • mgufrone