Module: ConsoleUtils::RequestUtils

Extended by:
ActiveSupport::Autoload
Defined in:
lib/console_utils/request_utils.rb,
lib/console_utils/request_utils/remo.rb,
lib/console_utils/request_utils/exap.rb,
lib/console_utils/request_utils/requester.rb,
lib/console_utils/request_utils/request_params.rb,
lib/console_utils/request_utils/auth_automators.rb

Overview

:nodoc:

Defined Under Namespace

Classes: DefaultAuthAutomator, Exap, Remo, RequestParams, Requester, SimpleTokenAutomator

Instance Method Summary collapse

Instance Method Details

#autoken(id) ⇒ Object

:call-seq:

autoken(id)
autoken(:any)

Returns user's token by primary key. Use :any to get random user.


24
25
26
# File 'lib/console_utils/request_utils.rb', line 24

def autoken(id)
  ConsoleUtils.auto_token_for(id)
end

#exapObject

:call-seq:

exap(.get|.post|.put|...)(url, user_id = nil, **params)

Local API requester context. See also: ConsoleUtils::RequestUtils::Exap

Examples:

Appends auth token of default user to params, makes request and prints formatted response:

exap.get("api/posts.json").preview

Authorize user #42, also copy formatted response to the pasteboard:

exap.get("api/posts.json", 42).preview(&:pbcopy)

Authorize random user:

exap.get("api/comments.json", :any).preview

Use additional request params (skip the second parameter to use default user), don't print response body:

exap.put("api/account.json", 42, user: { name: "Anton" })

Skip auto-fetching user's token:

exap.post("api/signup.json", nil, user: { name: "Guest" }).preview

57
58
59
# File 'lib/console_utils/request_utils.rb', line 57

def exap
  Exap.new(self)
end

#remoObject

:call-seq:

remo(.get|.post|.put|...)(url, user_id = nil, **params)

Remote API requester context. See also: ConsoleUtils::RequestUtils::Remo

Examples:

See exap examples.


69
70
71
# File 'lib/console_utils/request_utils.rb', line 69

def remo
  Remo.new(self)
end