Class: Obtenir::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/obtenir/application.rb

Instance Method Summary collapse

Instance Method Details

#get_user_detailsObject



9
10
11
12
13
# File 'lib/obtenir/application.rb', line 9

def get_user_details
  @response = APIRequest.fetch(@username)
  get_username if @response.message == 'Not Found'
  process_response
end

#get_usernameObject



3
4
5
6
7
# File 'lib/obtenir/application.rb', line 3

def get_username
  print "Please enter a valid github username: ".colorize(:yellow)
  @username = gets.strip
  get_user_details
end

#process_responseObject



15
16
17
18
19
20
21
22
23
# File 'lib/obtenir/application.rb', line 15

def process_response
  puts "Would you like to save the response?(y/n): ".colorize(:yellow)
  reply = gets.downcase.strip
  return if reply == 'n'
  puts "Where would you like to save this response?".colorize(:yellow)
  puts "Enter [1] for File, [2] for Database and any other character to exit".colorize(:yellow)
  decision = gets.strip.to_i
  save_github_user(decision)
end

#save_github_user(decision) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/obtenir/application.rb', line 25

def save_github_user(decision)
  case decision
    when 1 then save_to_file
    when 2 then save_to_database
    else
      puts "Goodbye!".colorize(:red)
  end
end

#save_to_databaseObject



44
45
46
47
48
49
50
51
# File 'lib/obtenir/application.rb', line 44

def save_to_database
  puts "Before you proceed, start a mongodb instance by running *mongod* or *sudo mongod* in another terminal".colorize(:red)
  puts "please enter mongodb database name: ".colorize(:yellow)
  database = gets.strip.downcase
  if Database.new(database, @response).save?
    puts "Response saved in database: #{database.capitalize} successfully.".colorize(:green)
  end
end

#save_to_fileObject



34
35
36
37
38
39
40
41
42
# File 'lib/obtenir/application.rb', line 34

def save_to_file
  puts "Please provide the absolute path to the file where the response will be saved".colorize(:yellow)
  file_path = gets.strip
  if FileOperations.new(file_path, @response).save?
    puts "Response saved successfully. You can view it here: #{file_path}".colorize(:green)
  else
    puts "Directory does not exist".colorize(:red)
  end
end