Module: Twurl::CLI::AvailableOptions
- Defined in:
- lib/twurl/cli.rb
Instance Method Summary collapse
- #access_token ⇒ Object
- #app_only ⇒ Object
- #base64 ⇒ Object
- #connection_timeout ⇒ Object
- #consumer_key ⇒ Object
- #consumer_secret ⇒ Object
- #data ⇒ Object
- #file ⇒ Object
- #filefield ⇒ Object
- #headers ⇒ Object
- #help ⇒ Object
- #host ⇒ Object
- #json_format ⇒ Object
- #options ⇒ Object
- #proxy ⇒ Object
- #quiet ⇒ Object
- #raw_data ⇒ Object
- #request_method ⇒ Object
- #section(heading, &block) ⇒ Object
- #timeout ⇒ Object
- #token_secret ⇒ Object
- #trace ⇒ Object
- #tutorial ⇒ Object
- #username ⇒ Object
- #version ⇒ Object
Instance Method Details
#access_token ⇒ Object
208 209 210 211 212 |
# File 'lib/twurl/cli.rb', line 208 def access_token on('-a', '--access-token [token]', 'Your access token') do |token| .access_token = token end end |
#app_only ⇒ Object
348 349 350 351 352 |
# File 'lib/twurl/cli.rb', line 348 def app_only on('--bearer', "Use application-only authentication (Bearer Token)") do |app_only| .app_only = true end end |
#base64 ⇒ Object
324 325 326 327 328 |
# File 'lib/twurl/cli.rb', line 324 def base64 on('-b', '--base64', 'Encode the uploaded file as base64 (default: false)') do |base64| .upload['base64'] = base64 end end |
#connection_timeout ⇒ Object
342 343 344 345 346 |
# File 'lib/twurl/cli.rb', line 342 def connection_timeout on('--connection-timeout [sec]', Integer, 'Number of seconds to wait for the connection to open (default: 60)') do |connection_timeout| .connection_timeout = connection_timeout end end |
#consumer_key ⇒ Object
196 197 198 199 200 |
# File 'lib/twurl/cli.rb', line 196 def consumer_key on('-c', '--consumer-key [key]', "Your consumer key (required)") do |key| .consumer_key = key ? key : CLI.prompt_for('Consumer key') end end |
#consumer_secret ⇒ Object
202 203 204 205 206 |
# File 'lib/twurl/cli.rb', line 202 def consumer_secret on('-s', '--consumer-secret [secret]', "Your consumer secret (required)") do |secret| .consumer_secret = secret ? secret : CLI.prompt_for('Consumer secret') end end |
#data ⇒ Object
232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/twurl/cli.rb', line 232 def data on('-d', '--data [data]', 'Sends the specified data in a POST request to the HTTP server.') do |data| if .args.count { |item| /^content-type:\s+application\/json/i.match(item) } > 0 .json_data = true .data = data else CGI.parse(data).each_pair do |key, value| .data[key] = value.first end end end end |
#file ⇒ Object
307 308 309 310 311 312 313 314 315 316 |
# File 'lib/twurl/cli.rb', line 307 def file on('-f', '--file [path_to_file]', 'Specify the path to the file to upload') do |file| if File.file?(file) .upload['file'] << file else CLI.puts "ERROR: File not found" exit end end end |
#filefield ⇒ Object
318 319 320 321 322 |
# File 'lib/twurl/cli.rb', line 318 def filefield on('-F', '--file-field [field_name]', 'Specify the POST parameter name for the file upload data (default: media)') do |filefield| .upload['filefield'] = filefield end end |
#headers ⇒ Object
257 258 259 260 261 262 |
# File 'lib/twurl/cli.rb', line 257 def headers on('-A', '--header [header]', 'Adds the specified header to the request to the HTTP server.') do |header| key, value = header.split(': ') .headers[key] = value end end |
#help ⇒ Object
287 288 289 290 291 292 |
# File 'lib/twurl/cli.rb', line 287 def help on_tail("-h", "--help", "Show this message") do CLI.puts self exit end end |
#host ⇒ Object
264 265 266 267 268 269 270 271 272 273 |
# File 'lib/twurl/cli.rb', line 264 def host on('-H', '--host [host]', 'Specify host to make requests to (default: api.twitter.com)') do |host| if host[PROTOCOL_PATTERN] protocol, protocolless_host = host.split(PROTOCOL_PATTERN, 2) .host = protocolless_host else .host = host end end end |
#json_format ⇒ Object
330 331 332 333 334 |
# File 'lib/twurl/cli.rb', line 330 def json_format on('-j', '--json-pretty', 'Format response body to JSON pretty style') do |json_format| .json_format = true end end |
#options ⇒ Object
178 179 180 |
# File 'lib/twurl/cli.rb', line 178 def Twurl. end |
#proxy ⇒ Object
301 302 303 304 305 |
# File 'lib/twurl/cli.rb', line 301 def proxy on('-P', '--proxy [proxy]', 'Specify HTTP proxy to forward requests to (default: No proxy)') do |proxy| .proxy = proxy end end |
#quiet ⇒ Object
275 276 277 278 279 |
# File 'lib/twurl/cli.rb', line 275 def quiet on('-q', '--quiet', 'Suppress all output (default: output is printed to STDOUT)') do |quiet| .output = StringIO.new end end |
#raw_data ⇒ Object
245 246 247 248 249 250 251 252 253 254 255 |
# File 'lib/twurl/cli.rb', line 245 def raw_data on('-r', '--raw-data [data]', 'Sends the specified data as it is in a POST request to the HTTP server.') do |data| if .raw_data raise Exception, "ERROR: can't specify '-r' option more than once" elsif .args.include?('-d') || .args.include?('--data') raise Exception, "ERROR: can't use '-r' and '-d' options together" end .raw_data = true .data = data end end |
#request_method ⇒ Object
281 282 283 284 285 |
# File 'lib/twurl/cli.rb', line 281 def request_method on('-X', '--request-method [method]', 'Request method (default: GET)') do |request_method| .request_method = request_method.downcase end end |
#section(heading, &block) ⇒ Object
182 183 184 185 186 187 |
# File 'lib/twurl/cli.rb', line 182 def section(heading, &block) separator "" separator heading instance_eval(&block) end |
#timeout ⇒ Object
336 337 338 339 340 |
# File 'lib/twurl/cli.rb', line 336 def timeout on('--timeout [sec]', Integer, 'Number of seconds to wait for the request to be read (default: 60)') do |timeout| .timeout = timeout end end |
#token_secret ⇒ Object
214 215 216 217 218 |
# File 'lib/twurl/cli.rb', line 214 def token_secret on('-S', '--token-secret [secret]', "Your token secret") do |secret| .token_secret = secret end end |
#trace ⇒ Object
226 227 228 229 230 |
# File 'lib/twurl/cli.rb', line 226 def trace on('-t', '--[no-]trace', 'Trace request/response traffic (default: --no-trace)') do |trace| .trace = trace end end |
#tutorial ⇒ Object
189 190 191 192 193 194 |
# File 'lib/twurl/cli.rb', line 189 def tutorial on('-T', '--tutorial', "Narrative overview of how to get started using Twurl") do CLI.puts IO.read(README) exit end end |
#username ⇒ Object
220 221 222 223 224 |
# File 'lib/twurl/cli.rb', line 220 def username on('-u', '--username [username]', 'Username of account to authorize (required)') do |username| .username = username end end |