Class: OAuth::TTY::Commands::SignCommand

Inherits:
OAuth::TTY::Command show all
Defined in:
lib/oauth/tty/commands/sign_command.rb

Instance Method Summary collapse

Methods inherited from OAuth::TTY::Command

#initialize, #run

Constructor Details

This class inherits a constructor from OAuth::TTY::Command

Instance Method Details

#_runObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/oauth/tty/commands/sign_command.rb', line 15

def _run
  request = OAuth::RequestProxy.proxy \
    "method" => options[:method],
    "uri" => options[:uri],
    "parameters" => parameters

  puts_verbose_parameters(request) if verbose?

  request.sign! \
    consumer_secret: options[:oauth_consumer_secret],
    token_secret: options[:oauth_token_secret]

  if verbose?
    puts_verbose_request(request)
  else
    puts request.oauth_signature
  end
end

#puts_verbose_parameters(request) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/oauth/tty/commands/sign_command.rb', line 34

def puts_verbose_parameters(request)
  puts "OAuth parameters:"
  request.oauth_parameters.each do |k, v|
    puts "  #{[k, v].join(": ")}"
  end
  puts

  if request.non_oauth_parameters.any?
    puts "Parameters:"
    request.non_oauth_parameters.each do |k, v|
      puts "  #{[k, v].join(": ")}"
    end
    puts
  end
end

#puts_verbose_request(request) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/oauth/tty/commands/sign_command.rb', line 50

def puts_verbose_request(request)
  puts "Method: #{request.method}"
  puts "URI: #{request.uri}"
  puts "Normalized params: #{request.normalized_parameters}" unless options[:xmpp]
  puts "Signature base string: #{request.signature_base_string}"

  if xmpp?
    puts
    puts "XMPP Stanza:"
    puts xmpp_output(request)
    puts
    puts "Note: You may want to use bare JIDs in your URI."
    puts
  else
    puts "OAuth Request URI: #{request.signed_uri}"
    puts "Request URI: #{request.signed_uri(with_oauth: false)}"
    puts "Authorization header: #{request.oauth_header(realm: options[:realm])}"
  end
  puts "Signature:         #{request.oauth_signature}"
  puts "Escaped signature: #{OAuth::Helper.escape(request.oauth_signature)}"
end

#required_optionsObject



11
12
13
# File 'lib/oauth/tty/commands/sign_command.rb', line 11

def required_options
  %i[oauth_consumer_key oauth_consumer_secret oauth_token oauth_token_secret]
end

#xmpp_output(request) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/oauth/tty/commands/sign_command.rb', line 72

def xmpp_output(request)
  <<-EOS
    <oauth xmlns='urn:xmpp:oauth:0'>
      <oauth_consumer_key>#{request.oauth_consumer_key}</oauth_consumer_key>
      <oauth_token>#{request.oauth_token}</oauth_token>
      <oauth_signature_method>#{request.oauth_signature_method}</oauth_signature_method>
      <oauth_signature>#{request.oauth_signature}</oauth_signature>
      <oauth_timestamp>#{request.oauth_timestamp}</oauth_timestamp>
      <oauth_nonce>#{request.oauth_nonce}</oauth_nonce>
      <oauth_version>#{request.oauth_version}</oauth_version>
    </oauth>
  EOS
end