Class: PeatioAPI::Auth
- Inherits:
-
Object
- Object
- PeatioAPI::Auth
- Defined in:
- lib/peatio_api/auth.rb
Instance Method Summary collapse
- #format_params(params) ⇒ Object
-
#initialize(access_key, secret_key) ⇒ Auth
constructor
A new instance of Auth.
- #payload(verb, path, params) ⇒ Object
- #sign(verb, path, params) ⇒ Object
- #signed_challenge(challenge) ⇒ Object
- #signed_params(verb, path, params = {}) ⇒ Object
Constructor Details
#initialize(access_key, secret_key) ⇒ Auth
Returns a new instance of Auth.
4 5 6 7 |
# File 'lib/peatio_api/auth.rb', line 4 def initialize(access_key, secret_key) @access_key = access_key @secret_key = secret_key end |
Instance Method Details
#format_params(params) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/peatio_api/auth.rb', line 28 def format_params(params) params = params.symbolize_keys params[:access_key] ||= @access_key params[:tonce] ||= (Time.now.to_f*1000).to_i params end |
#payload(verb, path, params) ⇒ Object
24 25 26 |
# File 'lib/peatio_api/auth.rb', line 24 def payload(verb, path, params) "#{verb.upcase}|#{path}|#{params}" end |
#sign(verb, path, params) ⇒ Object
20 21 22 |
# File 'lib/peatio_api/auth.rb', line 20 def sign(verb, path, params) OpenSSL::HMAC.hexdigest 'SHA256', @secret_key, payload(verb, path, params) end |
#signed_challenge(challenge) ⇒ Object
9 10 11 12 |
# File 'lib/peatio_api/auth.rb', line 9 def signed_challenge(challenge) signature = OpenSSL::HMAC.hexdigest 'SHA256', @secret_key, "#{@access_key}#{challenge}" {auth: {access_key: @access_key, answer: signature}} end |
#signed_params(verb, path, params = {}) ⇒ Object
14 15 16 17 18 |
# File 'lib/peatio_api/auth.rb', line 14 def signed_params(verb, path, params={}) params = format_params params signature = sign verb, path, URI.unescape(params.to_query) params.merge(signature: signature) end |