dvla-dataverse-helper 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c62f1c6091fd89ee3bbd28f75b97a82853e1348ce7d9a37d2ea390fc93590978
4
+ data.tar.gz: f83274347d0ace2cf147bb91224cafa6bb88540ca3a746e48418569e2503cc04
5
+ SHA512:
6
+ metadata.gz: 4132b77d33cf26d9ed9ea8c770450fef369ff620fc301da08ff2d9f7bbe80fed2764c9be70bcbf20fe9e9bfbee4f7056d624184a71e8fbb4a2e95e2a0b30f135
7
+ data.tar.gz: fd6bb336f2556c0944d465639cbc0597e7f17fe95eef393b58658b82f37ef2ffaaf7197ca7112f031b436605466ecaab055e89c3073fe2c4b8fdd6de4ee8c9ef
data/Gemfile ADDED
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in dvla-dataverse-helper.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "oauth2", "~> 2.0"
13
+
14
+ gem "config", "~> 4.0"
15
+
16
+ gem "rest-client", "~> 2.1"
17
+
18
+ gem "colorize", "~> 0.8.1"
data/Gemfile.lock ADDED
@@ -0,0 +1,115 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ dvla-dataverse-helper (0.1.0)
5
+ colorize
6
+ config
7
+ oauth2 (~> 2.0)
8
+ rest-client (~> 2.1)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ colorize (0.8.1)
14
+ concurrent-ruby (1.1.10)
15
+ config (4.0.0)
16
+ deep_merge (~> 1.2, >= 1.2.1)
17
+ dry-validation (~> 1.0, >= 1.0.0)
18
+ deep_merge (1.2.2)
19
+ diff-lcs (1.5.0)
20
+ domain_name (0.5.20190701)
21
+ unf (>= 0.0.5, < 1.0.0)
22
+ dry-configurable (0.15.0)
23
+ concurrent-ruby (~> 1.0)
24
+ dry-core (~> 0.6)
25
+ dry-container (0.10.0)
26
+ concurrent-ruby (~> 1.0)
27
+ dry-core (0.8.0)
28
+ concurrent-ruby (~> 1.0)
29
+ dry-inflector (0.3.0)
30
+ dry-initializer (3.1.1)
31
+ dry-logic (1.2.0)
32
+ concurrent-ruby (~> 1.0)
33
+ dry-core (~> 0.5, >= 0.5)
34
+ dry-schema (1.9.3)
35
+ concurrent-ruby (~> 1.0)
36
+ dry-configurable (~> 0.13, >= 0.13.0)
37
+ dry-core (~> 0.5, >= 0.5)
38
+ dry-initializer (~> 3.0)
39
+ dry-logic (~> 1.0)
40
+ dry-types (~> 1.5)
41
+ dry-types (1.5.1)
42
+ concurrent-ruby (~> 1.0)
43
+ dry-container (~> 0.3)
44
+ dry-core (~> 0.5, >= 0.5)
45
+ dry-inflector (~> 0.1, >= 0.1.2)
46
+ dry-logic (~> 1.0, >= 1.0.2)
47
+ dry-validation (1.8.1)
48
+ concurrent-ruby (~> 1.0)
49
+ dry-container (~> 0.7, >= 0.7.1)
50
+ dry-core (~> 0.5, >= 0.5)
51
+ dry-initializer (~> 3.0)
52
+ dry-schema (~> 1.8, >= 1.8.0)
53
+ faraday (2.3.0)
54
+ faraday-net_http (~> 2.0)
55
+ ruby2_keywords (>= 0.0.4)
56
+ faraday-net_http (2.0.3)
57
+ hashie (5.0.0)
58
+ http-accept (1.7.0)
59
+ http-cookie (1.0.5)
60
+ domain_name (~> 0.5)
61
+ jwt (2.4.1)
62
+ mime-types (3.4.1)
63
+ mime-types-data (~> 3.2015)
64
+ mime-types-data (3.2022.0105)
65
+ multi_xml (0.6.0)
66
+ netrc (0.11.0)
67
+ oauth2 (2.0.6)
68
+ faraday (>= 0.17.3, < 3.0)
69
+ jwt (>= 1.0, < 3.0)
70
+ multi_xml (~> 0.5)
71
+ rack (>= 1.2, < 3)
72
+ rash_alt (>= 0.4, < 1)
73
+ version_gem (~> 1.1)
74
+ rack (2.2.4)
75
+ rake (13.0.6)
76
+ rash_alt (0.4.12)
77
+ hashie (>= 3.4)
78
+ rest-client (2.1.0)
79
+ http-accept (>= 1.7.0, < 2.0)
80
+ http-cookie (>= 1.0.2, < 2.0)
81
+ mime-types (>= 1.16, < 4.0)
82
+ netrc (~> 0.8)
83
+ rspec (3.11.0)
84
+ rspec-core (~> 3.11.0)
85
+ rspec-expectations (~> 3.11.0)
86
+ rspec-mocks (~> 3.11.0)
87
+ rspec-core (3.11.0)
88
+ rspec-support (~> 3.11.0)
89
+ rspec-expectations (3.11.0)
90
+ diff-lcs (>= 1.2.0, < 2.0)
91
+ rspec-support (~> 3.11.0)
92
+ rspec-mocks (3.11.1)
93
+ diff-lcs (>= 1.2.0, < 2.0)
94
+ rspec-support (~> 3.11.0)
95
+ rspec-support (3.11.0)
96
+ ruby2_keywords (0.0.5)
97
+ unf (0.1.4)
98
+ unf_ext
99
+ unf_ext (0.0.8.2)
100
+ version_gem (1.1.0)
101
+
102
+ PLATFORMS
103
+ x86_64-darwin-21
104
+
105
+ DEPENDENCIES
106
+ colorize (~> 0.8.1)
107
+ config (~> 4.0)
108
+ dvla-dataverse-helper!
109
+ oauth2 (~> 2.0)
110
+ rake (~> 13.0)
111
+ rest-client (~> 2.1)
112
+ rspec (~> 3.0)
113
+
114
+ BUNDLED WITH
115
+ 2.3.20
data/README.md ADDED
@@ -0,0 +1,62 @@
1
+ <div align="center">
2
+ <img alt="gem logo" src="/docs/lego.png">
3
+ </div>
4
+
5
+ ## Dvla Dataverse Helper
6
+ ##### _Integrate Microsoft Dataverse Web API to your Ruby project_
7
+
8
+
9
+ Thank you for using DVLA Dataverse Helper gem. This gem helps you integrate with Microsoft Dynamics using Microsoft Dataverse Web API. You can create, retrieve, delete or update a record without worrying about authentications as it's automatically managed behind the scenes.
10
+
11
+
12
+ | 🏁 Installation & Getting statrted |
13
+ | ----------------------------------------- |
14
+
15
+
16
+ Install the gem and add to the application's Gemfile by executing:
17
+
18
+ $ bundle add dvla-dataverse-helper
19
+
20
+ If bundler is not being used to manage dependencies, install the gem by executing:
21
+
22
+ $ gem install dvla-dataverse-helper
23
+
24
+ You can set up a template for your configurations by executing:
25
+
26
+ $ dataverse
27
+
28
+ which will create a new yml file inside `config` folder called dataverse.yml. You will need to update the configurations before using the gem.
29
+
30
+
31
+ | 👔 Usage and examples |
32
+ | ----------------------------------------- |
33
+
34
+ Its recommended to have a constant for your Helper model:
35
+ ```ruby
36
+ Dataverse = Dvla::Dataverse::Helper
37
+ ```
38
+
39
+ The Dataverse helper makes it easy to create, update, retrieve and delete a record. The authentication happens automatically only if it's needed. For example, if the token is expired the Dataverse helper will set up a new token before making a request. To create a record:
40
+
41
+ ```ruby
42
+ Dataverse
43
+ .create_record('incidents', record)
44
+ .body
45
+ ```
46
+
47
+
48
+ | 🛠 Development |
49
+ | ----------------------------------------- |
50
+
51
+
52
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
53
+
54
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
55
+
56
+ | 📃 License |
57
+ | ----------------------------------------- |
58
+
59
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
60
+
61
+
62
+
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/docs/.DS_Store ADDED
Binary file
data/docs/lego.png ADDED
Binary file
data/exe/dataverse ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'colorize'
5
+
6
+ setting_file = <<SETTING_FILE
7
+ dataverse:
8
+ authorize_url:
9
+ token_url:
10
+ client_id:
11
+ client_secret:
12
+ scope:
13
+ operations:
14
+ base_url:
15
+ service_check_url:
16
+
17
+ SETTING_FILE
18
+
19
+ puts ">> Go to setting.yml to update the configuration".colorize(:blue)
20
+
21
+ Dir.mkdir('./config') unless File.exists?('./config')
22
+ File.open('./config/dataverse.yml', 'w') { |f| f.write(setting_file) }
23
+
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dvla
4
+ module Dataverse
5
+ module Helper
6
+ VERSION = "0.1.0"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "support/authenticator"
4
+ require_relative "operations/service_check"
5
+ require_relative "operations/retrieve_records"
6
+ require_relative "operations/create_records"
7
+ require_relative "operations/delete_records"
8
+ require_relative 'operations/update_records'
9
+
10
+ require_relative "helper/version"
11
+ require 'oauth2'
12
+ require 'config'
13
+ require 'logger'
14
+
15
+ require 'yaml'
16
+
17
+ module Dvla
18
+ module Dataverse
19
+ module Helper
20
+ class Error < StandardError; end
21
+
22
+ # Get all the records as an array. If no records is found, this function will throw
23
+ # http 404 error. You can retrieve sub-records using the filter. You can only set
24
+ # the maximum records to be return if specify the record name
25
+ #
26
+ # @example
27
+ # ex.get_all_records
28
+ # ex.get_all_records(record_name: 'emails')
29
+ # ex.get_all_records(record_name: 'emails', max_return: 3)
30
+ #
31
+ # @raise 404 Not Found
32
+ #
33
+ # @param [String] record_name the name of the record
34
+ # @param [Int] max_return the number of records to be returned
35
+ # @return [Array] the list of records
36
+ def self.retrieve_record(record_name: nil, max_return: nil)
37
+ RetrieveRecords
38
+ .new
39
+ .get_records(record_name: record_name, max_return: max_return)
40
+ end
41
+
42
+ # create a new record. You must provide the record name and the record
43
+ # payload/data. The payload/data must be a hash
44
+ #
45
+ # @example
46
+ # payload = {email => 'email@example.com'}
47
+ # new_record('user', payload)
48
+ #
49
+ # @param [String] record_name the name of the record
50
+ # @param [Hash] record_data the record payload
51
+ def self.create_record(record_name, record_data)
52
+ CreateRecords
53
+ .new
54
+ .new_record(record_name, record_data)
55
+ end
56
+
57
+ # remove the record. You must provide the record ID and the record name. The record
58
+ # ID and the record name should be string
59
+ #
60
+ # @example
61
+ # remove_record('user', '123-123-123')
62
+ #
63
+ # @param [String] record_name the name of the record
64
+ # @param [String] record_id the record ID usually its UUID
65
+ def self.delete_record(record_name, record_id)
66
+ DeleteRecord
67
+ .new
68
+ .remove_record(record_name, record_id)
69
+ end
70
+
71
+ # update the record. You must provide the record name, the record ID, and
72
+ # the record data.
73
+ #
74
+ # @example
75
+ # payload = {email => 'email@example.com'}
76
+ # alter_record('user', '123-123-123', payload)
77
+ #
78
+ # @param [String] record_name the name of the record
79
+ # @param [String] record_id the record ID usually its UUID
80
+ # @param [Hash] record_data the record payload
81
+ def self.update_record(record_name, record_id, record_data)
82
+ UpdateRecord
83
+ .new
84
+ .alter_record(record_name, record_id, record_data)
85
+ end
86
+
87
+ # check if the service is online, also, check if the connection is established without
88
+ # and error.
89
+ def self.service_check
90
+ ServiceCheck
91
+ .new
92
+ .send_request
93
+ end
94
+
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,32 @@
1
+ require_relative './dataverse_operations'
2
+
3
+ class CreateRecords < DataverseOperations
4
+
5
+ def setup_artifacts
6
+ setup_http_headers
7
+ http_request_artifacts.url = get_url_from_config_file
8
+ http_request_artifacts.method = :post
9
+ end
10
+
11
+ # create a new record. You must provide the record name and the record
12
+ # payload/data. The payload/data must be a hash
13
+ #
14
+ # @example
15
+ # payload = {email => 'email@example.com'}
16
+ # new_record('user', payload)
17
+ #
18
+ # @param [String] record_name the name of the record
19
+ # @param [Hash] record_data the record payload
20
+ def new_record(record_name, record_data)
21
+ setup_http_payload(record_data)
22
+ apply_filter({ record_name: record_name })
23
+
24
+ send_request
25
+ end
26
+
27
+ private
28
+
29
+ def setup_http_payload(payload)
30
+ http_request_artifacts.payload = payload.to_json
31
+ end
32
+ end
@@ -0,0 +1,88 @@
1
+ require 'logger'
2
+ require 'rest-client'
3
+ require_relative "../support/authenticator"
4
+
5
+ class DataverseOperations
6
+ Struct.new('HttpRequestArtifacts',
7
+ :headers,
8
+ :url,
9
+ :method,
10
+ :payload) do
11
+ end
12
+
13
+ def initialize
14
+ Authenticator.instance.setup_authentication_configs
15
+
16
+ setup_artifacts
17
+ end
18
+
19
+ def setup_artifacts
20
+ raise NotImplementedError, "#{self.class} method '#{__method__} has not been implemented'"
21
+ end
22
+
23
+ # load the url from the configuration yml file. You should overwrite this
24
+ # function if you dont dont want to use the base url
25
+ #
26
+ # @raise
27
+ # this function will throw an error if no url is found under
28
+ # dataverse:operations:base:url
29
+ #
30
+ # @return [String] base url
31
+ def get_url_from_config_file
32
+ url = Settings&.dataverse&.operations&.base_url
33
+ url.nil? ? raise('base url is missing from the configuration file') : url
34
+ end
35
+
36
+ # HttpRequestArtifacts is to store the artifacts needed to make the
37
+ # http request.
38
+ # headers: for the request headers, should be a hash
39
+ # url: the url to make the request, should be string
40
+ # method: the http method, for example :post
41
+ # payload: the body of the request if any
42
+ #
43
+ # @return [Struct::HttpRequestArtifacts]
44
+ def http_request_artifacts
45
+ @http_request_artifacts ||= Struct::HttpRequestArtifacts.new
46
+ end
47
+
48
+ # set up the request headers. this will also call +@@authenticator+ to
49
+ # get the authorization token
50
+ #
51
+ # @return [Hash{String->Float or String}]
52
+ def setup_http_headers
53
+ headers = { 'If-None-Match' => nil,
54
+ 'OData-Version' => 4.0,
55
+ 'Content-Type' => 'application/json',
56
+ 'Accept' => 'application/json',
57
+ 'OData-MaxVersion' => 4.0,
58
+ 'Authorization' => Authenticator.instance.get_token }
59
+
60
+ http_request_artifacts.headers = headers
61
+ end
62
+
63
+ # Send http request. Make sure that +http_request_artifacts+ is setup
64
+ # with url, headers, http method and payload if needed
65
+ #
66
+ # @return [RestClient] RestClient response
67
+ def send_request
68
+ RestClient::Request.execute(method: http_request_artifacts.method,
69
+ url: http_request_artifacts.url,
70
+ headers: http_request_artifacts.headers,
71
+ payload: http_request_artifacts.payload)
72
+ end
73
+
74
+ # Set up the filter to be in the url query string. The filter only be the name
75
+ # of the record, the maximum number of records to be retrieved and the
76
+ # record id.
77
+ #
78
+ # @param [Object] options the record name and max returned records
79
+ def apply_filter(options)
80
+ max_number_of_records = options[:top] ? "?$top=#{options[:top]}" : ''
81
+ record_id = options[:id] ? "(#{options[:id]})" : ''
82
+ record_nam = options[:record_name]
83
+ url = http_request_artifacts.url
84
+
85
+ http_request_artifacts.url = "#{url}#{record_nam}#{max_number_of_records}#{record_id}"
86
+ end
87
+
88
+ end
@@ -0,0 +1,28 @@
1
+ require_relative './dataverse_operations'
2
+
3
+ class DeleteRecord < DataverseOperations
4
+
5
+ def setup_artifacts
6
+ setup_http_headers
7
+ http_request_artifacts.url = get_url_from_config_file
8
+ http_request_artifacts.method = :DELETE
9
+ end
10
+
11
+ # remove the record. You must provide the record ID and the record name. The record
12
+ # ID and the record name should be string
13
+ #
14
+ # @example
15
+ # remove_record('user', '123-123-123')
16
+ #
17
+ # @param [String] record_name the name of the record
18
+ # @param [String] record_id the record ID usually its UUID
19
+ def remove_record(record_name, record_id)
20
+ apply_filter({
21
+ record_name: record_name,
22
+ id: record_id
23
+ })
24
+
25
+ send_request
26
+ end
27
+
28
+ end
@@ -0,0 +1,39 @@
1
+ require_relative './dataverse_operations'
2
+
3
+ class RetrieveRecords < DataverseOperations
4
+
5
+ def setup_artifacts
6
+ setup_http_headers
7
+ http_request_artifacts.url = get_url_from_config_file
8
+ http_request_artifacts.method = :get
9
+ end
10
+
11
+ # Get all the records as an array. If no records is found, this function will throw
12
+ # http 404 error. You can retrieve sub-records using the filter. You can only set
13
+ # the maximum records to be return if specify the record name
14
+ #
15
+ # @example
16
+ # ex.get_all_records
17
+ # ex.get_all_records(record_name: 'emails')
18
+ # ex.get_all_records(record_name: 'emails', max_return: 3)
19
+ #
20
+ # @raise 404 Not Found
21
+ #
22
+ # @param [String] record_name the name of the record
23
+ # @param [Int] max_return the number of records to be returned
24
+ # @return [Array] the list of records
25
+ def get_records(record_name: nil, max_return: nil)
26
+ unless record_name.nil?
27
+ apply_filter({
28
+ record_name: record_name,
29
+ top: max_return
30
+ })
31
+ end
32
+
33
+ send_request
34
+ &.body
35
+ .then { |response| JSON.parse(response) if response }
36
+ .then { |values| values['value'] || values }
37
+ end
38
+
39
+ end
@@ -0,0 +1,16 @@
1
+ require_relative './dataverse_operations'
2
+
3
+ class ServiceCheck < DataverseOperations
4
+
5
+ def setup_artifacts
6
+ setup_http_headers
7
+ http_request_artifacts.url = get_url_from_config_file
8
+ http_request_artifacts.method = :get
9
+ end
10
+
11
+ def get_url_from_config_file
12
+ url = Settings&.dataverse&.operations&.service_check_url
13
+ url.nil? ? raise('service_check url is missing from the configuration file') : url
14
+ end
15
+
16
+ end
@@ -0,0 +1,35 @@
1
+ require_relative './dataverse_operations'
2
+
3
+ class UpdateRecord < DataverseOperations
4
+
5
+ def setup_artifacts
6
+ setup_http_headers
7
+ http_request_artifacts.url = get_url_from_config_file
8
+ http_request_artifacts.method = :patch
9
+ end
10
+
11
+ # update the record. You must provide the record name, the record ID, and
12
+ # the record data.
13
+ #
14
+ # @example
15
+ # payload = {email => 'email@example.com'}
16
+ # alter_record('user', '123-123-123', payload)
17
+ #
18
+ # @param [String] record_name the name of the record
19
+ # @param [String] record_id the record ID usually its UUID
20
+ # @param [Hash] record_data the record payload
21
+ def alter_record(record_name, record_id, record_data)
22
+ setup_http_payload(record_data)
23
+ apply_filter({ record_name: record_name,
24
+ id: record_id })
25
+
26
+ send_request
27
+ end
28
+
29
+ private
30
+
31
+ def setup_http_payload(payload)
32
+ http_request_artifacts.payload = payload.to_json
33
+ end
34
+
35
+ end
@@ -0,0 +1,159 @@
1
+ # frozen_string_literal: true
2
+ require 'oauth2'
3
+ require 'singleton'
4
+
5
+ class Authenticator
6
+ include Singleton
7
+
8
+ Struct.new('AuthenticatorConfig',
9
+ :authorize_url,
10
+ :token_url,
11
+ :client_id,
12
+ :client_secret,
13
+ :scope,
14
+ :latest_token) do
15
+ end
16
+
17
+ # This function will setup the token using the client credentials only if the token
18
+ # is null or expired. Otherwise, the same token will be returned.
19
+ #
20
+ # @note
21
+ # Be sure to call +setup_authentication_configs+ to setup the configuration
22
+ # before calling +get_token+
23
+ #
24
+ # @example
25
+ # authenticator.setup_authentication_configs
26
+ # authenticator.get_token
27
+ #
28
+ # @return [String] access token
29
+ def get_token
30
+ client = setup_client
31
+ token = authenticator_config.latest_token
32
+ time_now = Time.now.to_i
33
+
34
+ if token.nil? || token.expires_at <= time_now
35
+ client
36
+ .client_credentials
37
+ .get_token(params = { :scope => authenticator_config.scope })
38
+ .then { |token| authenticator_config.latest_token = token }
39
+ end
40
+
41
+ authenticator_config.latest_token.token
42
+ end
43
+
44
+ # Setup the configuration for +AuthenticatorConfig+. call this function
45
+ # before using +get_token+.
46
+ #
47
+ # @example
48
+ # authenticator.setup_authentication_configs
49
+ # authenticator.get_token
50
+ #
51
+ # @note
52
+ # This function is void
53
+ def setup_authentication_configs
54
+ [config_auth_url, config_token_url, config_client_id, config_client_secret, config_scope].each(&:call)
55
+ end
56
+
57
+ def authenticator_config
58
+ @authenticator_config ||= Struct::AuthenticatorConfig.new
59
+ end
60
+
61
+ private
62
+
63
+ # Setup the client to be used by +get_token+. If the client is not null, it will
64
+ # return the same client. This function make use of +authenticator_config+. be
65
+ # sure to have the configuration setup before calling +get_token+
66
+ #
67
+ # @return [OAuth2::Client] connection client
68
+ def setup_client
69
+ options = {
70
+ :authorize_url => authenticator_config.authorize_url,
71
+ :token_url => authenticator_config.token_url
72
+ }
73
+
74
+ @client ||= OAuth2::Client.new(authenticator_config.client_id,
75
+ authenticator_config.client_secret,
76
+ options)
77
+ end
78
+
79
+ # This function will return a lambda function to set the authorize_url in
80
+ # the +AuthenticatorConfig+. The value will be retrieved from the
81
+ # setting file
82
+ #
83
+ # @raise error if the authorize_url missing from the setting file
84
+ #
85
+ # @return [lambda] set the authorize_url
86
+ def config_auth_url
87
+ _ = -> do
88
+ url = Settings&.dataverse&.authorize_url
89
+ authenticator_config.authorize_url = url
90
+
91
+ raise 'The dataverse authorize_url is missing' if url.nil? || url.empty?
92
+ end
93
+ end
94
+
95
+ # This function will return a lambda function to set the token_url in
96
+ # the +AuthenticatorConfig+. The value will be retrieved from the
97
+ # setting file
98
+ #
99
+ # @raise error if the token_url missing from the setting file
100
+ #
101
+ # @return [lambda] set the token_url
102
+ def config_token_url
103
+ _ = -> do
104
+ url = Settings&.dataverse&.token_url
105
+ authenticator_config.token_url = url
106
+
107
+ raise 'The dataverse token_url is missing' if url.nil? || url.empty?
108
+ end
109
+ end
110
+
111
+ # This function will return a lambda function to set the client_id in
112
+ # the +AuthenticatorConfig+. The value will be retrieved from the
113
+ # setting file
114
+ #
115
+ # @raise error if the client_id missing from the setting file
116
+ #
117
+ # @return [lambda] set the client_id
118
+ def config_client_id
119
+ _ = -> do
120
+ id = Settings&.dataverse&.client_id
121
+ authenticator_config.client_id = id
122
+
123
+ raise 'The dataverse client_id is missing' if id.nil? || id.empty?
124
+ end
125
+ end
126
+
127
+ # This function will return a lambda function to set the client_secret in
128
+ # the +AuthenticatorConfig+. The value will be retrieved from the
129
+ # setting file
130
+ #
131
+ # @raise error if the client_secret missing from the setting file
132
+ #
133
+ # @return [lambda] set the client_secret
134
+ def config_client_secret
135
+ _ = -> do
136
+ secret = Settings&.dataverse&.client_secret
137
+ authenticator_config.client_secret = secret
138
+
139
+ raise 'The dataverse client_secret is missing' if secret.nil? || secret.empty?
140
+ end
141
+ end
142
+
143
+ # This function will return a lambda function to set the scope in
144
+ # the +AuthenticatorConfig+. The value will be retrieved from the
145
+ # setting file
146
+ #
147
+ # @raise error if the scope missing from the setting file
148
+ #
149
+ # @return [lambda] set the scope
150
+ def config_scope
151
+ _ = -> do
152
+ scope = Settings&.dataverse&.scope
153
+ authenticator_config.scope = scope
154
+
155
+ raise 'The dataverse scope is missing' if scope.nil? || scope.empty?
156
+ end
157
+ end
158
+
159
+ end
@@ -0,0 +1,8 @@
1
+ module Dvla
2
+ module Dataverse
3
+ module Helper
4
+ VERSION: String
5
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
6
+ end
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dvla-dataverse-helper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Abdullah Janjua
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-10-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: oauth2
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rest-client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: colorize
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: config
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: This gem helps you integrate Microsoft Dataverse Web API to your ruby
70
+ project
71
+ email:
72
+ - Abdullah.Janjua@dvla.gov.uk
73
+ executables:
74
+ - dataverse
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - Gemfile
79
+ - Gemfile.lock
80
+ - README.md
81
+ - Rakefile
82
+ - docs/.DS_Store
83
+ - docs/lego.png
84
+ - exe/dataverse
85
+ - lib/dvla/dataverse/helper.rb
86
+ - lib/dvla/dataverse/helper/version.rb
87
+ - lib/dvla/dataverse/operations/create_records.rb
88
+ - lib/dvla/dataverse/operations/dataverse_operations.rb
89
+ - lib/dvla/dataverse/operations/delete_records.rb
90
+ - lib/dvla/dataverse/operations/retrieve_records.rb
91
+ - lib/dvla/dataverse/operations/service_check.rb
92
+ - lib/dvla/dataverse/operations/update_records.rb
93
+ - lib/dvla/dataverse/support/authenticator.rb
94
+ - sig/dvla/dataverse/helper.rbs
95
+ homepage: https://bitbucket.tooling.dvla.gov.uk/projects/QE/repos/dvla-dataverse-helper
96
+ licenses: []
97
+ metadata:
98
+ homepage_uri: https://bitbucket.tooling.dvla.gov.uk/projects/QE/repos/dvla-dataverse-helper
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: 2.6.0
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubygems_version: 3.2.33
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Integrate Microsoft Dataverse Web API to your project
118
+ test_files: []