Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

insights-api-common

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

insights-api-common

  • 5.0.7
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Insights::API::Common

Build Status Maintainability Test Coverage Security

Header, Encryption, RBAC, Serialization, Pagination and other common behavior for Insights microservices built with Rails

Installation

Add this line to your application's Gemfile:

gem 'insights-api-common'

And then execute:

$ bundle

Or install it yourself as:

$ gem install insights-api-common

Usage

Insights::Api::Common::Filter
Supported ComparatorsComparator
Integereq
not_eq
gt
gte
lt
lte
nil
not_nil
Stringeq
not_eq
contains
starts_with
ends_with
nil
not_nil
String (case insensitive)eq_i
not_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 ParameterRuby Client ParameterGraphQL Parameter
"?filter[name]=reviews"{ :filter => { :name => "reviews" } }filter: { name: "reviews" }
"?filter[name][eq]=reviews"{ :filter => { :name => { :eq => "reviews" } } }filter: { name: { eq: "reviews" } }
"?filter[name][not_eq]=reviews"{ :filter => { :name => { :not_eq => "reviews" } } }filter: { name: { not_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 sort_by parameter specifies which attribute name to sort the results by, and may include a sort order of ascending asc or descending desc. The default behavior when no sorting order is specified is to sort by ascending order.

The syntax for the sort_by parameter is as follows:

  • One or more object keys representing the attribute name(s) to sort by which may be assigned the asc or desc value for the sort order.

    • [attribute] (default order is ascending)
    • [attribute]=asc (ascending order)
    • [attribute]=desc (descending order)
Sort_by Examples:
  • GET /api/v2.0/sources?sort_by[name]
  • GET /api/v2.0/vms?sort_by[power_state]&sort_by[memory]=desc
Query ParameterRuby Client ParameterGraphQL Parameter
"?sort_by[name]"{ :sort_by => { :name => nil } }sort_by: { name: null }
"?sort_by[name]=asc"{ :sort_by => { :name => "asc" } }sort_by: { name: "asc" }
"?sort_by[power_state]&sort_by[memory]=desc"{ :sort_by => { :power_state => nil, :memory => "desc" } }sort_by: { power_state: null, memory: "desc" }
Filtering and Sorting by Association attribute

Requests can also be filtered by assocation attribute and sorted by association attribute and count in addition to the direct attribute specified as in the above examples.

Single level association can be specified as follows:

Filter by association attribute:
Query ParameterRuby Client ParameterGraphQL Parameter
"?filter[association][name]=reviews"{ :filter => { :association => { :name => "reviews" } } }filter: { association: { name: "reviews" } }
"?filter[association][name][eq]=reviews"{ :filter => { :association => { :name => { :eq => "reviews" } } } }filter: { association: { name: { eq: "reviews" } } }
Sort by association attributes and count:

The sort_by parameter can also be used to choose to sort by attributes of association objects as well as sorting by the count of association records by specifying the __count special attribute as follows:

Query ParameterRuby Client ParameterGraphQL Parameter
"?sort_by[association][name]"{ :sort_by => { :association => { :name => nil } } }sort_by: { association: { name: null } }
"?sort_by[association][name]=desc"{ :sort_by => { :association => { :name => "desc" } } }sort_by: { association: { name: "desc" } }
"?sort_by[association][__count]=asc"{ :sort_by => { :association => { :__count => "asc" } } }sort_by: { association: { __count: "asc" } }
Combined Filtering and Sorting example:
Query ParameterRuby Client ParameterGraphQL Parameter
"?filter[name][starts_with]=sample_&sort_by[application_types][__count]=desc&sort_by[name]=asc"{ :filter => { :name => { :starts_with => "sample_" } }, :sort_by => { :application_types => { :__count => "desc" }, :name => "asc" } }filter: { name: { starts_with: "sample_" } }, sort_by: { application_types: { __count: "desc" }, name: "asc" }

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/RedHatInsights/insights-api-common-rails. 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.

FAQs

Package last updated on 07 Oct 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc