Class: Flute::Network

Inherits:
Object
  • Object
show all
Defined in:
lib/flute/network.rb

Instance Method Summary collapse

Instance Method Details

#create_manager(max_concurrency: 5) ⇒ Object



25
26
27
# File 'lib/flute/network.rb', line 25

def create_manager(max_concurrency: 5)
  Typhoeus::Hydra.new(max_concurrency: max_concurrency)
end

#get(url, params: {}, headers: {}) ⇒ Object



3
4
5
6
7
# File 'lib/flute/network.rb', line 3

def get(url, params: {}, headers: {})
  options = make_options params, headers
  response = Typhoeus.get(url, options)
  Response.new response
end

#make_options(params = {}, headers = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/flute/network.rb', line 15

def make_options(params={}, headers={})
  options = {
      headers: headers,
      params: params,
      followlocation: true,
      accept_encoding: 'gzip'
  }      
  options
end

#request(url, params: {}, headers: {}, method: :get, body: {}) ⇒ Object



9
10
11
12
13
# File 'lib/flute/network.rb', line 9

def request(url,  params: {}, headers: {}, method: :get, body: {})
  options = make_options params, headers
  request = Request.new url, options.merge(method: method, body: body)      
  request
end