项目作者: TiagoDanin

项目描述 :
Wrapper for the Unsplash Source API
高级语言: JavaScript
项目地址: git://github.com/TiagoDanin/Unsplash-Source-Node.git
创建时间: 2018-02-02T15:09:06Z
项目社区:https://github.com/TiagoDanin/Unsplash-Source-Node

开源协议:MIT License

下载


Unsplash Source Node Build Status

NPM

Wrapper for the Unsplash Source API

Use

Ger redirectURL

Add the param redirectURL: true
Note: This function use Promise

  1. const unsplash = require('unsplash-source-node')
  2. const url = await unsplash({random: true, redirectURL: true})
  3. //Return string: https://images.unsplash.com/photo-1515349933451-b95498259b01?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=1080&fit=max&ixid=eyJhcHBfaWQiOjF9&s=0f1ac7e4ca80001ea0ec1c2ed6ce08db

Basic

  • Random all photos
  1. const unsplash = require('unsplash-source-node')
  2. const url = unsplash({random: true})
  3. //Return string: https://source.unsplash.com/random/
  • Random from a specific user
  1. const unsplash = require('unsplash-source-node')
  2. const url = unsplash({user: 'tiagodanin'})
  3. //Return string: https://source.unsplash.com/user/tiagodanin/
  • Random from a user’s likes
  1. const unsplash = require('unsplash-source-node')
  2. const url = unsplash({user: 'tiagodanin', likes: true})
  3. //Return string: https://source.unsplash.com/user/tiagoDanin/likes/
  • Random from a collection
  1. const unsplash = require('unsplash-source-node')
  2. const url = unsplash({collection: '190727', likes: true})
  3. //Return string: https://source.unsplash.com/collection/190727/
  • Fixed daily/weekly photo
  1. const unsplash = require('unsplash-source-node')
  2. const urlDaily = unsplash({daily: true})
  3. //Return string: https://source.unsplash.com/daily/
  4. const urlWeekly = unsplash({weekly: true})
  5. //Return string: https://source.unsplash.com/weekly/
  • Random search term
    1. const unsplash = require('unsplash-source-node')
    2. const url = unsplash({search: 'nature,water'})
    3. //Return string: https://source.unsplash.com/?nature,water/

Use with class

  1. const unsplash = require('unsplash-source-node')
  2. let myUnsplash = new unsplash({user: 'tiagodanin'})
  3. myUnsplash.likes = true
  4. myUnsplash.width = 1200
  5. myUnsplash.height = 600
  6. const url = myUnsplash.get()
  7. //Return string: https://source.unsplash.com/user/tiagodanin/likes/1200x600/

Installation

This is a Node.js module available through the
npm registry. It can be installed using the
npm command line tools.

  1. $ npm install unsplash-source-node

Dependencies

  • request: Simplified HTTP request client.
  • request-promise-native: The simplified HTTP request client ‘request’ with Promise support. Powered by native ES6 promises.

License

MIT