File: query_command.rb

package info (click to toggle)
ruby-oauth 0.5.4-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 584 kB
  • sloc: ruby: 4,070; makefile: 4
file content (25 lines) | stat: -rw-r--r-- 910 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class OAuth::CLI
  class QueryCommand < BaseCommand
    extend OAuth::Helper

    def required_options
      [: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 { |x| x.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