|
1 |
| -# Create REST-API service for address search in the FIAS database |
| 1 | +# Create REST-API service for address search in the FIAS |
2 | 2 |
|
3 |
| -Ruby on Rails project find russia's address with FIAS or KLADR code via API from FIAS database |
| 3 | +## Ruby on Rails project oneline searching valid russia's address via API from FIAS |
| 4 | +_(Проект реализующий REST-API сервис для получения валидных адресов из ФИАС посредством поисковой строки и некоторых параметров фильтрации)_ |
4 | 5 |
|
| 6 | +### Compatibility |
| 7 | + fias_api tested to work with: |
5 | 8 | * Ruby version 2.7.3 for script running
|
6 |
| -* Postgres server for Database |
| 9 | +* PostgreSQL13 as Database |
7 | 10 |
|
8 |
| -* System dependencies |
9 |
| - 100 Gb free disk space |
10 |
| - 4Gb RAM |
| 11 | +### Configuration |
| 12 | + config/puma.rb - defaul server ports, thread options, environment config |
| 13 | + _(тут можно настроить порт, режим запуска сервиса)_ |
11 | 14 |
|
| 15 | + max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } |
| 16 | + #Specifies the port that Puma will listen on to receive requests; default is 3000. |
| 17 | + port ENV.fetch("PORT") { 3000 } |
| 18 | + # Specifies the `environment` that Puma will run in. |
| 19 | + # default is production (test, development) |
| 20 | + environment ENV.fetch("RAILS_ENV") { "production" } |
12 | 21 |
|
13 |
| -* Configuration |
14 |
| - config/puma.rb - server ports, thread options config |
| 22 | + config/application.rb set default pagination params _(параметры пагинации по умолчанию)_ |
15 | 23 |
|
16 |
| -* Database creation |
17 |
| - edit config/database.yml and put |
18 |
| - right database connection params |
19 |
| - |
| 24 | + # the maximum number of records to be received is set by the user |
| 25 | + config.max_limit = 201 |
| 26 | + # default number of records to be received |
| 27 | + config.default_limit = 25 |
| 28 | + |
| 29 | + config/database.yml set database connection params _(настройка на базу данных)_ |
| 30 | + > the user must have the rights to create a database |
| 31 | +
|
| 32 | + default: &default |
| 33 | + adapter: postgresql |
| 34 | + encoding: unicode |
| 35 | + pool: 5 |
| 36 | + timeout: 5000 |
| 37 | + username: rails2 #change it |
| 38 | + password: qwerty123 #change it |
| 39 | + host: localhost |
| 40 | + |
| 41 | + |
| 42 | +### Initialization |
| 43 | + 1. download the fulldatabase in dbf format from https://fias.nalog.ru/ to the folder `dbf/` _(грузим полную базу ФИАС в dbf)_ |
| 44 | + |
| 45 | + 2. run `bin/setup`, and then, depending on the size of the input data, you will have to wait, while the database is being created from the imported files _(запускаем создание базы, и импорт данных)_ |
| 46 | + |
| 47 | + $ bin/setup |
| 48 | + |
| 49 | + 3. start server: |
| 50 | + |
| 51 | + $ rails s |
| 52 | + |
| 53 | + 4. in order to save disk space, delete all the files in the folder `dbf/` _(чистим папку от dbf-файлов)_ |
| 54 | + |
| 55 | +### Getting FIAS updates |
| 56 | + 1. download the updates in dbf format from https://fias.nalog.ru/ to the folder `dbf/` _(грузим обновления ФИАС в dbf)_ |
| 57 | + 2. stop server (ctrl+c) and run `rails db:seed`, and then, depending on the size of the input data, you will have to wait _(запускаем импорт данных)_ |
| 58 | + |
| 59 | + $ rails db:seed |
| 60 | + |
| 61 | + 3. start server: |
| 62 | + |
| 63 | + $ rails s |
| 64 | + |
| 65 | + 4. in order to save disk space, delete all the files in the folder `dbf/` _(чистим папку от dbf-файлов)_ |
| 66 | + |
| 67 | + ### Basic API Usage |
| 68 | + * type of request: `GET` |
| 69 | + * url of the service, by default: `http://<mydomen.com>/fias` |
| 70 | + * available parameters: |
| 71 | + * `query` - search query (search for) _(строка запроса)_ |
| 72 | + * `searchBar` - fulltext OneLineString search mode: `1` is ON, other - OFF |
| 73 | + _(режим свободного поиск одной строкой)_ |
| 74 | + * `level` - filter address level as (`region`,`district`,`city`,`territory`, `town`,`street`, `building`) |
| 75 | + * `parent` - filter by aogoid of parent address object as `UUID` _(выбрать только дочерние элементы для `parent`)_ |
| 76 | + * `regionID` - filter by region code like (`24`,`07`..) |
| 77 | + * `limit`,`offset` - pagination _(задают смещение и размер страницы результатов)_ |
| 78 | + * `total_found` - to include number of founded items: `1` is ON, other - OFF |
| 79 | + _(включить общее число найденных объектов)_ |
| 80 | + * `withParent`, `fullInfo` - additional info modes params: `1` is ON, other - OFF _(включить вышестоящие элементы адреса, включить полную информаию из ФИАС)_ |
20 | 81 |
|
| 82 | +### Examples |
| 83 | + Auto-completion for entering an address in one line: |
| 84 | + |
| 85 | + request: |
| 86 | + http://localhost:3000/fias?searchBar=1&total_found=1&query=благовещенск,театральная,6 |
| 87 | + |
| 88 | + response: |
| 89 | + { |
| 90 | + "status": "SUCCESS", |
| 91 | + "message": "1 entries received", |
| 92 | + "total_found": 1, |
| 93 | + "data": [ |
| 94 | + { |
| 95 | + "AOGUID": "985e90b6-99ca-4d18-abde-bd09ce01100f", |
| 96 | + "HouseGUID": "0afe10c4-bbfb-4ba2-bab8-85de58c27856", |
| 97 | + "name": "д. 65", |
| 98 | + "streetAddressLine": "Амурская обл, Благовещенск г, Театральная ул, д. 65", |
| 99 | + "rustype": "д.", |
| 100 | + "level": "building" |
| 101 | + } |
| 102 | + ] |
| 103 | + } |
21 | 104 |
|
22 |
| -* Database initialization |
23 |
| - 1. just put in 'dbf' folder actual updates or fullbase in dbf format from |
24 |
| - https://fias.nalog.ru/ |
25 |
| - 2. run 'bin/setup' in command line, And then, depending on the size of the input data, you will have to wait |
| 105 | + Auto-completion by cities of the Amur region |
26 | 106 |
|
| 107 | + request: |
| 108 | + http://localhost:3000/fias?parent=844a80d6-5e31-4017-b422-4d9c01e9942c&level=city&total_found=1 |
27 | 109 |
|
| 110 | + response: |
| 111 | + { |
| 112 | + "status": "SUCCESS", |
| 113 | + "message": "9 entries received", |
| 114 | + "total_found": 9, |
| 115 | + "data": [ |
| 116 | + { |
| 117 | + "AOGUID": "c528e99b-7e81-4290-9cda-8713884472a5", |
| 118 | + "parentGUID": "844a80d6-5e31-4017-b422-4d9c01e9942c", |
| 119 | + "code": "2800000300000", |
| 120 | + "name": "Белогорск", |
| 121 | + "shortname": "г", |
| 122 | + "streetAddressLine": "Амурская обл, Белогорск г", |
| 123 | + "level": "City" |
| 124 | + }, |
| 125 | + { |
| 126 | + "AOGUID": "8f41253d-6e3b-48a9-842a-25ba894bd093", |
| 127 | + "parentGUID": "844a80d6-5e31-4017-b422-4d9c01e9942c", |
| 128 | + "code": "2800000100000", |
| 129 | + "name": "Благовещенск", |
| 130 | + "shortname": "г", |
| 131 | + "streetAddressLine": "Амурская обл, Благовещенск г", |
| 132 | + "level": "City" |
| 133 | + }, |
| 134 | + { |
| 135 | + "AOGUID": "581855f4-f0bc-44a5-a36e-a298279f9ec4", |
| 136 | + "parentGUID": "844a80d6-5e31-4017-b422-4d9c01e9942c", |
| 137 | + "code": "2800000400000", |
| 138 | + "name": "Зея", |
| 139 | + "shortname": "г", |
| 140 | + "streetAddressLine": "Амурская обл, Зея г", |
| 141 | + "level": "City" |
| 142 | + }, |
| 143 | + { |
| 144 | + "AOGUID": "16de8821-04f5-4239-b33b-739f8eff7c88", |
| 145 | + "parentGUID": "844a80d6-5e31-4017-b422-4d9c01e9942c", |
| 146 | + "code": "2800000800000", |
| 147 | + "name": "Прогресс", |
| 148 | + "shortname": "пгт", |
| 149 | + "streetAddressLine": "Амурская обл, Прогресс пгт", |
| 150 | + "level": "City" |
| 151 | + }, |
| 152 | + ... |
0 commit comments