Module: Net

Defined in:
flow/net/net.rb,
flow/net/header.rb,
flow/net/config.rb,
flow/net/session.rb,
flow/net/actions.rb,
flow/net/response.rb,
flow/net/stubbable.rb,
flow/net/expectation.rb,
flow/net/authorization.rb

Defined Under Namespace

Modules: Config Classes: Request, Response, Session

Class Method Summary (collapse)

Class Method Details

+ (Object) build(base_url, &block)

Creates a session with common configuration

Examples:

session = Net.build('https://httpbin.org') do
  header(:content_type, :json)
end
session.get("/users") do |response|
end
session.get("/posts") do |response|
end


13
14
15
# File 'flow/net/net.rb', line 13

def build(base_url, &block)
  Session.build(base_url, &block)
end

+ (Object) delete(base_url, options) {|response| ... }

Parameters:

  • base_url (String)

    The url to request

  • options (Hash)

Options Hash (options):

  • headers (Hash)
  • body (String)
  • connection_timeout (Fixnum)
  • read_timeout (Fixnum)

Yields:

  • (response)

Yield Parameters:



# File 'flow/net/net.rb', line 76

+ (Object) get(base_url, options) {|response| ... }

Parameters:

  • base_url (String)

    The url to request

  • options (Hash)

Options Hash (options):

  • headers (Hash)
  • body (String)
  • connection_timeout (Fixnum)
  • read_timeout (Fixnum)

Yields:

  • (response)

Yield Parameters:



# File 'flow/net/net.rb', line 46

+ (Object) head(base_url, options) {|response| ... }

Parameters:

  • base_url (String)

    The url to request

  • options (Hash)

Options Hash (options):

  • headers (Hash)
  • body (String)
  • connection_timeout (Fixnum)
  • read_timeout (Fixnum)

Yields:

  • (response)

Yield Parameters:



115
116
117
118
119
# File 'flow/net/net.rb', line 115

[:get, :post, :put, :delete, :patch, :options, :head].each do |http_medhod|
  define_method(http_medhod) do |base_url, *options, &callback|
    Request.send(http_medhod, base_url, options.shift || {}, callback)
  end
end

+ (Object) options(base_url, options) {|response| ... }

Parameters:

  • base_url (String)

    The url to request

  • options (Hash)

Options Hash (options):

  • headers (Hash)
  • body (String)
  • connection_timeout (Fixnum)
  • read_timeout (Fixnum)

Yields:

  • (response)

Yield Parameters:



# File 'flow/net/net.rb', line 96

+ (Object) patch(base_url, options) {|response| ... }

Parameters:

  • base_url (String)

    The url to request

  • options (Hash)

Options Hash (options):

  • headers (Hash)
  • body (String)
  • connection_timeout (Fixnum)
  • read_timeout (Fixnum)

Yields:

  • (response)

Yield Parameters:



# File 'flow/net/net.rb', line 86

+ (Object) post(base_url, options) {|response| ... }

Parameters:

  • base_url (String)

    The url to request

  • options (Hash)

Options Hash (options):

  • headers (Hash)
  • body (String)
  • connection_timeout (Fixnum)
  • read_timeout (Fixnum)

Yields:

  • (response)

Yield Parameters:



# File 'flow/net/net.rb', line 56

+ (Object) put(base_url, options) {|response| ... }

Parameters:

  • base_url (String)

    The url to request

  • options (Hash)

Options Hash (options):

  • headers (Hash)
  • body (String)
  • connection_timeout (Fixnum)
  • read_timeout (Fixnum)

Yields:

  • (response)

Yield Parameters:



# File 'flow/net/net.rb', line 66

+ (Boolean) reachable?(hostname = 'www.google.com', &block)

Track the reachability of a hostname

Examples:

# this block will be called each time network status is updated
reachability = Net.reachable?("www.google.fr") do |reachable|
  if reachable
    ###
  end
end
# stop network reachability tracking
reachability.stop

Returns:

  • (Boolean)


27
28
29
# File 'flow/net/net.rb', line 27

def reachable?(hostname = 'www.google.com', &block)
  Reachability.new(hostname, &block)
end

+ (Object) stub(base_url)

Stub an url to return the desired Response object

Examples:

Net.stub('www.example.com').and_return(Response.new(body:"example"))
Net.get("www.example.com") do |response|
  response.body # example
end


37
38
39
40
41
42
43
44
# File 'flow/net/net.rb', line 37

def stub(base_url)
  expectation = Expectation.all.find{ |e| e.base_url == base_url }
  if expectation.nil?
    expectation = Expectation.new(base_url)
    Expectation.all << expectation
  end
  expectation
end