Class: Umbreo::Models::Configuration
- Inherits:
-
Object
- Object
- Umbreo::Models::Configuration
- Defined in:
- lib/umbreo/models/configuration.rb
Instance Method Summary collapse
-
#create_configuration ⇒ Object
Create file configuration.
-
#delete ⇒ Object
remove file configuration.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#is_valid_user? ⇒ Boolean
check valid user.
-
#read_file_authentication ⇒ Object
Read file configuration.
-
#write_file_authentication(data, endpoint_url = nil) ⇒ Object
Write authentication to File Configuration.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
5 6 7 |
# File 'lib/umbreo/models/configuration.rb', line 5 def initialize create_configuration end |
Instance Method Details
#create_configuration ⇒ Object
Create file configuration
12 13 14 |
# File 'lib/umbreo/models/configuration.rb', line 12 def create_configuration File.open(FILE_CONFIG, "w+") if !File.exists?(FILE_CONFIG) end |
#delete ⇒ Object
remove file configuration
62 63 64 65 66 |
# File 'lib/umbreo/models/configuration.rb', line 62 def delete File.delete(FILE_CONFIG) if File.exists? FILE_CONFIG return true end |
#is_valid_user? ⇒ Boolean
check valid user
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/umbreo/models/configuration.rb', line 71 def is_valid_user? @parse_file = ParseConfig.new(FILE_CONFIG) rescue nil @user_auth = @parse_file.params["user"] rescue nil if @user_auth.present? email = @user_auth["Email"] apikey = @user_auth["APIKey"] name = @user_auth["Name"] endpoint = @user_auth["Endpoint"] request = Typhoeus.get( "#{endpoint}/api/v1/users/is_valid_user", body: { email: email, apikey: apikey, } ) data = JSON.parse request.response_body return data['success'] else return false end end |
#read_file_authentication ⇒ Object
Read file configuration
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/umbreo/models/configuration.rb', line 45 def read_file_authentication @parse_file = ParseConfig.new(FILE_CONFIG) rescue nil if @parse_file.present? email = @parse_file.params["user"]["Email"] rescue nil apikey = @parse_file.params['user']['APIKey'] rescue nil name = @parse_file.params['user']['Name'] rescue nil endpoint = @parse_file.params["user"]["Endpoint"] rescue nil return { email: email, api_key: apikey, name: name, end_point: endpoint } else return "" end end |
#write_file_authentication(data, endpoint_url = nil) ⇒ Object
Write authentication to File Configuration
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/umbreo/models/configuration.rb', line 19 def write_file_authentication(data, endpoint_url = nil) name = data['name'] || data[:name] email = data['email'] || data[:email] token = data['authentication_token'] || data[:authentication_token] File.open("#{FILE_CONFIG}", 'w+') do |file| file.puts("# Umbreo's user configuration file.") file.puts("") file.puts("[user]") file.puts("Name=#{name}") file.puts("Email=#{email}") file.puts("APIKey=#{token}") if endpoint_url.present? file.puts("Endpoint=#{endpoint_url}") else file.puts("Endpoint=#{SERVER_END_POINT}") end end # Umbreo::Helpers::AlertMessage.show_success_message(read_file_authentication) end |