govuk-registers-api-client 1.0.1 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ab771bc838779644bbd8763beea0c5a4c1138a298011af39a4ac4121068c3d40
4
- data.tar.gz: ae34e34c99dc13883a2865393b54aa386fa04cf0174f835bfd60fa1dae582699
3
+ metadata.gz: ad44826f15da4eff3286aac98593630b0b34972a28701b6e72c6dffc8a79e1d3
4
+ data.tar.gz: a035133485d3f7f842dd44a542eb1c7253bb26579576fc0848ce20e61e5ef2bd
5
5
  SHA512:
6
- metadata.gz: cbe860777cef29b1ad7ba40fd47dcc3b10319eff06623637ad03deb83fd8e6771dd60c694acd92642c676270b78c9cfd631e4bda8e62d415bc232d858ea998ee
7
- data.tar.gz: 735d24e0805542891a4cd14a0504b40455ad8e2d77921e267775abefbf07bb4b4d284c78146ee239b608e182e5f5ce569b5b09ec9fb1eb5b697d560c142257fe
6
+ metadata.gz: fe46727474d9b7c8342b3cb909b2abb3423fb2b2d760cb8e957a75662fb1011492356a2e1a42d272141e4549114bcb061f79fa4fcd1351cc5b7ed53a5dc15d9e
7
+ data.tar.gz: bbbea01d73e999aebe657a75ccb8f1304e0913cc8fc7b12b923255f64e3b1ee798d85883843a54d1caff6b5ed49e8a36a494a9cf3e1fa56c49509bc7b5d37713
data/.version CHANGED
@@ -1 +1 @@
1
- 1.0.1
1
+ 1.1.1
data/README.md CHANGED
@@ -35,6 +35,7 @@ The `RegisterClientManager` is the entry point of the Registers Ruby client:
35
35
  require 'register_client_manager'
36
36
 
37
37
  registers_client = RegistersClient::RegisterClientManager.new({
38
+ api_key: "YOUR API KEY HERE",
38
39
  page_size: 10
39
40
  })
40
41
  ```
@@ -42,17 +43,22 @@ registers_client = RegistersClient::RegisterClientManager.new({
42
43
  The `RegisterClientManager` maintains individual instances of [`RegisterClient`](#registerclient) for each register you access via the [`get_register`](#getregister) method.
43
44
 
44
45
  When creating a new `RegisterClientManager`, you can pass a configuration object to specify the following:
46
+ - The `api_key` is the API key you received after signing-up your service on our product page.
45
47
  - `page_size`: number of results returned per page when using the `page` method of any of the collection classes (see below for more information) - default is `100`
46
48
 
47
49
  ## Reference
48
50
 
49
51
  ### <a id="registerclientmanager"></a>`RegisterClientManager`
50
52
 
51
- ##### <a id="getregister"></a>`get_register(register, phase, data_store = nil)`
53
+ ##### <a id="getregister"></a>`get_register(register, phase, options = {})`
52
54
 
53
55
  Gets the `RegisterClient` instance for the given `register` name and `phase`.
54
56
 
55
- The `data_store` parameter specifies the data store to use accessing a particular register. You can omit this parameter, which will make it default to the `InMemoryDataStore` value. You can also create a custom data store to include the `DataStore` module and to implement the methods it defines. For example, to insert register data directly into your Postgres database.
57
+ You can pass an optional `options` object, which can include the following properties:
58
+
59
+ - data_store
60
+
61
+ The `data_store` specifies the data store to use accessing a particular register. You can omit this parameter, which will make it default to the `InMemoryDataStore` value. You can also create a custom data store to include the `DataStore` module and to implement the methods it defines. For example, to insert register data directly into your Postgres database.
56
62
 
57
63
  <details>
58
64
  <summary>
@@ -61,7 +67,10 @@ Example use (click here to expand):
61
67
 
62
68
  ```
63
69
 
64
- registers_client.get_register('country', 'beta', nil)
70
+ options = {
71
+ data_store: nil
72
+ }
73
+ registers_client.get_register('country', 'beta', options)
65
74
 
