Skip to content

Commit

Permalink
Merge pull request Shopify#11 from Shopify/list_applications_for_user
Browse files Browse the repository at this point in the history
List applications for user
  • Loading branch information
fresh-eggs authored Sep 10, 2018
2 parents 8eec7cf + 3236c44 commit 7566c7c
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# http://shopify.github.io/ruby-style-guide/

AllCops:
TargetRubyVersion: 2.1
TargetRubyVersion: 2.2

Rails:
Enabled: false
Expand All @@ -22,7 +22,7 @@ Style/AlignParameters:
Style/FirstParameterIndentation:
EnforcedStyle: consistent

Style/TrailingCommaInLiteral:
Style/Style/TrailingCommaInArrayLiteral:
Enabled: false

Style/SignalException:
Expand Down
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
sudo: false
before_install: gem install bundler
rvm:
- '2.1'
- '2.2'
- '2.3.1'

11 changes: 4 additions & 7 deletions lib/oktakit/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,7 @@ def initialize(token:, organization: nil, api_endpoint: nil)
end

def api_endpoint
if @api_endpoint
@api_endpoint
else
"https://#{@organization.downcase}.okta.com/api/v1"
end
@api_endpoint || "https://#{@organization.downcase}.okta.com/api/v1"
end

# Make a HTTP GET request
Expand Down Expand Up @@ -182,7 +178,7 @@ def request(method, path, data:, query:, headers:, accept:, content_type:, pagin
end

def sawyer_agent
@agent ||= Sawyer::Agent.new(api_endpoint, sawyer_options) do |http|
@sawyer_agent ||= Sawyer::Agent.new(api_endpoint, sawyer_options) do |http|
http.headers[:accept] = 'application/json'
http.headers[:content_type] = 'application/json'
http.headers[:user_agent] = "Oktakit v#{Oktakit::VERSION}"
Expand All @@ -193,12 +189,13 @@ def sawyer_agent
def sawyer_options
{
links_parser: Sawyer::LinkParsers::Simple.new,
faraday: Faraday.new(builder: MIDDLEWARE),
faraday: Faraday.new(builder: MIDDLEWARE)
}
end

def absolute_to_relative_url(next_ref)
return unless next_ref

next_ref.href.sub(api_endpoint, '')
end
end
Expand Down
16 changes: 16 additions & 0 deletions lib/oktakit/client/apps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,22 @@ def list_users_assigned_to_application(id, options = {})
get("/apps/#{id}/users", options)
end

# List Applications Assigned to User
#
# @params user_id [string] User ID
# @param options[:query] [Hash] Optional. Query params for request
# @param options[:headers] [Hash] Optional. Header params for the request.
# @param options[:accept] [String] Optional. The content type to accept. Default application/json
# @param options[:content_type] [String] Optional. The content type for the request. Default application/json
# @param options [Hash] Optional. Body params for request.
# @return [Array<Sawyer::Resource>] Array of Applications Assigned to User
# @see https://developer.okta.com/docs/api/resources/apps#list-applications-assigned-to-user
# @example
# Oktakit.list_applications_assigned_to_user('<user_id>')
def list_applications_assigned_to_user(user_id, options = {})
get("/apps?filter=user.id+eq+\"#{user_id}\"&expand=user/#{user_id}", options)
end

# Update Application Credentials for Assigned User
#
# @params app_id [string] Application ID
Expand Down
4 changes: 2 additions & 2 deletions oktakit.gemspec
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
lib = File.expand_path('../lib', __FILE__)
lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'oktakit/version'

Expand All @@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']

spec.required_ruby_version = '>= 2.0'
spec.required_ruby_version = '>= 2.2'

spec.add_dependency 'sawyer', '~> 0.8.1'
spec.add_development_dependency 'bundler'
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def serializable_body(*)
end
end

$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
$LOAD_PATH.unshift File.expand_path('../lib', __dir__)
require 'oktakit'

module TestClient
Expand Down

0 comments on commit 7566c7c

Please sign in to comment.