Module: RestEasy

Extended by:
RestEasy
Included in:
RestEasy
Defined in:
lib/rest_easy.rb,
lib/rest_easy/version.rb

Constant Summary collapse

VERSION =
"1.0.1"

Instance Method Summary collapse

Instance Method Details

#get_until(uri, timeout = 10, opts = {}, &block) ⇒ Boolean

Wait until an API call block resolves to true or the timeout is reached. The default is 10 seconds.

Parameters:

  • uri (String)

    API endpoint

  • timeout (Fixnum) (defaults to: 10)

    time to wait until false is returned

  • opts (Hash) (defaults to: {})

    options yielded to block

  • block (Proc)

    API call to evaluate

Returns:

  • (Boolean)


18
19
20
21
22
23
24
# File 'lib/rest_easy.rb', line 18

def get_until uri, timeout = 10, opts = {}, &block
  iterate timeout do
    result = RestClient.get(uri, opts){ |resp| yield resp }
    return true if result
    sleep 0.5
  end
end

#get_while(uri, timeout = 10, opts = {}, &block) ⇒ Boolean

Wait while an API call block resolves to true or the timeout is reached. The default is 10 seconds.

Parameters:

  • uri (String)

    API endpoint

  • timeout (Fixnum) (defaults to: 10)

    time to wait until false is returned

  • opts (Hash) (defaults to: {})

    options yielded to block

  • block (Proc)

    API call to evaluate

Returns:

  • (Boolean)


37
38
39
40
41
42
43
# File 'lib/rest_easy.rb', line 37

def get_while uri, timeout = 10, opts = {}, &block
  iterate timeout do
    result = RestClient.get(uri, opts){ |resp| yield resp }
    return true unless result
    sleep 0.5
  end
end