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



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

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



9
10
11
# File 'lib/geminabox/http_adapter/template_faraday_adapter.rb', line 9

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

#get_content(*args) ⇒ Object



13
14
15
16
# File 'lib/geminabox/http_adapter/template_faraday_adapter.rb', line 13

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

#http_engineObject



41
42
43
# File 'lib/geminabox/http_adapter/template_faraday_adapter.rb', line 41

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

#optionsObject



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

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

#post(*args) ⇒ Object



18
19
20
# File 'lib/geminabox/http_adapter/template_faraday_adapter.rb', line 18

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



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

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
  set_username_and_password connection, username, password if username
  connection
end