superavatar 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d72781a53f5b3a3a437e909cbc1a015e4bae499bb17ef53fb3e5b63aae30ed75
4
- data.tar.gz: b13530ba7c113f2017a9c69f8b1acef3d25730667321fbea538ad5e38e6125f1
3
+ metadata.gz: 6dc131530c91271290b7f4d58bd01c949bc97770ac97ad4b3ae2bab84d18995a
4
+ data.tar.gz: e6f785f6e15fb71fda86b9e93cd014d2b027adb2c98ccf2180dfcf7a738a311c
5
5
  SHA512:
6
- metadata.gz: 93fbe223554901e27270b1b488691b0a93deb6afb75cd905f29d643c81e0d024ec2c1636e0b22981214a60a06c1206fbbcf63658fd295f57285616772c3e8e67
7
- data.tar.gz: be71cf45fef1eabcc95016d88a06fc26f8a85dfb32a913175c3a0483d3419ee18082e2659636fde9732887f1d4e1ce2fccfc5306fcdb7524f9250d6e7ad45599
6
+ metadata.gz: ba6c7e742439231bb147e0a25d071a4135cd82706304df6e24ead879b93a84d9bd3faf0d9c15925470dd245e11f3da052968983588a8ce522ad0e8fb0ed02751
7
+ data.tar.gz: e7315905fa0b6cf8312284a41070d1e69dfb615fe7661d8debbf8176bdeb4408c0f5ebe5822f091780c1fcd213ded4a36509cd9e26b7fbba5f886e93c339fd67
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Superavatar
4
+ module Sources
5
+ class Github
6
+ def initialize(username)
7
+ @username = username
8
+ @avatar_url = nil
9
+ end
10
+
11
+ def get_avatar_url
12
+ return @avatar_url if !@avatar_url.nil?
13
+ url = api_profile_endpoint
14
+ github_res = Superavatar::Utils::Apiclient.fetch_external_api(url)
15
+ @avatar_url = github_res.fetch("avatar_url")
16
+ end
17
+
18
+ def web_profile
19
+ "https://github.com/#{@username}/"
20
+ end
21
+
22
+ def api_profile_endpoint
23
+ "https://api.github.com/users/#{@username}"
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Superavatar::Apiclient
4
+ #
5
+ # Fetches external resources
6
+ #
7
+ module Superavatar
8
+ module Utils
9
+ class Apiclient
10
+ require 'net/http'
11
+ require 'json'
12
+ require 'open-uri'
13
+
14
+ def self.test_me
15
+ puts "Testing from APIClient::Fetch"
16
+ end
17
+
18
+ def self.fetch_external_api(url, json=true)
19
+ begin
20
+ puts 'Fetching from...'
21
+ puts url
22
+ response = URI.open(url).read
23
+ response
24
+ JSON.parse(response) if json==true
25
+ rescue StandardError => e
26
+ puts "Request failed #{e.message}"
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
data/lib/superavatar.rb CHANGED
@@ -3,13 +3,9 @@
3
3
  #
4
4
  # Superavatar
5
5
 
6
- require_relative 'sources/github'
7
-
8
6
  # Provides avatars for your users
9
7
  #
10
8
  module Superavatar
11
- # Tester method
12
- def self.talk
13
- 'Talking init'
14
- end
9
+ require 'superavatar/sources/github'
10
+ require 'superavatar/utils/apiclient'
15
11
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: superavatar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Arce
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-07 00:00:00.000000000 Z
11
+ date: 2023-04-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A gem to get your users' backup avatar from public resources
14
14
  email: martin.arce.teixeira@gmail.com
@@ -17,6 +17,8 @@ extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
19
  - lib/superavatar.rb
20
+ - lib/superavatar/sources/github.rb
21
+ - lib/superavatar/utils/apiclient.rb
20
22
  homepage: https://github.com/divagueame/superavatar
21
23
  licenses:
22
24
  - MIT