66
75
  ```
67
76
  </details>
@@ -802,4 +811,3 @@ ull}}]],
802
811
 
803
812
  ```
804
813
  </details>
805
-
@@ -1,5 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: govuk-registers-api-client 1.0.1 ruby lib
2
+ # stub: govuk-registers-api-client 1.1.1 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "govuk-registers-api-client".freeze
@@ -5,10 +5,11 @@ require 'exceptions/invalid_hash_value_error'
5
5
 
6
6
  module RegistersClient
7
7
  class RegisterClient
8
- def initialize(register_url, data_store, page_size)
8
+ def initialize(register_url, data_store, page_size, options = {})
9
9
  @register_url = register_url
10
10
  @data_store = data_store
11
11
  @page_size = page_size
12
+ @options = options
12
13
 
13
14
  refresh_data
14
15
  end
@@ -149,11 +150,11 @@ module RegistersClient
149
150
  if params[1] == 'user'
150
151
  user_entry_number += 1
151
152
 
152
- entry = Entry.new(line, user_entry_number, params[1])
153
+ entry = RegistersClient::Entry.new(line, user_entry_number, params[1])
153
154
  else
154
155
  system_entry_number += 1
155
156
 
156
- entry = Entry.new(line, system_entry_number, params[1])
157
+ entry = RegistersClient::Entry.new(line, system_entry_number, params[1])
157
158
  end
158
159
 
159
160
  data_store.append_entry(entry)
@@ -167,7 +168,13 @@ module RegistersClient
167
168
  end
168
169
 
169
170
  def register_http_request(path)
170
- RestClient.get(@register_url.merge(path).to_s)
171
+ headers = {}
172
+
173
+ unless @options[:api_key] == nil
174
+ headers[:Authorization] = @options[:api_key]
175
+ end
176
+
177
+ RestClient.get(@register_url.merge(path).to_s, headers)
171
178
  end
172
179
 
173
180
  def is_valid_hash_value(hash_value)
@@ -2,27 +2,25 @@ require 'register_client'
2
2
  require 'in_memory_data_store'
3
3
 
4
4
  module RegistersClient
5
- VERSION = '1.0.1'
5
+ VERSION = '1.1.1'
6
6
  class RegisterClientManager
7
7
  def initialize(config_options = {})
8
8
  @config_options = defaults.merge(config_options)
9
9
  @register_clients = {}
10
10
  end
11
11
 
12
- def get_register(register, phase, data_store = nil)
12
+ def get_register(register, phase, options = {})
13
13
  environment_url = get_environment_url_from_phase(phase)
14
- get_register_from_environment(register, environment_url, data_store)
14
+ get_register_from_environment(register, environment_url, options)
15
15
  end
16
16
 
17
- def get_register_from_environment(register, environment_url, data_store = nil)
17
+ def get_register_from_environment(register, environment_url, options = {})
18
18
  key = register + ':' + environment_url.to_s
19
19
 
20
20
  if !@register_clients.key?(key)
21
- if (data_store.nil?)
22
- data_store = RegistersClient::InMemoryDataStore.new(@config_options)
23
- end
24
-
21
+ data_store = options.has_key?(:data_store) ? options[:data_store] : RegistersClient::InMemoryDataStore.new(@config_options)
25
22
  register_url = get_register_url(register, environment_url)
23
+
26
24
  @register_clients[key] = create_register_client(register_url, data_store, @config_options.fetch(:page_size))
27
25
  end
28
26
 
@@ -33,12 +31,17 @@ module RegistersClient
33
31
 
34
32
  def defaults
35
33
  {
34
+ api_key: nil,
36
35
  page_size: 100
37
36
  }
38
37
  end
39
38
 
40
39
  def create_register_client(register_url, data_store, page_size)
41
- RegistersClient::RegisterClient.new(register_url, data_store, page_size)
40
+ register_options = {
41
+ api_key: @config_options[:api_key]
42
+ }
43
+
44
+ RegistersClient::RegisterClient.new(register_url, data_store, page_size, register_options)
42
45
  end
43
46
 
44
47
  def get_register_url(register, environment_url)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk-registers-api-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Registers Team (Government Digital Service)