Class: Pindo::HttpClient

Inherits:
Object
  • Object
show all
Defined in:
lib/pindo/client/httpclient.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#baseurlObject

Returns the value of attribute baseurl.



16
17
18
# File 'lib/pindo/client/httpclient.rb', line 16

def baseurl
  @baseurl
end

#request_configObject

Returns the value of attribute request_config.



17
18
19
# File 'lib/pindo/client/httpclient.rb', line 17

def request_config
  @request_config
end

#tokenObject

Returns the value of attribute token.



15
16
17
# File 'lib/pindo/client/httpclient.rb', line 15

def token
  @token
end

#use_local_wechat_urlObject

Returns the value of attribute use_local_wechat_url.



14
15
16
# File 'lib/pindo/client/httpclient.rb', line 14

def use_local_wechat_url
  @use_local_wechat_url
end

Class Method Details

.create_instanceObject



43
44
45
46
47
# File 'lib/pindo/client/httpclient.rb', line 43

def self.create_instance()
    
    con = Faraday.new 
    con
end

.create_instance_with_proxyObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/pindo/client/httpclient.rb', line 19

def self.create_instance_with_proxy()

    # puts body_params.to_json
    proxy_options = {
      uri: ENV['http_proxy'] || ENV['https_proxy'],
      user: ENV['HTTP_PROXY_USER'],
      password: ENV['HTTP_PROXY_PASSWORD']
    }

    retry_options = {
      max: 3,                   # Retry a failed request up to 5 times
      interval: 0.5,            # First retry after 0.5s
      backoff_factor: 2,        # Double the delay for each subsequent retry
      interval_randomness: 0.5, # Specify "jitter" of up to 50% of interval
    }

    con = Faraday.new do |config|
      config.request :retry, retry_options
      config.proxy = proxy_options.compact if proxy_options[:uri]  
    end
    
    con
end