Sha256: b00e5a0ecaf84a2fa4863cf6d8cfa6a7826fc5b645234f0a5351bf1ff9cb6481

Contents?: true

Size: 899 Bytes

Versions: 6

Compression:

Stored size: 899 Bytes

Contents

class OAuth::CLI
  class QueryCommand < BaseCommand
    extend OAuth::Helper

    def required_options
      %i[oauth_consumer_key oauth_consumer_secret oauth_token oauth_token_secret]
    end

    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 { |k, v| Array(v).map { |v2| "#{OAuth::Helper.escape(k)}=#{OAuth::Helper.escape(v2)}" } * "&" }
      uri.query = [uri.query, *params].reject(&:nil?) * "&"
      puts uri.to_s

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
oauth-0.5.14 lib/oauth/cli/query_command.rb
oauth-0.5.13 lib/oauth/cli/query_command.rb
oauth-0.5.12 lib/oauth/cli/query_command.rb
oauth-0.5.11 lib/oauth/cli/query_command.rb
oauth-0.5.10 lib/oauth/cli/query_command.rb
oauth-0.5.9 lib/oauth/cli/query_command.rb