Class: AssUpdater::HTTP

Inherits:
Object
  • Object
show all
Defined in:
lib/ass_updater/http.rb

Overview

Note:

1C servise often unavaileble and #get fail on timeout

HTTP access to 1C services.

Constant Summary collapse

USER_AGENT_DEFAULT =

Value of useragent controled 1C web server and server may return 403 error

'1C+Enterprise/8.2'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(proxy_options = {}) ⇒ HTTP

Returns a new instance of HTTP.

Parameters:

  • proxy_options (Hash) (defaults to: {})

    options for proxy server



23
24
25
26
27
28
29
30
31
# File 'lib/ass_updater/http.rb', line 23

def initialize(proxy_options = {})
  self.open_timeout = 30 # fucking 1C
  self.user_agent = USER_AGENT_DEFAULT
  self.proxy_options = { addr: nil,
                         port: nil,
                         user: nil,
                         pass: nil }.merge(proxy_options)
  yeld self if block_given?
end

Instance Attribute Details

#open_timeoutObject

Note:

1C servise often unavaileble and #get fail on timeout

see Net::HTTP#open_timeout



17
18
19
# File 'lib/ass_updater/http.rb', line 17

def open_timeout
  @open_timeout
end

#proxy_optionsHash

see #initialize param

Returns:

  • (Hash)


14
15
16
# File 'lib/ass_updater/http.rb', line 14

def proxy_options
  @proxy_options
end

#read_timeoutObject

Note:

1C servise often unavaileble and #get fail on timeout

see Net::HTTP#read_timeout



20
21
22
# File 'lib/ass_updater/http.rb', line 20

def read_timeout
  @read_timeout
end

#user_agentString

Value of useragent controled 1C web server and server may return 403 error

Returns:

  • (String)


11
12
13
# File 'lib/ass_updater/http.rb', line 11

def user_agent
  @user_agent
end

Instance Method Details

#get(uri_str, user_name = nil, password = nil) ⇒ Object

Note:

1C servise often unavaileble and #get fail on timeout

Parameters:

  • uri_str (String)
  • user_name (String) (defaults to: nil)

    user 1C sevice

  • password (String) (defaults to: nil)


37
38
39
40
41
42
43
44
# File 'lib/ass_updater/http.rb', line 37

def get(uri_str, user_name = nil, password = nil)
  response = _http(URI(uri_str)).request(_get(user_name,
                                              password,
                                              URI(uri_str)
                                             )
                                        )
  _body(response, uri_str)
end