Class: MrMurano::Account
- Inherits:
-
Object
show all
- Includes:
- Http
- Defined in:
- lib/MrMurano/Account.rb
Constant Summary
collapse
- @@token =
Store the token in a class variable so that we only fetch it once per run session of this tool
nil
Instance Method Summary
collapse
Methods included from Http
#curldebug, #delete, #get, #http, #http_reset, #json_opts, #post, #postf, #put, #set_def_headers, #showHttpError, #tryToPrettyJSON, #workit
Instance Method Details
#_loginInfo ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/MrMurano/Account.rb', line 61
def _loginInfo
host = $cfg['net.host']
user = $cfg['user.name']
if user.nil? then
user = ask("Account name: ")
$cfg.set('user.name', user, :user)
end
pff = $cfg.file_at('passwords', :user)
pf = Passwords.new(pff)
pf.load
pws = pf.get(host, user)
if pws.nil? then
pws = ask("Password: ") { |q| q.echo = "*" }
pf.set(host, user, pws)
pf.save
end
{
:email => $cfg['user.name'],
:password => pws
}
end
|
#businesses ⇒ Object
111
112
113
|
# File 'lib/MrMurano/Account.rb', line 111
def businesses
get('user/' + $cfg['user.name'] + '/membership/')
end
|
#endPoint(path) ⇒ Object
57
58
59
|
# File 'lib/MrMurano/Account.rb', line 57
def endPoint(path)
URI('https://' + $cfg['net.host'] + '/api:1/' + path.to_s)
end
|
#products ⇒ Object
115
116
117
118
|
# File 'lib/MrMurano/Account.rb', line 115
def products
raise "Missing Bussiness ID" if $cfg['business.id'].nil?
get('business/' + $cfg['business.id'] + '/product/')
end
|
#solutions ⇒ Object
120
121
122
123
|
# File 'lib/MrMurano/Account.rb', line 120
def solutions
raise "Missing Bussiness ID" if $cfg['business.id'].nil?
get('business/' + $cfg['business.id'] + '/solution/')
end
|
#token ⇒ Object
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
# File 'lib/MrMurano/Account.rb', line 86
def token
if @@token.nil? then
uri = endPoint('token/')
request = Net::HTTP::Post.new(uri)
request['User-Agent'] = "MrMurano/#{MrMurano::VERSION}"
request.content_type = 'application/json'
curldebug(request)
request.body = JSON.generate(_loginInfo)
response = http.request(request)
case response
when Net::HTTPSuccess
token = JSON.parse(response.body, json_opts)
@@token = token[:token]
else
showHttpError(request, response)
@@token = nil
raise response
end
end
@@token
end
|