# encoding: utf-8 # frozen_string_literal: true module Nimbu module Endpoints class Authorizations < Endpoint VALID_AUTH_PARAM_NAMES = ["scopes", "add_scopes", "remove_scopes", "note", "note_url", "client_id", "client_secret",].freeze # List authorizations # # = Examples # nimbu = Nimbu.new :basic_auth => 'login:password' # nimbu.oauth.list # nimbu.oauth.list { |auth| ... } # def list(*args, &block) require_authentication arguments(args) response = get_request("/authorizations", arguments.params) return response unless block_given? response.each(&block) end alias_method :all, :list # Get a single authorization # # = Examples # nimbu = Nimbu.new :basic_auth => 'login:password' # nimbu.oauth.get 'authorization-id' # def get(*args) require_authentication arguments(args, required: [:authorization_id]) get_request("/authorizations/#{authorization_id}", arguments.params) end alias_method :find, :get # Create a new authorization # # = Inputs # * :scopes - Optional array - A list of scopes that this authorization is in. # * :note - Optional string - A note to remind you what the OAuth token is for. # * :note_url - Optional string - A URL to remind you what the OAuth token is for. # # = Examples # nimbu = Nimbu.new :basic_auth => 'login:password' # nimbu.oauth.create # "scopes" => ["public_repo"] # def create(*args) require_authentication arguments(args) do sift(VALID_AUTH_PARAM_NAMES) end post_request("/authorizations", arguments.params) end # Update an existing authorization # # = Inputs # * :scopes - Optional array - A list of scopes that this authorization is in. # * :add_scopes - Optional array - A list of scopes to add to this authorization. # * :remove_scopes - Optional array - A list of scopes to remove from this authorization. # * :note - Optional string - A note to remind you what the OAuth token is for. # * :note_url - Optional string - A URL to remind you what the OAuth token is for. # # = Examples # nimbu = Nimbu.new :basic_auth => 'login:password' # nimbu.oauth.update "authorization-id", "add_scopes" => ["repo"], # def update(*args) require_authentication arguments(args, required: [:authorization_id]) do sift(VALID_AUTH_PARAM_NAMES) end patch_request("/authorizations/#{authorization_id}", arguments.params) end alias_method :edit, :update # Delete an authorization # # = Examples # nimbu.oauth.delete 'authorization-id' # def delete(*args) require_authentication arguments(args, required: [:authorization_id]) delete_request("/authorizations/#{authorization_id}", arguments.params) end alias_method :remove, :delete private def require_authentication raise ArgumentError, "You can only access authentication tokens through Basic Authentication" unless authenticated? end end # Authorizations end # Endpoints end # Nimbu