Coder Social home page Coder Social logo

ubw-client's Introduction

Ubw::Client

A Ruby client for the UBW REST API. Note that the API is currently readonly.

The goal of this gem is to provide a Ruby-ish wrapper for the UBW API.

Installation

Add this line to your application's Gemfile:

gem 'ubw-client', '~> 0.1', git: 'https://github.com/sanger/ubw-client.git'

And then execute:

$ bundle

Usage

Configuration example:

# The site must be set before using the gem, as it is the base URL for all API calls.
#
# By default ENV['UBW_SITE'] is used but it can be set like so
Ubw::Client.site = 'https://ubw.sanger.ac.uk' 

# A Faraday::Connection can be obtained and configured before use (perhaps to disable a proxy)
Ubw::Client.connection do |connection|
  connection.proxy {}
  connection.use SomeCustomMiddleware
end

Getting started:

# Fetch a SubProject
Ubw::SubProject.find('S0001-001')
# => #<Ubw::SubProject sub_cost_code="S0001-001", cost_code="S0001", status="N", is_active?=true>

# Fetch all SubProjects
Ubw::SubProject.all
# => #<Ubw::ResultSet:0x000032fd23ad42 @result_count=10, @items=[#<Ubw::SubProject sub_cost_code="S0001-001", cost_code="S0001", status="N", is_active?=true>, ...]

# Find all Prices where module_name is 'WGS' or 'Library Prep' and cost_code is 'S0001'
# Note that the values here can either be a String or an Array
Ubw::Price.where(module_name: ['WGS', 'Library Prep'], cost_code: 'S0001')
# => #<Ubw::ResultSet:0x0001972ae1df28 @result_count=2, @items=[#<Ubw::Price module_name="WGS", cost_code="S0001", unit_price="9.99">, ...]

Resources

There are currently only two resources: Ubw::SubProject and Ubw::Price.

Ubw::SubProject can be looked up by sub_cost_code e.g. Ubw::SubProject.find(sub_cost_code)

Both also include where and all class methods.

Ubw::ResultSet

Result Sets represent a collection of resources e.g. a list of Ubw::Prices. #result_count will give the size of the collection:

Ubw::Price.find(module_name: 'WGS').result_count
# => 3

They are also enumerable, allowing you iterate through #items. e.g.

# Are there any SubProjects that have cost_codes that don't start with 'S'?
Ubw::SubProject.all.any? { |sub_project| sub_project.cost_code[0] != 'S' }
# => false

Development

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

License

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

ubw-client's People

Contributors

jbeast avatar

Watchers

 avatar  avatar

Forkers

sanger-archive

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.