Sha256: dcc13c4c169b1fb5b40b7c03479cabdb384220b888745e670e7293c6cabea4e6

Contents?: true

Size: 1.12 KB

Versions: 3

Compression:

Stored size: 1.12 KB

Contents

module Nurego
  class Entitlement < APIResource
    include Nurego::APIOperations::List
    include Nurego::APIOperations::Create

    def set_usage(feature_id, amount)
      payload = {
          feature_id: feature_id,
          organization: id,
          amount: amount,
      }
      response, api_key = Nurego.request(:put, "/v1/entitlements/usage", nil, payload)
    end

    def is_allowed(features)
      payload =  {
          :organization => id,
      }

      features = features.is_a?(Array) ? features : [features]
      features_url = structure_sensitive_mimic_to_query(features, 'features')
      response, api_key = Nurego.request(:get, "/v1/entitlements/allowed?#{features_url}",
                                         nil, payload)
      Util.convert_to_nurego_object(response, api_key)
    end

private
      def structure_sensitive_mimic_to_query(array, key)
        prefix = "#{key}[]"
        array.collect do | feature |
          feature.collect do |key, value|
            nk = "#{prefix}[#{key}]"
            "#{CGI.escape(nk)}=#{CGI.escape(value.to_s)}"
          end.sort * '&'
        end.join '&'
      end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
nurego-1.1.17 lib/nurego/entitlement.rb
nurego-1.1.16 lib/nurego/entitlement.rb
nurego-1.1.15 lib/nurego/entitlement.rb