Class: LearnTest::GithubInteractor

Inherits:
Object
  • Object
show all
Defined in:
lib/learn_test/github_interactor.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username) ⇒ GithubInteractor

Returns a new instance of GithubInteractor.



11
12
13
# File 'lib/learn_test/github_interactor.rb', line 11

def initialize(username)
  @username = username
end

Instance Attribute Details

#user_idObject (readonly)

Returns the value of attribute user_id.



5
6
7
# File 'lib/learn_test/github_interactor.rb', line 5

def user_id
  @user_id
end

#usernameObject (readonly)

Returns the value of attribute username.



5
6
7
# File 'lib/learn_test/github_interactor.rb', line 5

def username
  @username
end

Class Method Details

.get_user_id_for(username) ⇒ Object



7
8
9
# File 'lib/learn_test/github_interactor.rb', line 7

def self.get_user_id_for(username)
  new(username).get_user_id
end

Instance Method Details

#get_user_idObject



15
16
17
18
19
20
# File 'lib/learn_test/github_interactor.rb', line 15

def get_user_id
  @user_id ||= Oj.load(
    open("https://api.github.com/users/#{username}").read,
    symbol_keys: true
  )[:id]
end