Skip to content

Latest commit

 

History

History
136 lines (96 loc) · 3.28 KB

README.md

File metadata and controls

136 lines (96 loc) · 3.28 KB

Designer News Ruby API Client

Travis CI

This is the Ruby client library that wraps the Designer News API. It assumes you have used another oAuth 2 library to obtain and manage a valid access token. It is based on the Ruby gem for the LayerVault API.

Installation

Put this in your Gemfile and smoke it:

gem 'dn'

Or install it:

$ gem install dn

Supported oAuth flows

Currently only Resource Owner Credentials and Client Credentials are supported.

Requesting an Access Token

  1. Please send an email to [email protected] to request your API credentials. Please include your callback URL. One day, this might be automated.
  2. Receive a friendly note back from the LayerVault staff with your application credentials.
  3. Note your client_id and client_secret.
  4. Try the example Access Token request below.
curl -i https://api-news.layervault.com/oauth/token \
  -F grant_type="password" \
  -F username="<username_goes_here>" \
  -F password="<password_goes_here>" \
  -F client_id="<client_id_goes_here>" \
  -F client_secret="<client_secret_goes_here>"
  1. You now have an access token. You can make API requests by calling via CURL like so:
curl -H 'Authorization: Bearer <your access token>' \
  'https://api-news.layervault.com/api/v1/me'

Initializing the Client

You can initialize the client via Environment Variables or by passing configurations options into the client when you create it, like this:

@client = DesignerNews::Client.new({
  access_token: 'your_access_token',
  api_endpoint: 'your_api_endpoint'
})

Or you can also say:

DesignerNews.client.access_token = 'access_token'
DesignerNews.client.api_endpoint = 'api_endpoint'

Environment Variables

# You Designer News API access token
ENV['DESIGNER_NEWS_ACCESS_TOKEN']

# The API Endpoint you wish to target calls against (defaults to https://api-news.layervault.com/api/v1/)
ENV['DESIGNER_NEWS_API_ENDPOINT']

# Defaults to Designer News Ruby Gem #{DesignerNews::VERSION}
ENV['DESIGNER_NEWS_USER_AGENT']

The User Agent

You should set the User agent to include your email address so that in the event your client does something wrong we can contact you.

Making API calls

You should instantiate a DesignerNews::Client object and then make calls from that:

client = DesignerNews::Client.new({
  access_token: 'your_access_token',
  api_endpoint: 'your_api_endpoint'
})

client.story(123)
client.upvote_story(123)

And so on.

Local Development

Coming soon.

Client Methods Summary

User Info

#me

Stories

#story(story_id)
#stories(page_number=1)
#recent_stories(page_number=1)
#search_stories(query)
#upvote_story(story_id)
#reply_to_story(story_id, comment)

Comments

#comment(comment_id)
#upvote_comment(comment_id)
#reply_to_comment(comment_id, comment)

MOTDs

#motd
#upvote_motd
#downvote_motd