ManageIQ::API::Common

Build Status Maintainability Test Coverage Security

Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file lib/shared/micro/utilities. To experiment with that code, run bin/console for an interactive prompt.

TODO: Delete this and the text above, and describe your gem

Installation

Add this line to your application's Gemfile:

gem 'manageiq-api-common'

And then execute:

$ bundle

Or install it yourself as:

$ gem install manageiq-api-common

Usage

ManageIQ::Api::Common::Filter

Supported Comparators Comparator
Integer eq
gt
gte
lt
lte
nil
not_nil
String eq
contains
starts_with
ends_with
nil
not_nil
String (case insensitive) eq_i
contains_i
starts_with_i
ends_with_i

After implementing filtering in your application, this is the way to filter via parameters on index functions:

Query Parameter Ruby Client Parameter
GraphQL filter: Parameter
"?filter[name]=reviews" {:filter => { :name => "reviews" }}
filter: { name: "reviews" }
"?filter[name][eq]=reviews" {:filter => { :name => { :eq => "reviews" } }}
filter: { name: { eq: "reviews" } }
"?filter[name][starts_with]=a" {:filter => { :name => { :starts_with => "a" } }}
filter: { name: { starts_with: "a" } }
"?filter[name][ends_with]=manager" {:filter => { :name => { :ends_with => "manager" } }}
filter: { name: { ends_with: "manager" } }
"?filter[name][contains]=openshift" {:filter => { :name => { :contains => "openshift" } }}
filter: { name: { contains: "openshift" } }
"?filter[id]=5" {:filter => { :id => "5" }}
filter: { id: "5" }
"?filter[id][eq]=5" {:filter => { :id => { :eq => "5" }}}
filter: { id: { eq: "5" } }
"?filter[id][gt]=180" {:filter => { :id => { :gt => "180" }}}
filter: { id: { gt: "180" } }
"?filter[id][gte]=190" {:filter => { :id => { :gte => "190" }}}
filter: { id: { gte: "190" } }
"?filter[id][lt]=5" {:filter => { :id => { :lt => "5" }}}
filter: { id: { lt: "5" } }
"?filter[id][lte]=5" {:filter => { :id => { :lte => "5" }}}
filter: { id: { lte: "5" } }
"?filter[id][]=5&filter[id][]=10&filter[id][]=15&filter[id][]=20" {:filter => { :id => ["5", "10", "15", "20"]}}
filter: { id: ["5", "10", "15", "20"] }
"?filter[id][eq][]=5&filter[id][eq][]=10&filter[id][eq][]=15&filter[id][eq][]=20" {:filter => { :id => { :eq => ["5", "10", "15", "20"]}}}
filter: { id: { eq: ["5", "10", "15", "20"] }

Sorting Results

Sorting query results is controlled via the sort_by query parameter. The sort_by parameter is available for both REST API and GraphQL requests.

The syntax for the sort_by parameter supports:

  • a single string representing the attribute name to sort by which may be followed by :asc or :desc
    • attribute (default order is ascending)
    • attribute:asc (ascending order)
    • attribute:desc (descending order)
  • an array of strings of the above syntax
Sort_by Examples:
  • GET /api/v1.0/sources?sort_by=name
  • GET /api/v1.0/vms?sort_by[]=power_state&sort_by[]=memory:desc
Query Parameter Ruby Client Parameter GraphQL Parameter
"?sort_by=name" { :sort_by => "name" } sort_by: "name"
"?sort_by[]=power_state&sort_by[]=memory:desc" { :sort_by => ["power_state", "memory:desc"] } sort_by: ["power_state, "memory:desc"]

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec 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. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/shared-micro-utilities. 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

This project is available as open source under the terms of the Apache License 2.0.