Module: Getauthtoken
- Defined in:
- lib/getauthtoken.rb,
lib/getauthtoken/version.rb
Constant Summary collapse
- AUTH_PATH =
'/api/xcr/v2/xauth'
- VERSION =
"0.5.0"
Class Method Summary collapse
- .authenticate(password) ⇒ Object
- .get_config ⇒ Object
- .pbcopy(token) ⇒ Object
- .post_credentials(config, password) ⇒ Object
Class Method Details
.authenticate(password) ⇒ Object
8 9 10 11 |
# File 'lib/getauthtoken.rb', line 8 def self.authenticate(password) config = get_config() post_credentials(config, password) end |
.get_config ⇒ Object
13 14 15 16 17 18 |
# File 'lib/getauthtoken.rb', line 13 def self.get_config() file = File.open(File.("~/.xaptum_config.json")) data = JSON.load file file.close data end |
.pbcopy(token) ⇒ Object
29 30 31 |
# File 'lib/getauthtoken.rb', line 29 def self.pbcopy(token) IO.popen('pbcopy', 'w') { |f| f << token } end |
.post_credentials(config, password) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/getauthtoken.rb', line 20 def self.post_credentials(config, password) hash = { "username" => config["username"], "token" => password} json = JSON.generate(hash) response = HTTP.headers("Content-Type": "application/json", "Accept": "application/json") .post(config["host"] + AUTH_PATH, body: json) response.code == 200 ? JSON.parse(response)["data"][0]["token"] : nil end |