Class: OAuth::TTY::Commands::QueryCommand — Documentation by YARD 0.9.37

# Class: OAuth::TTY::Commands::QueryCommand

Inherits:
  OAuth::TTY::Command
  - Object
  - OAuth::TTY::Command
  - OAuth::TTY::Commands::QueryCommand
  show all

Extended by:
  Helper

Defined in:
  lib/oauth/tty/commands/query_command.rb

## Instance Method Summary collapse

- #_run ⇒ Object
- #required_options ⇒ Object

### Methods inherited from OAuth::TTY::Command

#initialize, #run

## Constructor Details

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

## Instance Method Details

### #_run ⇒ `Object`

    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/oauth/tty/commands/query_command.rb', line 21

    def _run
      consumer = OAuth::Consumer.new(
        options[:oauth_consumer_key],
        options[:oauth_consumer_secret],
        scheme: options[:scheme],
      )

      access_token = OAuth::AccessToken.new(consumer, options[:oauth_token], options[:oauth_token_secret])

      # append params to the URL
      uri = URI.parse(options[:uri])
      params = parameters.map do |k, v|
        Array(v).map do |v2|
          "#{OAuth::Helper.escape(k)}=#{OAuth::Helper.escape(v2)}"
        end * "&"
      end
      uri.query = [uri.query, *params].compact * "&"
      puts uri

      response = access_token.request(options[:method].to_s.downcase.to_sym, uri.to_s)
      puts "#{response.code} #{response.message}"
      puts response.body
    end

### #required_options ⇒ `Object`

    17
    18
    19
    # File 'lib/oauth/tty/commands/query_command.rb', line 17

    def required_options
      %i[oauth_consumer_key oauth_consumer_secret oauth_token oauth_token_secret]
    end