• Stars
    star
    224
  • Rank 177,792 (Top 4 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 9 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐Ÿ’Ž Ruby wrapper for the Unsplash API.

unsplash_rb

Build Status Coverage Status

A ruby client for the Unsplash API.

Installation

Add this line to your application's Gemfile:

gem 'unsplash'

And then execute:

$ bundle

Or install it yourself as:

$ gem install unsplash

Usage

Configuration

Before making requests, you must configure the gem with your application ID and secret. If you are using Rails, you can do this in an initializer.

Unsplash.configure do |config|
  config.application_access_key = "YOUR ACCESS KEY"
  config.application_secret = "YOUR APPLICATION SECRET"
  config.application_redirect_uri = "https://your-application.com/oauth/callback"
  config.utm_source = "alices_terrific_client_app"

  # optional:
  config.logger = MyCustomLogger.new
end

API Guidelines

All API applications must abide by the API Guidelines.

As part of the API guidelines, all API uses are required to use utm links when providing credit to photographers and Unsplash. Set the config.utm_source to your app's name to automatically append the utm source.

Public-scope actions

If you are only making public requests (i.e. nothing requiring a specific logged-in user, for example liking photos or accessing private user details), then you're ready to go!

Looking for details of a specific photo? Find it by ID:

photo = Unsplash::Photo.find("tAKXap853rY")

Want a bunch of pictures of cats? You're on the internet; of course you do.

search_results = Unsplash::Photo.search("cats")

For a complete list of available actions, see our documentation details.

User Authorization

For non-public actions, you'll have to get the user's permission to access their data. Direct them to the Unsplash authorization URL:

requested_scopes = ["public", "read_user", "something_else_you_are_asking_for"]
auth_url = Unsplash::Client.connection.authorization_url(requested_scopes)

Upon authorization, Unsplash will return to you an authentication code via your OAuth callback handler. With that you can generate an access token:

Unsplash::Client.connection.authorize!("the authentication code")

And that's it. The API actions will be available to you according to whichever permission scopes you requested and the user authorized.

Hotlinking

Hotlinking the Unsplash image files is required

Unlike most APIs, Unsplash requires for the image URLs returned by the API to be directly used or embedded in your applications (generally referred to as hotlinking). By using the CDN and embedding the photo URLs in your application, Unsplash can better track photo views and pass those stats on to the photographer, providing them with context for how popular their photo is and how it's being used.

Track Download

Do you want to trigger track download attribution on a photo ?

photo = Unsplash::Photo.find("tAKXap853rY")
photo.track_download

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake rspec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/unsplash/unsplash_rb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

More Repositories

1

react-trend

๐Ÿ“ˆ Simple, elegant spark lines
JavaScript
2,480
star
2

datasets

๐ŸŽ 4,800,000+ Unsplash images made available for research and machine learning
Jupyter Notebook
2,224
star
3

unsplash-js

๐Ÿค– Official JavaScript wrapper for the Unsplash API
TypeScript
2,027
star
4

unsplash-php

๐Ÿ‘ป Official PHP wrapper for the Unsplash API
PHP
408
star
5

unsplash-photopicker-ios

๐Ÿ“ฑAn iOS photo picker to search and download photos from Unsplash.
Swift
390
star
6

unsplash-photopicker-android

๐Ÿ“ฑAn Android photo picker to search and download photos from Unsplash.
Kotlin
327
star
7

unsplash-source-js

๐Ÿฎ A javascript wrapper for the Unsplash Source API
JavaScript
176
star
8

comment-on-pr

A GitHub Action to comment on the relevant open PR when a commit is pushed.
Ruby
146
star
9

swiftui-lazycollectionview

A modest attempt to port UICollectionView to SwiftUI.
Swift
136
star
10

react-progressive-enhancement

A handy collection of HOCs for universally renderedย apps
TypeScript
63
star
11

intlc

Compile ICU messages into code. Supports TypeScript and JSX. No runtime.
Haskell
51
star
12

uploader-prototype

An open-source prototype of the Unsplash uploader.
TypeScript
45
star
13

sum-types

Safe, ergonomic, non-generic sum types in TypeScript.
TypeScript
41
star
14

url-transformers

Small helper library for manipulating URL strings in Node and in the browser.
TypeScript
35
star
15

ts-imgix

Strongly-typed imgix URL builder function, `buildImgixUrl`.
TypeScript
32
star
16

ts-namespace-import-plugin

Auto import common namespaces in your modules
TypeScript
30
star
17

pipe-ts

TypeScript
30
star
18

request-frp

`request-frp` is a package that provides pure wrappers around `fetch` and `XMLHttpRequest`.
TypeScript
14
star
19

ts-redux-finite-state-machine-example

TypeScript
13
star
20

tinplate

โญ๏ธ TinEye API wrapper
Ruby
13
star
21

responsive-image-test

TypeScript
12
star
22

unsplash-imageview-ios

A UIImageView subclass that displays a random photo from Unsplash.
Swift
9
star
23

imagga-auto-tag

๐ŸŽฉ Ruby client for fetching tags from the Imagga Auto Tagging API
Ruby
8
star
24

sum-types-fast-check

fast-check bindings for @unsplash/sum-types.
TypeScript
3
star
25

swift-storyboard-identifiers

A script that generates identifiers strings from .storyboard files.
Ruby
2
star
26

service-dash

๐Ÿ”ฅ Is anything on fire?
Ruby
2
star
27

mercury

The guide of souls to the underworld.
Rust
2
star
28

imgix-trackable

๐Ÿ›ฐ Tracklable Imgix URLs via the ixid param
TypeScript
2
star
29

sum-types-io-ts

io-ts bindings for @unsplash/sum-types.
TypeScript
2
star
30

ts-type-tests-example

TypeScript
2
star
31

import-sort-style-unsplash

TypeScript
2
star
32

sum-types-fp-ts

fp-ts bindings for @unsplash/sum-types.
TypeScript
2
star
33

translations-connector-test

1
star