Class: Holistics::AuthApiClient
- Inherits:
-
Object
- Object
- Holistics::AuthApiClient
- Defined in:
- lib/holistics/auth_api_client.rb
Instance Method Summary collapse
- #auth_info ⇒ Object
- #authenticate(token) ⇒ Object
- #login(token) ⇒ Object
- #write_token_to_gconfig(token) ⇒ Object
Instance Method Details
#auth_info ⇒ Object
7 8 9 |
# File 'lib/holistics/auth_api_client.rb', line 7 def auth_info @auth_info ||= Helpers::AuthInfo.new end |
#authenticate(token) ⇒ Object
27 28 29 30 31 |
# File 'lib/holistics/auth_api_client.rb', line 27 def authenticate(token) url = auth_info.api_url_for('users/info.json', {}) response = Helpers::HttpRequest.new.simple_get url, token return response, (response.code == 200) end |
#login(token) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/holistics/auth_api_client.rb', line 11 def login token puts 'Logging in...' response, ok = authenticate(token) if ok parsed = JSON.parse(response.body) puts 'Authentication successful. Info:' puts "- ID: #{parsed['id']}" puts "- Email: #{parsed['email']}" write_token_to_gconfig(token) else puts 'Error logging in. Please check your token again.' puts response end end |
#write_token_to_gconfig(token) ⇒ Object
33 34 35 36 37 |
# File 'lib/holistics/auth_api_client.rb', line 33 def write_token_to_gconfig(token) file_path = File.join(ENV['HOME'], '.holistics.yml') h = {'token' => token} File.write(file_path, h.to_yaml) end |