Class: TorgApi::Api::Bidder

Inherits:
Base
  • Object
show all
Defined in:
lib/torg_api/api/bidder.rb

Overview

Участник закупки

Constant Summary

Constants inherited from Base

Base::REMOVE_HASH_ATTRS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

attr_accessor, attributes, #initialize, #to_h, torg_resource

Constructor Details

This class inherits a constructor from TorgApi::Base

Instance Attribute Details

#contractor_idInteger



8
9
10
# File 'lib/torg_api/api/bidder.rb', line 8

def contractor_id
  @contractor_id
end

#idInteger



6
7
8
# File 'lib/torg_api/api/bidder.rb', line 6

def id
  @id
end

#tender_idInteger



10
11
12
# File 'lib/torg_api/api/bidder.rb', line 10

def tender_id
  @tender_id
end

Class Method Details

.create(contractor_id, tender_id, date_offer = nil) ⇒ Bidder

Создаёт участника в системе и возвращает его id



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/torg_api/api/bidder.rb', line 19

def create(contractor_id, tender_id, date_offer = nil)
  responce_b = JSON.parse(
    torg_resource["tenders/#{tender_id}/bidders"].post(
      bidder: {
        tender_id: tender_id,
        contractor_id: contractor_id,
        covers_attributes: {
          '0' => {
            _destroy: false,
            compound_register_time_attributes: {
              date: date_offer && date_offer.strftime('%d.%m.%Y'),
              time: date_offer && date_offer.strftime('%H:%M')
            },
            type_id: CoverLabels::REQUEST,
            delegate: 'B2B-Center',
            provision: 'Электронный конверт'
          }
        }
      },
      accept: :json,
      content_type: :json,
      format: :json
    ),
    symbolize_names: true
  )

  new(responce_b)
end

Instance Method Details

#add_file(file, name = nil, note = nil) ⇒ Object

Добавляет файл предложения участника к нему



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/torg_api/api/bidder.rb', line 69

def add_file(file, name = nil, note = nil)
  document = if file.start_with?('http')
    { remote_document_url: file }
  else
    { document: File.open(file) }
  end
  responce_f = JSON.parse(
    TorgApi::Base.torg_resource["tender_files"].post(
      tender_file: {
        area_id: TenderFileArea::BIDDER,
        year: Date.current.year,
        external_filename: name
      }.merge(document),
      accept: :json,
      content_type: :json,
      format: :json
    ),
    symbolize_names: true
  )

  responce_bf = JSON.parse(
    TorgApi::Base.torg_resource["tenders/#{tender_id}/bidders/#{id}"].patch(
      bidder: {
        bidder_files_attributes: {
          '0' => {
            note: note,
            tender_file_id: responce_f[:id],
            bidder_id: id
          }
        }
      },
      accept: :json,
      content_type: :json,
      format: :json
    ),
    symbolize_names: true
  )
  responce_bf
end

#file_exists?(file_name) ⇒ Boolean

Проверяет, есть ли файл с таким именем у данного участника return [Boolean]



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/torg_api/api/bidder.rb', line 51

def file_exists?(file_name)
  responce = JSON.parse(
    TorgApi::Base.torg_resource["tenders/#{tender_id}/bidders/#{id}/file_exists"].get(
      params: { file_name: file_name },
      accept: :json,
      content_type: :json,
      format: :json
    ),
    symbolize_names: true
  )
  responce[:exists]
end