Method: HaveAPI::ClientExamples::RubyClient#auth

Defined in:
lib/haveapi/client_examples/ruby_client.rb

#auth(method, desc) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/haveapi/client_examples/ruby_client.rb', line 18

def auth(method, desc)
  case method
  when :basic
    <<~END
      #{init}

      client.authenticate(:basic, user: "user", password: "secret")
    END

  when :token
    <<~END
      #{init}

      # Get token using username and password
      client.authenticate(:token, #{auth_token_credentials(desc).map { |k, v| "#{k}: \"#{v}\"" }.join(', ')})

      puts "Token = \#{client.auth.token}"

      # Next time, the client can authenticate using the token directly
      client.authenticate(:token, token: saved_token)
    END

  when :oauth2
    '# OAuth2 is not supported by HaveAPI Ruby client.'
  end
end