superavatar 0.0.2 → 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: 93335ffca2acdaf312d15aec1db6d009d42773a1af730d3332b9583df371f84e
4
- data.tar.gz: dfc75804b85bac862aa8b6feaa3c962acb9f12685aef305122e73c90e1b96f97
3
+ metadata.gz: 6dc131530c91271290b7f4d58bd01c949bc97770ac97ad4b3ae2bab84d18995a
4
+ data.tar.gz: e6f785f6e15fb71fda86b9e93cd014d2b027adb2c98ccf2180dfcf7a738a311c
5
5
  SHA512:
6
- metadata.gz: 5a4bbb246b120a8b5bc173469b326c3d4bf7bf5dc702dbecd6158c759fa950b3927cdd8bfc23e4475cd554784fe31262dfb8547888fe8af6c1ea59447769ac32
7
- data.tar.gz: a99fcb498c2193f994748c31e726b0e47d9b2b917375230428d7204142abe90897be0232aef67ce58b65b9d164e80a284d409fcfe275f536e7acd57e1a2a0167
6
+ metadata.gz: ba6c7e742439231bb147e0a25d071a4135cd82706304df6e24ead879b93a84d9bd3faf0d9c15925470dd245e11f3da052968983588a8ce522ad0e8fb0ed02751
7
+ data.tar.gz: e7315905fa0b6cf8312284a41070d1e69dfb615fe7661d8debbf8176bdeb4408c0f5ebe5822f091780c1fcd213ded4a36509cd9e26b7fbba5f886e93c339fd67
@@ -5,20 +5,22 @@ module Superavatar
5
5
  class Github
6
6
  def initialize(username)
7
7
  @username = username
8
+ @avatar_url = nil
8
9
  end
9
10
 
10
- def avatar_url
11
- res = api_profile
12
- p res
13
- # JSON.parse(res)[:avatar_url]
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")
14
16
  end
15
17
 
16
18
  def web_profile
17
19
  "https://github.com/#{@username}/"
18
20
  end
19
21
 
20
- def api_profile
21
- "https://api.github.com/users/#{@username}/"
22
+ def api_profile_endpoint
23
+ "https://api.github.com/users/#{@username}"
22
24
  end
23
25
  end
24
26
  end
@@ -1,25 +1,31 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Superavatar::APIClient
3
+ # Superavatar::Apiclient
4
4
  #
5
5
  # Fetches external resources
6
6
  #
7
7
  module Superavatar
8
- module APIClient
9
- class Fetch
10
- require 'net/http'
11
- require 'json'
12
- require 'open-uri'
8
+ module Utils
9
+ class Apiclient
10
+ require 'net/http'
11
+ require 'json'
12
+ require 'open-uri'
13
13
 
14
- def self.fetch_external_api(url, json=true)
15
- begin
16
- puts 'Fetching...'
17
- response = URI.open(url).read
18
- response
19
- JSON.parse(response) if json==true
20
- rescue StandardError => e
21
- puts 'Request failed #{e.message}'
22
- end
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
23
29
  end
24
30
  end
25
31
  end
data/lib/superavatar.rb CHANGED
@@ -3,14 +3,9 @@
3
3
  #
4
4
  # Superavatar
5
5
 
6
- #require_relative 'sources/github'
7
- require_relative 'superavatar/sources/github'
8
- require_relative 'superavatar/utils/apiclient'
9
6
  # Provides avatars for your users
10
7
  #
11
8
  module Superavatar
12
- # Tester method
13
- def self.talk
14
- 'Talking init'
15
- end
9
+ require 'superavatar/sources/github'
10
+ require 'superavatar/utils/apiclient'
16
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.2
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-08 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