Merge remote-tracking branch 'origin/master' into exercise-anomaly-detection

# Conflicts:
#	db/schema.rb
This commit is contained in:
Maximilian Grundke
2017-12-13 13:15:29 +01:00
95 changed files with 526 additions and 397 deletions

View File

@ -1,59 +0,0 @@
class Xikolo::Client
def self.get_user(user_id)
params = {:user_id => user_id}
response = get_request(user_profile_url(user_id), params)
if response
return JSON.parse(response)
else
return nil
end
end
def self.user_profile_url(user_id)
return url + 'v2/users/' + user_id
end
def self.post_request(url, params)
begin
return RestClient.post url, params, http_header
rescue
return nil
end
end
def self.get_request(url, params)
begin
return RestClient.get url, {:params => params}.merge(http_header)
rescue
return nil
end
end
def self.http_header
return {:accept => accept, :authorization => token}
end
def self.url
@url ||= CodeOcean::Config.new(:code_ocean).read.fetch(:xikolo_api_url, 'http://localhost:3000/api/') #caches this with ||=, second value of fetch is default value
end
def self.accept
'application/vnd.xikolo.v1, application/vnd.api+json, application/json'
end
def self.token
'Token token='+Rails.application.secrets.openhpi_api_token#+'"'
end
private
def authenticate_with_user
params = {:email => "admin@openhpi.de", :password => "admin"}
response = post_request(authentication_url, params)
@token = 'Token token="'+JSON.parse(response)['token']+'"'
end
def self.authentication_url
return @url + 'authenticate'
end
end

View File

@ -1,15 +0,0 @@
class Xikolo::UserClient
def self.get(user_id)
user = Xikolo::Client.get_user(user_id)
# return default values if user is not found or if there is a server issue:
if user
name = user.dig('data', 'attributes', 'name') || "User " + user_id
user_visual = user.dig('data', 'attributes', 'avatar_url') || ActionController::Base.helpers.image_path('default.png')
language = user.dig('data', 'attributes', 'language') || "DE"
return {display_name: name, user_visual: user_visual, language: language}
else
return {display_name: "User " + user_id, user_visual: ActionController::Base.helpers.image_path('default.png'), language: "DE"}
end
end
end