lib/auth/lh/api.rb in auth-lh-0.0.3 vs lib/auth/lh/api.rb in auth-lh-0.0.4
- old
+ new
@@ -28,10 +28,19 @@
def logout_url
"#{@endpoint}/logout?return=#{CGI::escape(@return_url)}"
end
+ def get_user(code_or_login)
+ User.new(get_request("/api/user/#{code_or_login}"))
+ end
+
+ def get_users(filters={})
+ results = get_request("/api/users", filters)
+ results.map { |r| User.new(r) }
+ end
+
protected
def create_login_attempt
result = post_request '/login_attempts', {
app_code: @application_code,
@@ -40,14 +49,19 @@
LoginAttempt.new(result)
end
def get_request(action, params={})
- JSON.parse(RestClient.get("#{@endpoint}#{action}", {params: params}))
+ response = RestClient.get("#{@endpoint}#{action}", {params: params}.merge(auth_headers))
+ JSON.parse(response.body)
end
def post_request(action, params={})
- JSON.parse(RestClient.post("#{@endpoint}#{action}", params))
+ JSON.parse(RestClient.post("#{@endpoint}#{action}", params, auth_headers))
+ end
+
+ def auth_headers
+ { authorization: "Token token=\"#{@access_token}\"" }
end
end
end
end