fdp_client 0.0.2

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 40cb339a04805d24f89099a2d412cfa37b4d2efd049f556429f68d9836841713
4
+ data.tar.gz: baafe98a63217640b99856020b3ed2895c904fc00a54517ff8b6ace9c1be3581
5
+ SHA512:
6
+ metadata.gz: f12b2d06b1411f5a53484274e0b22f6bd6f859efc50074bf15e44b7bb36dbcb91075a68bec025cb8a7bdf912471d22d9a3e4cea2f468bb1a5da85a984ee261a3
7
+ data.tar.gz: d9a87965115568695962efb6175f43e5a445af22fa6972c646c92eb7906b42b2eda53f1d94e9e64fbc17db5e50a825af69eeb6115bb06117cb7248ea91455994
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.2.4
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-05-25
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in fdp_mate.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "rubocop", "~> 1.21"
13
+
14
+ gem "rest_client", "~> 8.0"
15
+
16
+ gem "json", "~> 2.6"
data/Gemfile.lock ADDED
@@ -0,0 +1,60 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ fdp_client (0.0.2)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ diff-lcs (1.5.0)
11
+ json (2.6.2)
12
+ parallel (1.22.1)
13
+ parser (3.2.2.1)
14
+ ast (~> 2.4.1)
15
+ rainbow (3.1.1)
16
+ rake (13.0.6)
17
+ regexp_parser (2.5.0)
18
+ rest_client (8.0.0)
19
+ rexml (3.2.5)
20
+ rspec (3.11.0)
21
+ rspec-core (~> 3.11.0)
22
+ rspec-expectations (~> 3.11.0)
23
+ rspec-mocks (~> 3.11.0)
24
+ rspec-core (3.11.0)
25
+ rspec-support (~> 3.11.0)
26
+ rspec-expectations (3.11.0)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.11.0)
29
+ rspec-mocks (3.11.1)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.11.0)
32
+ rspec-support (3.11.0)
33
+ rubocop (1.51.0)
34
+ json (~> 2.3)
35
+ parallel (~> 1.10)
36
+ parser (>= 3.2.0.0)
37
+ rainbow (>= 2.2.2, < 4.0)
38
+ regexp_parser (>= 1.8, < 3.0)
39
+ rexml (>= 3.2.5, < 4.0)
40
+ rubocop-ast (>= 1.28.0, < 2.0)
41
+ ruby-progressbar (~> 1.7)
42
+ unicode-display_width (>= 2.4.0, < 3.0)
43
+ rubocop-ast (1.28.1)
44
+ parser (>= 3.2.1.0)
45
+ ruby-progressbar (1.11.0)
46
+ unicode-display_width (2.4.2)
47
+
48
+ PLATFORMS
49
+ x86_64-linux
50
+
51
+ DEPENDENCIES
52
+ fdp_client!
53
+ json (~> 2.6)
54
+ rake (~> 13.0)
55
+ rest_client (~> 8.0)
56
+ rspec (~> 3.0)
57
+ rubocop (~> 1.21)
58
+
59
+ BUNDLED WITH
60
+ 4.0.3
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Mark Wilkinson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # FdpMate
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/fdp_mate`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Install the gem and add to the application's Gemfile by executing:
10
+
11
+ $ bundle add fdp_mate
12
+
13
+ If bundler is not being used to manage dependencies, install the gem by executing:
14
+
15
+ $ gem install fdp_mate
16
+
17
+ ## Usage
18
+
19
+ TODO: Write usage instructions here
20
+
21
+ ## Development
22
+
23
+ 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.
24
+
25
+ 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).
26
+
27
+ ## Contributing
28
+
29
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/fdp_mate.
30
+
31
+ ## License
32
+
33
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
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]
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "fdp_client"
5
+ spec.version = "0.0.2"
6
+ spec.authors = ["Mark Wilkinson"]
7
+ spec.email = ["markw@illuminae.com"]
8
+
9
+ spec.summary = "Gem for interacting with FAIR Data Point reference implementation (only!)."
10
+ spec.homepage = "https://github.com/markwilkinson/FDP-Client-Ruby"
11
+ spec.license = "MIT"
12
+ spec.required_ruby_version = ">= 3.2.4"
13
+
14
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://github.com/markwilkinson/FDP-Client-Ruby"
18
+ spec.metadata["changelog_uri"] = "https://github.com/markwilkinson/FDP-Client-Ruby/CHANGELOG.md"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(__dir__) do
23
+ `git ls-files -z`.split("\x0").reject do |f|
24
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
25
+ end
26
+ end
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ # For more information and examples about making a new gem, check out our
32
+ # guide at: https://bundler.io/guides/creating_gem.html
33
+ end
@@ -0,0 +1,53 @@
1
+ module FDPMate
2
+ class DCATDataService < DCATResource
3
+ attr_accessor :endpointDescription, :endpointURL
4
+
5
+ def initialize(parent:, endpointDescription: nil, endpointURL: nil, **args)
6
+ super(**args)
7
+ @endpointDescription = endpointDescription
8
+ @endpointURL = endpointURL
9
+
10
+ warn "Building Data Service"
11
+ warn self.endpointDescription, self.endpointURL, self.class
12
+
13
+ self.types = [DCAT.Resource, DCAT.DataService]
14
+ init_accessService # create record and get GUID
15
+ build # make the RDF
16
+ write_accessService
17
+ parent.accessServices << self
18
+ end
19
+
20
+ def init_accessService
21
+ warn "initializing access Service"
22
+ asinit = <<~END
23
+ @prefix dcat: <http://www.w3.org/ns/dcat#> .
24
+ @prefix dct: <http://purl.org/dc/terms/> .
25
+ @prefix foaf: <http://xmlns.com/foaf/0.1/> .
26
+ <> a dcat:DataService ;
27
+ foaf:name "test" ;
28
+ dct:title "test" ;
29
+ dct:hasVersion "1.0" ;
30
+ dcat:endpointURL <https://example.org> ;
31
+ dct:publisher [ a foaf:Agent ; foaf:name "Example User" ] ;
32
+ dct:isPartOf <#{@parentURI}> .
33
+ END
34
+
35
+ warn "#{serverURL}/dataService"
36
+ # warn "#{asinit}\n\n"
37
+ resp = RestClient.post("#{serverURL}/dataService", asinit, $headers)
38
+ aslocation = resp.headers[:location]
39
+ puts "temporary distribution written to #{aslocation}\n\n"
40
+ self.identifier = RDF::URI(aslocation) # set identifier to where it lives
41
+ end
42
+
43
+ def write_accessService
44
+ build
45
+ location = identifier.to_s.gsub(baseURI, serverURL)
46
+ warn "rewriting access service to #{location}"
47
+ ds = serialize
48
+ # warn ds
49
+ resp = RestClient.put(location, ds, $headers)
50
+ warn resp.headers
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,56 @@
1
+ module FDPMate
2
+ class DCATCatalog < DCATResource
3
+ attr_accessor :primaryTopic, :datasets, :themeTaxonomy, :accessServices
4
+
5
+ # def initialize(primary_topic: nil, baseuri: "http://example.org", access_rights: nil, conforms_to: nil, contact_point: nil, resource_creator: nil,
6
+ # title: nil, release_date: nil, modification_date: nil, publisher: nil, identifier: nil, license: nil )
7
+ def initialize(themeTaxonomy: nil, **args)
8
+ super
9
+ # warn "initialize"
10
+ @datasets = []
11
+ @accessServices = []
12
+ @themeTaxonomy = themeTaxonomy
13
+ self.types = [DCAT.Catalog, DCAT.Resource]
14
+ init_catalog # create record and get GUID
15
+ build # make the RDF
16
+ write_catalog
17
+ end
18
+
19
+ def init_catalog
20
+ warn "initializing catalog"
21
+ catinit = <<~END
22
+ @prefix dcat: <http://www.w3.org/ns/dcat#> .
23
+ @prefix dct: <http://purl.org/dc/terms/> .
24
+ @prefix foaf: <http://xmlns.com/foaf/0.1/> .
25
+
26
+ <> a dcat:Catalog, dcat:Resource ;
27
+ dct:title "test" ;
28
+ dct:hasVersion "1.0" ;
29
+ dct:publisher [ a foaf:Agent ; foaf:name "Example User" ] ;
30
+ dct:isPartOf <#{@parentURI}> .
31
+ END
32
+
33
+ warn "#{serverURL}/catalog\n\n"
34
+ # warn "#{catinit}\n\n"
35
+ # $stderr.puts catinit
36
+ resp = RestClient.post("#{serverURL}/catalog", catinit, $headers)
37
+ catlocation = resp.headers[:location]
38
+ warn "temporary catalog written to #{catlocation}\n\n"
39
+ self.identifier = RDF::URI(catlocation) # set identifier to where it lives
40
+ end
41
+
42
+ def write_catalog
43
+ build
44
+ location = identifier.to_s.gsub(baseURI, serverURL)
45
+ warn "rewriting cat to #{location}"
46
+ catalog = serialize
47
+ # warn catalog
48
+ resp = RestClient.put(location, catalog, $headers)
49
+ warn resp.headers
50
+ end
51
+
52
+ def add_dataset(dataset:)
53
+ @datasets << dataset
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,59 @@
1
+ module FDPMate
2
+ class DCATDataset < DCATResource
3
+ attr_accessor :was_generated_by, :distribution, :theme, :landingPage, :distributions
4
+
5
+ def initialize(parent_catalog:, theme: nil, landingPage: nil, **args)
6
+ super
7
+ @theme = theme
8
+ @landingPage = landingPage
9
+ @distributions = []
10
+
11
+ self.types = [DCAT.Resource, DCAT.Dataset]
12
+
13
+ init_dataset # create record and get GUID
14
+ build # make the RDF
15
+ write_dataset
16
+ parent_catalog.datasets << self
17
+ end
18
+
19
+ def init_dataset
20
+ warn "initializing dataset"
21
+ dsetinit = <<~END
22
+ @prefix dcat: <http://www.w3.org/ns/dcat#> .
23
+ @prefix dct: <http://purl.org/dc/terms/> .
24
+ @prefix foaf: <http://xmlns.com/foaf/0.1/> .
25
+ <> a dcat:Dataset, dcat:Resource ;
26
+ dct:title "test" ;
27
+ dct:hasVersion "1.0" ;
28
+ dct:publisher [ a foaf:Agent ; foaf:name "Example User" ] ;
29
+ dcat:theme <http://exampletheme.org/> ;
30
+ dct:isPartOf <#{@parentURI}> .
31
+ END
32
+
33
+ warn "#{@serverURL}/dataset"
34
+ warn "#{dsetinit}\n\n"
35
+ warn dsetinit
36
+ resp = RestClient.post("#{@serverURL}/dataset", dsetinit, $headers)
37
+ dsetlocation = resp.headers[:location]
38
+ puts "temporary dataset written to #{dsetlocation}\n\n"
39
+ self.identifier = RDF::URI(dsetlocation) # set identifier to where it lives
40
+ end
41
+
42
+ def write_dataset
43
+ build
44
+ location = identifier.to_s.gsub(baseURI, serverURL)
45
+ warn "rewriting dset to #{location}"
46
+ dataset = serialize
47
+ warn dataset
48
+ resp = RestClient.put(location, dataset, $headers)
49
+ warn resp.headers
50
+ end
51
+
52
+ # def datasets
53
+ # return $datasets
54
+ # end
55
+ # def self.datasets
56
+ # return $datasets
57
+ # end
58
+ end
59
+ end
@@ -0,0 +1,55 @@
1
+ module FDPMate
2
+ class DCATDistribution < DCATResource
3
+ attr_accessor :mediaType, :format, :accessServices
4
+
5
+ def initialize(parent_dataset:, mediaType: nil, format: nil, **args)
6
+ @accessServices = []
7
+ @mediaType = mediaType
8
+ @format = format
9
+
10
+ super
11
+
12
+ self.types = [DCAT.Resource, DCAT.Distribution]
13
+ init_distribution # create record and get GUID
14
+ build # make the RDF
15
+ write_distribution
16
+ parent_dataset.distributions << self
17
+ end
18
+
19
+ def init_distribution
20
+ warn "initializing distribution"
21
+ distinit = <<~END
22
+ @prefix dcat: <http://www.w3.org/ns/dcat#> .
23
+ @prefix dct: <http://purl.org/dc/terms/> .
24
+ @prefix foaf: <http://xmlns.com/foaf/0.1/> .
25
+ <> a dcat:Distribution, dcat:Resource ;
26
+ dct:title "test" ;
27
+ dct:hasVersion "1.0" ;
28
+ dct:publisher [ a foaf:Agent ; foaf:name "Example User" ] ;
29
+ dct:isPartOf <#{@parentURI}> ;
30
+ dcat:mediaType "text/plain" .
31
+ END
32
+
33
+ warn "#{serverURL}/distribution"
34
+ warn "#{distinit}\n\n"
35
+ resp = RestClient.post("#{@serverURL}/distribution", distinit, $headers)
36
+ distlocation = resp.headers[:location]
37
+ puts "temporary distribution written to #{distlocation}\n\n"
38
+ self.identifier = RDF::URI(distlocation) # set identifier to where it lives
39
+ end
40
+
41
+ def write_distribution
42
+ build
43
+ location = identifier.to_s.gsub(@baseURI, @serverURL)
44
+ warn "rewriting distribution to #{location}"
45
+ distribution = serialize
46
+ warn distribution
47
+ resp = RestClient.put(location, distribution, $headers)
48
+ warn resp.headers
49
+ end
50
+
51
+ def add_accessService(accessService:)
52
+ @accessServices << accessService
53
+ end
54
+ end
55
+ end