Project

relax

0.01
No commit activity in last 3 years
No release in over 3 years
A flexible library for creating web service consumers.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 3.12
~> 2.4

Runtime

~> 2.0
 Project Readme

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.