rail-locator-api 0.1.2 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: facf4423c0e86173d4dc747fc5223723b98a7999c316f5b1fb64b80ce048b988
4
- data.tar.gz: eac12b206586fd5d73e70bc812d7b0f293d0676bb2dd400ffc1d03b9b3197057
3
+ metadata.gz: 7762a99a37ea7b47aa2ed65f3f6630241f517032406bc2429b67dee2c50427ca
4
+ data.tar.gz: 123e945e95a7e6bf9cb3b7ca4f9bbe75b04f3cf1696eb80b34210083beb4043d
5
5
  SHA512:
6
- metadata.gz: 123fe83f4d87605ea16a9ce70d2d1d7f94c114cafa18431fde2947feee042ac9a72ad05c2ffadce538fc6e2a920832ecb2b679e3a2a1cedc73baba20993b3691
7
- data.tar.gz: f51540d4f9048cd0c2d57638d65cabeb6e8a4d33dd5c755180a32a5d74c1ef40f97e51f768f815a7dd30aa3f7491805a269348253a11fd382ca2f98965d68dfc
6
+ metadata.gz: c5380c51d1e5e98257a77082d5cef152dc252e58cd8a38b0bfbfc93f7ce1e29659f20283fbaa466f6b047b6c41b262c9bc1add14ed33d7761fedbd40e47da408
7
+ data.tar.gz: 81f3c66c05e639fa367397d0c0c451c89645e7bbf45b6c83ba932d8f26590370223259eff448700f1a39199e763c214a336bd293d15fcedb560383e69ebcb76e
data/README.markdown CHANGED
@@ -43,9 +43,18 @@ API wrapper для RailLocator API v2
43
43
  8. [Справочники](#references)
44
44
  1. [Получение Координат Станции](#references_station_get)
45
45
  2. [Получение Списка Станций С Краткой Информацией](#references_stations_get)
46
+ 9. [Рассылки](#emailings)
47
+ 1. [Создание Рассылки](#emailings_post)
46
48
 
47
49
  # <a name="install"></a> Установка
48
50
 
51
+ Для авторизации по api key необходимо получить его [в личном кабинете локатора](https://rail-locator.com/app/api-keys)
52
+ или в телеграм боте [@RailLocatorApiBot](https://t.me/RailLocatorApiBot)
53
+
54
+ либо использовать другие методы авторизации:
55
+
56
+ `:keycloak, :api_key, :base64`
57
+
49
58
  ## Ruby
50
59
  $ gem install rail-locator-api
51
60
  ## Rails
@@ -59,7 +68,6 @@ API wrapper для RailLocator API v2
59
68
 
60
69
  rails g rail_locator_api:install
61
70
 
62
-
63
71
  ## <a name="using_rails"></a> Использование Rails
64
72
 
65
73
  В файл `config/rail_locator_api.yml` вставьте ваши данные
@@ -69,19 +77,24 @@ API wrapper для RailLocator API v2
69
77
  Сначала создайте экземпляр объекта `RailLocatorApi::Request`:
70
78
 
71
79
  ```ruby
72
- locator = RailLocatorApi::Request.new(api_user_email: "email@ctm.ru", api_user_password: "12345678")
80
+ locator = RailLocatorApi::Request.new(api_key: "***")
81
+ # или
82
+ locator = RailLocatorApi::Request.new(api_auth_method: :base64, api_user_email: "email@ctm.ru", api_user_password: "12345678")
73
83
  ```
74
84
 
75
- Вы можете изменять `api_user_email`, `api_user_password`, `timeout`, `open_timeout`, `faraday_adapter`, `proxy`, `symbolize_keys`, `logger`, и `debug`:
85
+ Вы можете изменять `api_auth_method`, `api_key`, `api_user_email`, `api_user_password`, `timeout`, `open_timeout`, `faraday_adapter`, `proxy`, `symbolize_keys`, `logger`, и `debug`:
76
86
 
77
87
  ```ruby
78
- RailLocatorApi::Request.api_key = "your_api_key"
79
- RailLocatorApi::Request.api_user_email = "email@ctm.ru"
80
- RailLocatorApi::Request.api_user_password = "12345678"
81
88
  RailLocatorApi::Request.timeout = 15
82
89
  RailLocatorApi::Request.open_timeout = 15
83
90
  RailLocatorApi::Request.symbolize_keys = true
84
91
  RailLocatorApi::Request.debug = false
92
+
93
+ RailLocatorApi::Request.api_key = "your_api_key"
94
+ # или
95
+ RailLocatorApi::Request.api_auth_method = :base64
96
+ RailLocatorApi::Request.api_user_email = "email@ctm.ru"
97
+ RailLocatorApi::Request.api_user_password = "12345678"
85
98
  ```
86
99
 
87
100
  Либо в файле `config/initializers/rail_locator_api.rb` для Rails.
@@ -91,7 +104,7 @@ RailLocatorApi::Request.debug = false
91
104
  Измените `debug: true` чтобы включить логирование в STDOUT.
92
105
 
93
106
  ```ruby
94
- locator = RailLocatorApi::Request.new(api_key: "your_api_key", debug: true)
107
+ locator = RailLocatorApi::Request.new(api_key: "***", debug: true)
95
108
  ```
96
109
 
97
110
  ### <a name="custom_logger"></a> Custom logger
@@ -99,7 +112,7 @@ locator = RailLocatorApi::Request.new(api_key: "your_api_key", debug: true)
99
112
  `Logger.new` используется по умолчанию, но вы можете изменить на свой:
100
113
 
101
114
  ```ruby
102
- locator = RailLocatorApi::Request.new(api_user_email: "email@ctm.ru", api_user_password: "12345678", debug: true, logger: MyLogger.new)
115
+ locator = RailLocatorApi::Request.new(api_key: "***", debug: true, logger: MyLogger.new)
103
116
  ```
104
117
 
105
118
  Или:
@@ -490,4 +503,40 @@ p response.body
490
503
  ```ruby
491
504
  response = RailLocatorApi::Request.references.stations.retrieve(params: {station_code: "111"})
492
505
  p response.body
493
- ```
506
+ ```
507
+ ## <a name="emailings"></a> Рассылки
508
+ ### <a name="emailings_post"></a> [Создание Рассылки](http://soap.ctm.ru:8112/api/v2.0/redoc#tag/Rassylki/operation/__________________emailings_post)
509
+
510
+ ```ruby
511
+ request = {
512
+ "title": "Название рассылки",
513
+ "data_source": "groups",
514
+ "data_ids": [
515
+ "1234",
516
+ "12345"
517
+ ],
518
+ "recipients": [
519
+ "example@mail.ru"
520
+ ],
521
+ "sending_days": [
522
+ "Sun",
523
+ "Mon",
524
+ "Tue",
525
+ "Wed",
526
+ "Thu",
527
+ "Fri",
528
+ "Sat"
529
+ ],
530
+ "sending_times": [
531
+ "08:00:00",
532
+ "17:00:00"
533
+ ],
534
+ "template_title": "Тема письма",
535
+ "template_content": "Текст письма",
536
+ "active_objects": true,
537
+ "language": "ru",
538
+ "user_note": "Примечание"
539
+ }
540
+ response = RailLocatorApi::Request.emailings.create(body: request)
541
+ p response.body
542
+ ```
@@ -1,8 +1,12 @@
1
1
  defaults: &defaults
2
- API_KEY: "***"
3
2
  API_ENDPOINT: "http://soap.ctm.ru:8112"
3
+
4
+ API_AUTH_METHOD: "api_key"
5
+ API_KEY: "***"
6
+
4
7
  API_USER_EMAIL: ""
5
8
  API_USER_PASSWORD: ""
9
+
6
10
  KEYCLOAK_TOKEN_URL: "https://iam.ctm.ru/auth/realms/ctm/protocol/openid-connect/token"
7
11
  KEYCLOAK_GRANT_TYPE: "password"
8
12
  KEYCLOAK_CLIENT_ID: "client_id"
@@ -127,11 +127,14 @@ module RailLocatorApi
127
127
  if [:api_key, :keycloak].include?(self.api_auth_method)
128
128
  request.headers['Authorization'] = "Bearer #{RailLocatorApi::Request.access_token}"
129
129
  end
130
+ if [:keycloak].include?(self.api_auth_method)
131
+ request.headers['X-API-KEY'] = "#{RailLocatorApi::Request.api_key}"
132
+ end
130
133
  request.headers['User-Agent'] = "RailLocatorApi/#{RailLocatorApi::VERSION} Ruby gem"
131
134
  if @request_builder.without_ratelimit
132
135
  request.headers['X-Request-Without-Ratelimit'] = "1"
133
136
  end
134
-
137
+ request.headers['Accept-Encoding'] = "gzip"
135
138
  request.headers.merge!(headers) if headers
136
139
  request.body = MultiJson.dump(body) if body
137
140
  request.options.timeout = self.timeout
@@ -5,7 +5,7 @@ module RailLocatorApi
5
5
  :without_ratelimit, :logger, :test
6
6
 
7
7
  AUTH_METHODS = [:keycloak, :api_key, :base64]
8
- DEFAULT_AUTH_METHOD = :keycloak
8
+ DEFAULT_AUTH_METHOD = :api_key
9
9
  DEFAULT_TIMEOUT = 60
10
10
  DEFAULT_OPEN_TIMEOUT = 60
11
11
 
@@ -1,3 +1,3 @@
1
1
  module RailLocatorApi
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rail-locator-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Osetrov