rail-locator-api 0.1.2 → 0.1.3
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86dafa172f5244cd21ea40704c850a5f585514ba5b00437da05bca58d420cbe5
|
4
|
+
data.tar.gz: 439dc8ac49e8998c577981a319e1939600831304ce60bfcd2f10179af2d28c51
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 074b9f3ad0f4561006e01a58bc9a7f83c2b792f3c715adc85f25317d080a9cdada8e3c95f2ba1d28c267a511f93dfac118894af414ae51ded59ffae582592b9c
|
7
|
+
data.tar.gz: 1393c5d85d5bc21600d50e618a2c0ef1e87763e68d5a77c936e87911f139f172d439951d024345d927f1569a3086bb4916e96a60821ece19885e6aba04811d24
|
data/README.markdown
CHANGED
@@ -46,6 +46,11 @@ API wrapper для RailLocator API v2
|
|
46
46
|
|
47
47
|
# <a name="install"></a> Установка
|
48
48
|
|
49
|
+
Для авторизации по api key необходимо получить его [в личном кабинете локатора](https://rail-locator.com/app/api-keys)
|
50
|
+
либо использовать другие методы авторизации:
|
51
|
+
|
52
|
+
`:keycloak, :api_key, :base64`
|
53
|
+
|
49
54
|
## Ruby
|
50
55
|
$ gem install rail-locator-api
|
51
56
|
## Rails
|
@@ -59,7 +64,6 @@ API wrapper для RailLocator API v2
|
|
59
64
|
|
60
65
|
rails g rail_locator_api:install
|
61
66
|
|
62
|
-
|
63
67
|
## <a name="using_rails"></a> Использование Rails
|
64
68
|
|
65
69
|
В файл `config/rail_locator_api.yml` вставьте ваши данные
|
@@ -69,19 +73,24 @@ API wrapper для RailLocator API v2
|
|
69
73
|
Сначала создайте экземпляр объекта `RailLocatorApi::Request`:
|
70
74
|
|
71
75
|
```ruby
|
72
|
-
locator = RailLocatorApi::Request.new(
|
76
|
+
locator = RailLocatorApi::Request.new(api_key: "***")
|
77
|
+
# или
|
78
|
+
locator = RailLocatorApi::Request.new(api_auth_method: :base64, api_user_email: "email@ctm.ru", api_user_password: "12345678")
|
73
79
|
```
|
74
80
|
|
75
|
-
Вы можете изменять `api_user_email`, `api_user_password`, `timeout`, `open_timeout`, `faraday_adapter`, `proxy`, `symbolize_keys`, `logger`, и `debug`:
|
81
|
+
Вы можете изменять `api_auth_method`, `api_key`, `api_user_email`, `api_user_password`, `timeout`, `open_timeout`, `faraday_adapter`, `proxy`, `symbolize_keys`, `logger`, и `debug`:
|
76
82
|
|
77
83
|
```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
84
|
RailLocatorApi::Request.timeout = 15
|
82
85
|
RailLocatorApi::Request.open_timeout = 15
|
83
86
|
RailLocatorApi::Request.symbolize_keys = true
|
84
87
|
RailLocatorApi::Request.debug = false
|
88
|
+
|
89
|
+
RailLocatorApi::Request.api_key = "your_api_key"
|
90
|
+
# или
|
91
|
+
RailLocatorApi::Request.api_auth_method = :base64
|
92
|
+
RailLocatorApi::Request.api_user_email = "email@ctm.ru"
|
93
|
+
RailLocatorApi::Request.api_user_password = "12345678"
|
85
94
|
```
|
86
95
|
|
87
96
|
Либо в файле `config/initializers/rail_locator_api.rb` для Rails.
|
@@ -91,7 +100,7 @@ RailLocatorApi::Request.debug = false
|
|
91
100
|
Измените `debug: true` чтобы включить логирование в STDOUT.
|
92
101
|
|
93
102
|
```ruby
|
94
|
-
locator = RailLocatorApi::Request.new(api_key: "
|
103
|
+
locator = RailLocatorApi::Request.new(api_key: "***", debug: true)
|
95
104
|
```
|
96
105
|
|
97
106
|
### <a name="custom_logger"></a> Custom logger
|
@@ -99,7 +108,7 @@ locator = RailLocatorApi::Request.new(api_key: "your_api_key", debug: true)
|
|
99
108
|
`Logger.new` используется по умолчанию, но вы можете изменить на свой:
|
100
109
|
|
101
110
|
```ruby
|
102
|
-
locator = RailLocatorApi::Request.new(
|
111
|
+
locator = RailLocatorApi::Request.new(api_key: "***", debug: true, logger: MyLogger.new)
|
103
112
|
```
|
104
113
|
|
105
114
|
Или:
|
@@ -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,6 +127,9 @@ 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"
|