Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A library of simple modules for building web service wrappers.

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 examples
Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .rspec
Octocat-spinner-32 .travis.yml
Octocat-spinner-32 CHANGELOG.md
Octocat-spinner-32 Gemfile
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.md
Octocat-spinner-32 Rakefile
Octocat-spinner-32 relax.gemspec
README.md

Relax

Build Status

A library of simple modules for building web service wrappers.

Usage

Relax a toolkit of sorts, which makes it easier to write Faraday-based API Gems while still leaning heavily on the strengths of the Ruby language.

Overview

Relax is made up of three primary modules:

  • Relax::Client — forms the basis of a web service wrapper by storing the configuration and serving as a factory for resources

  • Relax::Resource — used to handle the actual web service connections and help organize related endpoints

  • Relax::Delegator — delegates class methods to an instance of the client allowing for simple client usage

It also includes a basic configuration class, Relax::Config, which defines some of client defaults and can used as the basis for your own custom configuration classes.

Example

require 'relax'
require 'faraday_middleware' # for JSON response parsing

module Vimeo
  extend Relax::Delegator[:client]

  class Client
    include Relax::Client

    def initialize
      config.base_uri = 'http://vimeo.com/api/v2'
    end

    def user(username)
      Resources::User.new(self, username: username)
    end
  end

  module Resource
    include Relax::Resource

    def connection
      super { |builder| builder.response(:json) }
    end
  end

  module Resources
    class User
      include Resource

      def videos
        get("#{@options[:username]}/videos.json").body
      end
    end
  end

  def self.client
    @client ||= Client.new
  end
end

Vimeo.user(ENV['VIMEO_USERNAME']).videos

See the examples directory for more.

Contributing

  1. Fork it.
  2. Create your feature branch (git checkout -b my-new-feature).
  3. Commit your changes (git commit -am 'Add some feature.').
  4. Push to the branch (git push origin my-new-feature).
  5. Create a new Pull Request.
Something went wrong with that request. Please try again.