From d58619fc98aae50dfa480d613beb654133445742 Mon Sep 17 00:00:00 2001 From: Akash Srivastava Date: Fri, 22 Feb 2019 01:14:04 +0530 Subject: [PATCH] Avatar API --- lib/gitlab/client.rb | 1 + lib/gitlab/client/avatar.rb | 21 +++++++++++++++++++++ spec/fixtures/avatar.json | 3 +++ spec/gitlab/client/avatar_spec.rb | 17 +++++++++++++++++ 4 files changed, 42 insertions(+) create mode 100644 lib/gitlab/client/avatar.rb create mode 100644 spec/fixtures/avatar.json create mode 100644 spec/gitlab/client/avatar_spec.rb diff --git a/lib/gitlab/client.rb b/lib/gitlab/client.rb index 06c666dc3..5ad4b005a 100644 --- a/lib/gitlab/client.rb +++ b/lib/gitlab/client.rb @@ -7,6 +7,7 @@ class Client < API # Please keep in alphabetical order include AccessRequests + include Avatar include AwardEmojis include Boards include Branches diff --git a/lib/gitlab/client/avatar.rb b/lib/gitlab/client/avatar.rb new file mode 100644 index 000000000..c0cde0d4a --- /dev/null +++ b/lib/gitlab/client/avatar.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class Gitlab::Client + # Defines methods related to avatar. + # @see https://docs.gitlab.com/ce/api/avatar.html + module Avatar + # Get a single avatar URL for a user with the given email address. + # + # @example + # Gitlab.avatar(email: 'admin@example.com') + # Gitlab.avatar(email: 'admin@example.com', size: 32) + # + # @param [Hash] options A customizable set of options. + # @option options [String] :email(required) Public email address of the user. + # @option options [Integer] :size(optional) Single pixel dimension (since images are squares). Only used for avatar lookups at Gravatar or at the configured Libravatar server. + # @return + def avatar(options = {}) + get('/avatar', query: options) + end + end +end diff --git a/spec/fixtures/avatar.json b/spec/fixtures/avatar.json new file mode 100644 index 000000000..e2ea57c06 --- /dev/null +++ b/spec/fixtures/avatar.json @@ -0,0 +1,3 @@ +{ + "avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=64&d=identicon" +} diff --git a/spec/gitlab/client/avatar_spec.rb b/spec/gitlab/client/avatar_spec.rb new file mode 100644 index 000000000..1b664e4d4 --- /dev/null +++ b/spec/gitlab/client/avatar_spec.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::Client do + describe '.avatar' do + before do + stub_get('/avatar', 'avatar').with(query: { email: 'admin@example.com', size: 32 }) + @avatar = Gitlab.avatar(email: 'admin@example.com', size: 32) + end + + it 'gets the correct resource' do + expect(a_get('/avatar') + .with(query: { email: 'admin@example.com', size: 32 })).to have_been_made + end + end +end