Class: Geminabox::TemplateFaradayAdapter

Inherits:
HttpAdapter show all
Defined in:
lib/geminabox/http_adapter/template_faraday_adapter.rb

Instance Method Summary collapse

Instance Method Details

#adapterObject


32
33
34
35
36
37
# File 'lib/geminabox/http_adapter/template_faraday_adapter.rb', line 32

def adapter
  @adapter ||= Faraday.new do |faraday|
    faraday.adapter http_engine
    faraday.proxy(ENV['http_proxy']) if ENV['http_proxy']
  end
end

#get(*args) ⇒ Object


7
8
9
# File 'lib/geminabox/http_adapter/template_faraday_adapter.rb', line 7

def get(*args)
  adapter.get(*args)
end

#get_content(*args) ⇒ Object


11
12
13
14
# File 'lib/geminabox/http_adapter/template_faraday_adapter.rb', line 11

def get_content(*args)
  response = adapter.get(*args)
  response.body
end

#http_engineObject


39
40
41
# File 'lib/geminabox/http_adapter/template_faraday_adapter.rb', line 39

def http_engine
  :net_http  # make requests with Net::HTTP
end

#optionsObject


43
44
45
46
47
48
# File 'lib/geminabox/http_adapter/template_faraday_adapter.rb', line 43

def options
  lambda {|faraday|
    faraday.adapter http_engine
    faraday.proxy(ENV['http_proxy']) if ENV['http_proxy']
  }
end

#post(*args) ⇒ Object


16
17
18
# File 'lib/geminabox/http_adapter/template_faraday_adapter.rb', line 16

def post(*args)
  adapter.post(*args)
end

#set_auth(uri, username = nil, password = nil) ⇒ Object

Note that this configuration turns SSL certificate verification off. To set up the adapter for your environment see: github.com/lostisland/faraday/wiki/Setting-up-SSL-certificates


23
24
25
26
27
28
29
30
# File 'lib/geminabox/http_adapter/template_faraday_adapter.rb', line 23

def set_auth(uri, username = nil, password = nil)
  connection = Faraday.new url: uri, ssl: {verify: false} do |faraday|
    faraday.adapter http_engine
    faraday.proxy(ENV['http_proxy']) if ENV['http_proxy']
  end
  connection.basic_auth username, password if username
  connection
end