Module: Twurl::CLI::AvailableOptions

Defined in:
lib/twurl/cli.rb

Instance Method Summary collapse

Instance Method Details

#access_tokenObject



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|
    options.access_token = token
  end
end

#app_onlyObject



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|
    options.app_only = true
  end
end

#base64Object



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|
    options.upload['base64'] = base64
  end
end

#connection_timeoutObject



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|
    options.connection_timeout = connection_timeout
  end
end

#consumer_keyObject



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|
    options.consumer_key = key ? key : CLI.prompt_for('Consumer key')
  end
end

#consumer_secretObject



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|
    options.consumer_secret = secret ? secret : CLI.prompt_for('Consumer secret')
  end
end

#dataObject



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 options.args.count { |item| /^content-type:\s+application\/json/i.match(item) } > 0
      options.json_data = true
      options.data = data
    else
      CGI.parse(data).each_pair do |key, value|
        options.data[key] = value.first
      end
    end
  end
end

#fileObject



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)
      options.upload['file'] << file
    else
      CLI.puts "ERROR: File not found"
      exit
    end
  end
end

#filefieldObject



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|
    options.upload['filefield'] = filefield
  end
end

#headersObject



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(': ')
    options.headers[key] = value
  end
end

#helpObject



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

#hostObject



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)
      options.host = protocolless_host
    else
      options.host = host
    end
  end
end

#json_formatObject



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|
    options.json_format = true
  end
end

#optionsObject



178
179
180
# File 'lib/twurl/cli.rb', line 178

def options
  Twurl.options
end

#proxyObject



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|
    options.proxy = proxy
  end
end

#quietObject



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|
    options.output = StringIO.new
  end
end

#raw_dataObject



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 options.raw_data
      raise Exception, "ERROR: can't specify '-r' option more than once"
    elsif options.args.include?('-d') || options.args.include?('--data')
      raise Exception, "ERROR: can't use '-r' and '-d' options together"
    end
    options.raw_data = true
    options.data = data
  end
end

#request_methodObject



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|
    options.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

#timeoutObject



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|
    options.timeout = timeout
  end
end

#token_secretObject



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|
    options.token_secret = secret
  end
end

#traceObject



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|
    options.trace = trace
  end
end

#tutorialObject



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

#usernameObject



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|
    options.username = username
  end
end

#versionObject



294
295
296
297
298
299
# File 'lib/twurl/cli.rb', line 294

def version
  on_tail("-v", "--version", "Show version") do
    CLI.puts "twurl version: #{Version}\nplatform: #{RUBY_ENGINE} #{RUBY_VERSION} (#{RUBY_PLATFORM})"
    exit
  end
end