Skip to content

Instantly share code, notes, and snippets.

@stp-che
Created October 3, 2018 12:20
Show Gist options
  • Save stp-che/03525dca38e54cc89e63f2dbaf61230a to your computer and use it in GitHub Desktop.
Save stp-che/03525dca38e54cc89e63f2dbaf61230a to your computer and use it in GitHub Desktop.
require 'json'
require 'net/http'
HOST = '192.168.242.150'
USER = 'Администратор'
PASSWORD = ''
DB = 'DemoHRM1'
# Идентификаторы
# ПАО "Винтерфелл" - a878eda5-9484-11e8-a45d-e269cdf4837d
# Родрик Кассель - df67776e-948a-11e8-a45d-e269cdf4837d (Сотрудник в Винтерфелле)
# df67776f-948a-11e8-a45d-e269cdf4837d (Физ лицо)
# Робб Старк - df67775c-948a-11e8-a45d-e269cdf4837d (Сотрудник в Винтерфелле)
# df67775d-948a-11e8-a45d-e269cdf4837d (Физ лицо)
date_begin = Time.local(2018, 8, 1)
date_end = Time.local(2018, 8, 2)
def json_date(d)
d.strftime '%Y-%m-%dT00:00:00'
end
otpusk_data = {
# 'Ответственный_Key'
'Организация_Key' => 'a878eda5-9484-11e8-a45d-e269cdf4837d',
'Сотрудник_Key' => 'df67775c-948a-11e8-a45d-e269cdf4837d',
# 'ПериодРегистрации'
# 'ДатаНачалаСобытия' => json_date(date_begin),
'ДатаНачала' => json_date(date_begin),
'ДатаОкончания' => json_date(date_end)
}
uri = URI(URI.escape "http://#{HOST}/#{DB}/odata/standard.odata/Document_ОтпускБезСохраненияОплаты?$format=json")
req = Net::HTTP::Post.new(uri)
req.basic_auth USER, PASSWORD
req.body = JSON.dump(otpusk_data)
req.content_type = 'application/json'
res = Net::HTTP.start(uri.hostname, uri.port) do |http|
http.request(req)
end
File.open("create_otpusk1/#{Time.now.strftime '%Y-%m-%d_%H%M%S'}__#{res.code}", 'wb'){|f|
f.puts '--- REQUEST URI ---'
f.puts uri
f.puts
f.puts '--- REQUEST ---'
f << req.body
f.puts
f.puts
f.puts '--- RESPONSE ---'
f << res.body
f.puts
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment