nice 0.0.7 → 0.1.0

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: 453be594423ebb52c2d2f79176d99ccf45978a186866c05b95865570753b2af4
4
+ data.tar.gz: 94dd016e6281da05dcc3ec203069c6618d47930a9b021357c1eac76e547daf3b
5
+ SHA512:
6
+ metadata.gz: b2099b60716dd2bb8e2b053e5e33bd7f633259b7ba2b26ff4bd2fe14024d4a31211fbe6d94980b6a5e99cc5f75e91fa416f917de0aad96f7f0ad87245265c13e
7
+ data.tar.gz: 32c4dd74d029529ef5439787bfb8233ab34b22439de997bd53fdb1867e4cd9761d041525eecd23128fe17663461610de2c218e74dc9c475c10c7bf08acaf2984
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --require spec_helper
2
+ --color
3
+ --format documentation
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # Changelog
2
+
3
+ ## 1.0.0 (2026-02-12)
4
+
5
+
6
+ ### Features
7
+
8
+ * add simple Nice client for CKAN data ([#1](https://github.com/nicolasleger/nice/issues/1)) ([2a7a318](https://github.com/nicolasleger/nice/commit/2a7a3185c7dc799d2b59e5320c97a0697e7de985))
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ # Use nicolasleger updated CKAN fork for v3 API support
6
+ gem 'ckan', github: 'nicolasleger/ckan', branch: 'feat/add-ckan-v3-support'
data/Gemfile.lock ADDED
@@ -0,0 +1,162 @@
1
+ GIT
2
+ remote: https://github.com/nicolasleger/ckan.git
3
+ revision: 0f89d5f23b62b83c98b5371d9243e36c2d42839e
4
+ branch: feat/add-ckan-v3-support
5
+ specs:
6
+ ckan (0.0.3)
7
+
8
+ PATH
9
+ remote: .
10
+ specs:
11
+ nice (0.1.0)
12
+ ckan
13
+ httparty (~> 0.21)
14
+ json (~> 2.6)
15
+
16
+ GEM
17
+ remote: https://rubygems.org/
18
+ specs:
19
+ addressable (2.8.8)
20
+ public_suffix (>= 2.0.2, < 8.0)
21
+ ast (2.4.3)
22
+ bigdecimal (4.0.1)
23
+ byebug (13.0.0)
24
+ reline (>= 0.6.0)
25
+ coderay (1.1.3)
26
+ crack (1.0.1)
27
+ bigdecimal
28
+ rexml
29
+ csv (3.3.5)
30
+ diff-lcs (1.6.2)
31
+ hashdiff (1.2.1)
32
+ httparty (0.24.2)
33
+ csv
34
+ mini_mime (>= 1.0.0)
35
+ multi_xml (>= 0.5.2)
36
+ io-console (0.8.2)
37
+ json (2.18.1)
38
+ language_server-protocol (3.17.0.5)
39
+ lint_roller (1.1.0)
40
+ method_source (1.1.0)
41
+ mini_mime (1.1.5)
42
+ multi_xml (0.8.1)
43
+ bigdecimal (>= 3.1, < 5)
44
+ parallel (1.27.0)
45
+ parser (3.3.10.1)
46
+ ast (~> 2.4.1)
47
+ racc
48
+ prism (1.9.0)
49
+ pry (0.16.0)
50
+ coderay (~> 1.1)
51
+ method_source (~> 1.0)
52
+ reline (>= 0.6.0)
53
+ pry-byebug (3.12.0)
54
+ byebug (~> 13.0)
55
+ pry (>= 0.13, < 0.17)
56
+ public_suffix (7.0.2)
57
+ racc (1.8.1)
58
+ rainbow (3.1.1)
59
+ rake (13.3.1)
60
+ regexp_parser (2.11.3)
61
+ reline (0.6.3)
62
+ io-console (~> 0.5)
63
+ rexml (3.4.4)
64
+ rspec (3.13.2)
65
+ rspec-core (~> 3.13.0)
66
+ rspec-expectations (~> 3.13.0)
67
+ rspec-mocks (~> 3.13.0)
68
+ rspec-core (3.13.6)
69
+ rspec-support (~> 3.13.0)
70
+ rspec-expectations (3.13.5)
71
+ diff-lcs (>= 1.2.0, < 2.0)
72
+ rspec-support (~> 3.13.0)
73
+ rspec-mocks (3.13.7)
74
+ diff-lcs (>= 1.2.0, < 2.0)
75
+ rspec-support (~> 3.13.0)
76
+ rspec-support (3.13.7)
77
+ rubocop (1.84.1)
78
+ json (~> 2.3)
79
+ language_server-protocol (~> 3.17.0.2)
80
+ lint_roller (~> 1.1.0)
81
+ parallel (~> 1.10)
82
+ parser (>= 3.3.0.2)
83
+ rainbow (>= 2.2.2, < 4.0)
84
+ regexp_parser (>= 2.9.3, < 3.0)
85
+ rubocop-ast (>= 1.49.0, < 2.0)
86
+ ruby-progressbar (~> 1.7)
87
+ unicode-display_width (>= 2.4.0, < 4.0)
88
+ rubocop-ast (1.49.0)
89
+ parser (>= 3.3.7.2)
90
+ prism (~> 1.7)
91
+ ruby-progressbar (1.13.0)
92
+ unicode-display_width (3.2.0)
93
+ unicode-emoji (~> 4.1)
94
+ unicode-emoji (4.2.0)
95
+ vcr (6.4.0)
96
+ webmock (3.26.1)
97
+ addressable (>= 2.8.0)
98
+ crack (>= 0.3.2)
99
+ hashdiff (>= 0.4.0, < 2.0.0)
100
+
101
+ PLATFORMS
102
+ arm64-darwin-25
103
+ ruby
104
+
105
+ DEPENDENCIES
106
+ ckan!
107
+ nice!
108
+ pry (~> 0.14)
109
+ pry-byebug (~> 3.10)
110
+ rake (~> 13.0)
111
+ rspec (~> 3.12)
112
+ rubocop (~> 1.50)
113
+ vcr (~> 6.0)
114
+ webmock (~> 3.0)
115
+
116
+ CHECKSUMS
117
+ addressable (2.8.8) sha256=7c13b8f9536cf6364c03b9d417c19986019e28f7c00ac8132da4eb0fe393b057
118
+ ast (2.4.3) sha256=954615157c1d6a382bc27d690d973195e79db7f55e9765ac7c481c60bdb4d383
119
+ bigdecimal (4.0.1) sha256=8b07d3d065a9f921c80ceaea7c9d4ae596697295b584c296fe599dd0ad01c4a7
120
+ byebug (13.0.0) sha256=d2263efe751941ca520fa29744b71972d39cbc41839496706f5d9b22e92ae05d
121
+ ckan (0.0.3)
122
+ coderay (1.1.3) sha256=dc530018a4684512f8f38143cd2a096c9f02a1fc2459edcfe534787a7fc77d4b
123
+ crack (1.0.1) sha256=ff4a10390cd31d66440b7524eb1841874db86201d5b70032028553130b6d4c7e
124
+ csv (3.3.5) sha256=6e5134ac3383ef728b7f02725d9872934f523cb40b961479f69cf3afa6c8e73f
125
+ diff-lcs (1.6.2) sha256=9ae0d2cba7d4df3075fe8cd8602a8604993efc0dfa934cff568969efb1909962
126
+ hashdiff (1.2.1) sha256=9c079dbc513dfc8833ab59c0c2d8f230fa28499cc5efb4b8dd276cf931457cd1
127
+ httparty (0.24.2) sha256=8fca6a54aa0c4aa4303a0fd33e5e2156175d6a5334f714263b458abd7fda9c38
128
+ io-console (0.8.2) sha256=d6e3ae7a7cc7574f4b8893b4fca2162e57a825b223a177b7afa236c5ef9814cc
129
+ json (2.18.1) sha256=fe112755501b8d0466b5ada6cf50c8c3f41e897fa128ac5d263ec09eedc9f986
130
+ language_server-protocol (3.17.0.5) sha256=fd1e39a51a28bf3eec959379985a72e296e9f9acfce46f6a79d31ca8760803cc
131
+ lint_roller (1.1.0) sha256=2c0c845b632a7d172cb849cc90c1bce937a28c5c8ccccb50dfd46a485003cc87
132
+ method_source (1.1.0) sha256=181301c9c45b731b4769bc81e8860e72f9161ad7d66dd99103c9ab84f560f5c5
133
+ mini_mime (1.1.5) sha256=8681b7e2e4215f2a159f9400b5816d85e9d8c6c6b491e96a12797e798f8bccef
134
+ multi_xml (0.8.1) sha256=addba0290bac34e9088bfe73dc4878530297a82a7bbd66cb44dcd0a4b86edf5a
135
+ nice (0.1.0)
136
+ parallel (1.27.0) sha256=4ac151e1806b755fb4e2dc2332cbf0e54f2e24ba821ff2d3dcf86bf6dc4ae130
137
+ parser (3.3.10.1) sha256=06f6a725d2cd91e5e7f2b7c32ba143631e1f7c8ae2fb918fc4cebec187e6a688
138
+ prism (1.9.0) sha256=7b530c6a9f92c24300014919c9dcbc055bf4cdf51ec30aed099b06cd6674ef85
139
+ pry (0.16.0) sha256=d76c69065698ed1f85e717bd33d7942c38a50868f6b0673c636192b3d1b6054e
140
+ pry-byebug (3.12.0) sha256=594e094ae8a8390a7ad4c7b36ae36e13304ed02664c67417d108dc5f7213d1b7
141
+ public_suffix (7.0.2) sha256=9114090c8e4e7135c1fd0e7acfea33afaab38101884320c65aaa0ffb8e26a857
142
+ racc (1.8.1) sha256=4a7f6929691dbec8b5209a0b373bc2614882b55fc5d2e447a21aaa691303d62f
143
+ rainbow (3.1.1) sha256=039491aa3a89f42efa1d6dec2fc4e62ede96eb6acd95e52f1ad581182b79bc6a
144
+ rake (13.3.1) sha256=8c9e89d09f66a26a01264e7e3480ec0607f0c497a861ef16063604b1b08eb19c
145
+ regexp_parser (2.11.3) sha256=ca13f381a173b7a93450e53459075c9b76a10433caadcb2f1180f2c741fc55a4
146
+ reline (0.6.3) sha256=1198b04973565b36ec0f11542ab3f5cfeeec34823f4e54cebde90968092b1835
147
+ rexml (3.4.4) sha256=19e0a2c3425dfbf2d4fc1189747bdb2f849b6c5e74180401b15734bc97b5d142
148
+ rspec (3.13.2) sha256=206284a08ad798e61f86d7ca3e376718d52c0bc944626b2349266f239f820587
149
+ rspec-core (3.13.6) sha256=a8823c6411667b60a8bca135364351dda34cd55e44ff94c4be4633b37d828b2d
150
+ rspec-expectations (3.13.5) sha256=33a4d3a1d95060aea4c94e9f237030a8f9eae5615e9bd85718fe3a09e4b58836
151
+ rspec-mocks (3.13.7) sha256=0979034e64b1d7a838aaaddf12bf065ea4dc40ef3d4c39f01f93ae2c66c62b1c
152
+ rspec-support (3.13.7) sha256=0640e5570872aafefd79867901deeeeb40b0c9875a36b983d85f54fb7381c47c
153
+ rubocop (1.84.1) sha256=14cc626f355141f5a2ef53c10a68d66b13bb30639b26370a76559096cc6bcc1a
154
+ rubocop-ast (1.49.0) sha256=49c3676d3123a0923d333e20c6c2dbaaae2d2287b475273fddee0c61da9f71fd
155
+ ruby-progressbar (1.13.0) sha256=80fc9c47a9b640d6834e0dc7b3c94c9df37f08cb072b7761e4a71e22cff29b33
156
+ unicode-display_width (3.2.0) sha256=0cdd96b5681a5949cdbc2c55e7b420facae74c4aaf9a9815eee1087cb1853c42
157
+ unicode-emoji (4.2.0) sha256=519e69150f75652e40bf736106cfbc8f0f73aa3fb6a65afe62fefa7f80b0f80f
158
+ vcr (6.4.0) sha256=077ac92cc16efc5904eb90492a18153b5e6ca5398046d8a249a7c96a9ea24ae6
159
+ webmock (3.26.1) sha256=4f696fb57c90a827c20aadb2d4f9058bbff10f7f043bd0d4c3f58791143b1cd7
160
+
161
+ BUNDLED WITH
162
+ 4.0.6
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 nicolasleger
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,147 +1,141 @@
1
- # Nice \[franz. nis\]
1
+ # nice
2
2
 
3
- ## What?
3
+ A Ruby gem for accessing and managing OpenData from Nice Côte d'Azur (NCA) metropolitan area via CKAN API.
4
4
 
5
- *Nice* is a light-weight engine which puts some *magic* into JS/AJAX driven Rails pages with the aim to ease the development of rich and interactive restful web applications.
5
+ ## Installation
6
6
 
7
- Go [here](http://nice.codebility.com) for an example and a detailed description.
7
+ Add this line to your application's Gemfile:
8
8
 
9
- ## How to use
9
+ ```ruby
10
+ gem 'nice'
11
+ ```
10
12
 
11
- ### Requirements
13
+ And then execute:
12
14
 
13
- This gem was tested with **Rails 3.2** but should also work with Rails 3.1 which introduced the *Asset-Pipeline* used by this gem.
14
- Furthermore, the current version uses **JQuery** to manipulate the DOM tree, so you should have the appropriate files in place. Although, it is easily possible to replace this by other frameworks (see *Contribution Section*)
15
+ $ bundle install
15
16
 
16
- ### Install
17
+ Or install it yourself as:
17
18
 
18
- 1. Add Gem dependency to your Gemfile
19
+ $ gem install nice
19
20
 
20
- ```ruby
21
- #.Gemfile
21
+ ## Configuration
22
22
 
23
- gem 'nice'
24
- ```
23
+ Configure the gem with your CKAN instance URL and API key:
25
24
 
26
- 2. Run
25
+ ```ruby
26
+ require 'nice'
27
27
 
28
- ```
29
- bundle install
30
- ```
28
+ Nice.configure do |config|
29
+ config.ckan_url = "https://opendata.nicecotedazur.org/data/"
30
+ config.api_key = "your-api-key-here"
31
+ end
32
+ ```
31
33
 
32
- 3. Add Middleware
34
+ Alternatively, set environment variables:
33
35
 
34
- ```ruby
35
- #config/application.rb
36
+ ```bash
37
+ export NICE_CKAN_URL="https://opendata.nicecotedazur.org/data/"
38
+ export NICE_CKAN_API_KEY="your-api-key-here"
39
+ ```
36
40
 
37
- config.middleware.use Nice::Middleware
38
- ```
41
+ ## Usage
39
42
 
40
- 4. Require Gem javascript in your applicaton.js manifest
43
+ ### Create a client
41
44
 
42
- ```js
43
- //app/assets/javascripts/application.js
45
+ ```ruby
46
+ client = Nice::Client.new
47
+ ```
44
48
 
45
- //= require nice_jquery
46
- ```
49
+ Or with direct credentials:
47
50
 
48
- ### Basic Usage
51
+ ```ruby
52
+ client = Nice::Client.new(
53
+ ckan_url: "https://opendata.nicecotedazur.org/data/",
54
+ api_key: "your-api-key-here"
55
+ )
56
+ ```
49
57
 
50
- The idea is to combine all views of one controller into one layout file exactly as it was already possible with rails and make heavy use of **yield()** and **content_for** tags to include view specific content.
51
- The convention of rails is to put a file named after your controller inside the *app/views/layouts/* folder. Such a file could look like this
58
+ ### List packages (datasets)
52
59
 
53
- ```haml
54
- -# app/views/layouts/books.html.haml
60
+ ```ruby
61
+ packages = client.list_packages
62
+ puts "Found #{packages.count} packages"
63
+ ```
55
64
 
56
- - content_for :content do
57
- %div
58
- .one{"data-state" => "get_books"}
59
- %h1 Only visible in state index
60
- = yield(:container1)
61
- .two{"data-state" => "get_books_show"}
62
- %h1 Only visible in state show
63
- = yield(:container1)
65
+ ### Search for datasets
64
66
 
65
- = render :template => 'layouts/application'
67
+ ```ruby
68
+ results = client.search_packages("transport")
69
+ puts "Found #{results['count']} matches"
66
70
  ```
67
71
 
68
- ```haml
69
- -# app/views/layouts/application.html.haml
72
+ ### Get package details
70
73
 
71
- \#{content_for?(:content) ? yield(:content) : yield}
74
+ ```ruby
75
+ package = client.get_package("package-id")
76
+ puts package['title']
72
77
  ```
73
78
 
74
- - The *content_for* tag will make sure the following context gets rendered in the application layout file \(see [Rails Guide](http://guides.rubyonrails.org/layouts_and_rendering.html#using-nested-layouts) for a deeper understanding of nested layouts\).
75
- - *.one{"data-state" => "get_books"}* is [HAML](http://haml.info/) code to generate a DIV block with a HTML5 attribute **data-state**. This is the key part: The value of the **data-state** attribute *marks the state in which the annotated element should be included*. This attribute can also hold a list of *space-separated* state names.
76
- - *= yield(:container1)* is a placeholder where content from the view file will be inserted at runtime.
77
- - The last line is part of the nexted layout design and just makes sure that this *books* layout page gets rendered inside the application layout.
79
+ ### List organizations
78
80
 
79
- There is one golden rule when programming with this state engine:
81
+ ```ruby
82
+ organizations = client.list_organizations
83
+ ```
80
84
 
81
- **All elements bounded to one or more states \(meaning that they are annotated with a *data-state* attribute\) must live in the *layout* file but not in a *view*!**
85
+ ### Get organization details
82
86
 
83
- This restriction is imposed by the way how the middleware calculates reference points for elements but should normally not effect your workflow - just keep it in mind.
87
+ ```ruby
88
+ org = client.get_organization("organization-id")
89
+ ```
84
90
 
85
- All links in your application should now use the ```:remote => :true``` attribute to ensure the requests will be sent using javascript by default.
91
+ ### List groups
86
92
 
87
- ### State Transitions
93
+ ```ruby
94
+ groups = client.list_groups
95
+ ```
88
96
 
89
- Nice offers the ability to make your state changes even smoother by using either JS and/or CSS. Every element inside a <code>data-state</code> with <code>data-state-transition=\"default\"</code> will be animated using the corresponding transition configuration. By default, a linear fade-in over 200ms is used, but you can override or configure any other property animation. You need to provide your configuration by creating some JS functions. I recommend using [coffee-script](http://coffeescript.org) and name the file *nice-transitions.js.coffee*:
97
+ ### Get resource details
90
98
 
99
+ ```ruby
100
+ resource = client.get_resource("resource-id")
91
101
  ```
92
- class this.NiceTransitions
93
- @default =
94
- duration: 1000
95
- easing: "linear"
96
- properties:
97
- opacity: 0.0
98
-
99
- @fade_slow =
100
- duration: 2000
101
- easing: "linear"
102
- properties:
103
- opacity: 0.0
104
-
105
- @slide_top =
106
- duration: 1000
107
- easing: "swing"
108
- properties:
109
- "top": "-200px"
110
- ```
111
102
 
112
- The body class gets the always a CSS class with the following naming convention assigned: <code>state-\{current_state_name\}</code>. You can use this to configure your styles per state like this:
103
+ ## Development
113
104
 
105
+ After checking out the repo, run `bundle install` to install dependencies.
106
+
107
+ ### Running Tests
108
+
109
+ Run the test suite:
110
+
111
+ ```bash
112
+ bundle exec rspec
114
113
  ```
115
- .state-get_basic_a{
116
- .set2, .set3{
117
- opacity: 0.4;
118
- }
119
- }
114
+
115
+ Run tests with detailed output:
116
+
117
+ ```bash
118
+ bundle exec rspec --format documentation
120
119
  ```
121
120
 
122
- ### Features
121
+ Run a specific test file:
122
+
123
+ ```bash
124
+ bundle exec rspec spec/nice/client_spec.rb
125
+ ```
123
126
 
124
- *Nice* is still in early stages and there is truly a lot to do. If you feel intrested and want to contribute, please don't hestitate to start work on one of the following features or enhance existing ones.
127
+ ### Linting
125
128
 
126
- - state annotation via HTML5 data attribute **data-state**
127
- - elements can belong to more than one state annotated by space separated list
128
- - naming convention for state names follows the appropriate REST route: method_controller_action
129
- - if an elements exist in the current and the following state it can be optionally left untouched with the **data-state-update** property set to *no*. Default is true.
130
- - automated Browser history management
131
- - javascript code for DOM manipulation is separated and can be replaced to use other frameworks easily \(just remove *nice_jquery* requirement in application.js manifest and put your own methods in place. Hava a look in *Nice-GEM/lib/assets/javascripts/dom_jquery.js.coffee* and *Nice-GEM/lib/assets/javascripts/dom_jquery.js.coffee* for the signature to implement\)
129
+ Check code style with RuboCop:
132
130
 
133
- ## Behind the scenes
131
+ ```bash
132
+ bundle exec rubocop
133
+ ```
134
134
 
135
- Nice is a middleware which processes all HTML and JS requests by either removing non-state specific content from the rendered page or generates JS code to manipulate the DOM tree client side.
135
+ ## Contributing
136
136
 
137
- ## Roadmap / Contribute
137
+ Bug reports and pull requests are welcome.
138
138
 
139
- - css class manipulation and css3 transition support
140
- - test cases
141
- - customization of state names
142
- - customization of HTML5 attribute names
143
- - add more js events which can be catched by application
144
- - preloading of states (for elements which do not require updated backend data)
139
+ ## License
145
140
 
146
- # License
147
- This project rocks and uses MIT-LICENSE.
141
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -1,47 +1,6 @@
1
- #!/usr/bin/env rake
2
- begin
3
- require 'bundler/setup'
4
- rescue LoadError
5
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
- end
7
- begin
8
- require 'rdoc/task'
9
- rescue LoadError
10
- require 'rdoc/rdoc'
11
- require 'rake/rdoctask'
12
- RDoc::Task = Rake::RDocTask
13
- end
14
-
15
- RDoc::Task.new(:rdoc) do |rdoc|
16
- rdoc.rdoc_dir = 'rdoc'
17
- rdoc.title = 'Nice'
18
- rdoc.options << '--line-numbers'
19
- rdoc.rdoc_files.include('README.rdoc')
20
- rdoc.rdoc_files.include('lib/**/*.rb')
21
- end
22
-
23
-
24
-
25
-
26
- Bundler::GemHelper.install_tasks
27
-
28
- require 'rake/testtask'
29
-
30
- Rake::TestTask.new(:test) do |t|
31
- t.libs << 'lib'
32
- t.libs << 'test'
33
- t.pattern = 'test/integration/*_test.rb'
34
- t.verbose = false
35
- end
36
-
37
- task :default => :test
38
-
39
-
40
- # rspec tests
41
- #require 'rspec/core/rake_task'
42
-
43
- #RSpec::Core::RakeTask.new(:spec)
44
-
45
- #task :default => :spec
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
46
3
 
4
+ RSpec::Core::RakeTask.new(:spec)
47
5
 
6
+ task default: :spec
@@ -0,0 +1,51 @@
1
+ require 'ckan'
2
+
3
+ module Nice
4
+ class Client
5
+ attr_reader :ckan_url, :api_key
6
+
7
+ def initialize(ckan_url: nil, api_key: nil)
8
+ @ckan_url = ckan_url || Nice.configuration&.ckan_url
9
+ @api_key = api_key || Nice.configuration&.api_key
10
+
11
+ validate_credentials!
12
+
13
+ # add ending slash if missing
14
+ fixed_ckan_url = @ckan_url.end_with?('/') ? @ckan_url : "#{@ckan_url}/"
15
+ CKAN::API.api_url = fixed_ckan_url
16
+ CKAN::API.api_version = "3"
17
+ CKAN::API.api_key = @api_key
18
+ end
19
+
20
+ # List all package IDs (datasets)
21
+ def list_package_ids
22
+ CKAN::Package.find
23
+ rescue => e
24
+ raise APIError, "Failed to list packages: #{e.message}"
25
+ end
26
+
27
+ # Get package details
28
+ def get_package(package_or_id)
29
+ package_id = package_or_id.is_a?(CKAN::Package) ? package_or_id.id : package_or_id
30
+ package = CKAN::Package.find(package_id)
31
+ {
32
+ 'id' => package.id,
33
+ 'name' => package.name,
34
+ 'title' => package.title,
35
+ 'resources' => package.resources
36
+ }
37
+ rescue => e
38
+ raise APIError, "Failed to get package: #{e.message}"
39
+ end
40
+
41
+ private
42
+
43
+ def validate_credentials!
44
+ raise ConfigurationError, "CKAN URL is required" if @ckan_url.nil? || @ckan_url.empty?
45
+
46
+ # API key is not mandatory for public datasets, so we won't raise an error if it's missing.
47
+ # However, we might check if it's provided and warn if not, depending on the use case.
48
+ # raise ConfigurationError, "API key is required" if @api_key.nil? || @api_key.empty?
49
+ end
50
+ end
51
+ end
data/lib/nice/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Nice
2
- VERSION = "0.0.7"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/nice.rb CHANGED
@@ -1,5 +1,33 @@
1
- require 'nice/middleware'
2
- require 'nice/engine'
1
+ require 'ckan'
2
+ require_relative 'nice/client'
3
+ require_relative 'nice/version'
3
4
 
4
5
  module Nice
6
+ class Error < StandardError; end
7
+ class ConfigurationError < Error; end
8
+ class APIError < Error; end
9
+
10
+ class << self
11
+ attr_accessor :configuration
12
+ end
13
+
14
+ def self.configure
15
+ self.configuration ||= Configuration.new
16
+ yield(configuration)
17
+ end
18
+
19
+ class Configuration
20
+ attr_accessor :ckan_url, :api_key
21
+
22
+ def initialize
23
+ @ckan_url = ENV['NICE_CKAN_URL'] || 'https://opendata.nicecotedazur.org/data/'
24
+
25
+ @api_key = ENV['NICE_CKAN_API_KEY']
26
+ end
27
+
28
+ def validate!
29
+ raise ConfigurationError, "CKAN URL is required" if ckan_url.nil? || ckan_url.empty?
30
+ raise ConfigurationError, "API key is required" if api_key.nil? || api_key.empty?
31
+ end
32
+ end
5
33
  end
data/nice.gemspec ADDED
@@ -0,0 +1,43 @@
1
+ require_relative "lib/nice/version"
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "nice"
5
+ spec.version = Nice::VERSION
6
+ spec.authors = ["Nicolas Leger"]
7
+ spec.email = ["nicolasleger@users.noreply.github.com"]
8
+
9
+ spec.summary = "OpenData NCA - Métropole Nice Côte d'Azur"
10
+ spec.description = "A Ruby gem for accessing and managing OpenData from Nice Côte d'Azur metropolitan area via CKAN API"
11
+ spec.homepage = "https://github.com/nicolasleger/nice"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = ">= 2.7.0"
14
+
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata["source_code_uri"] = "https://github.com/nicolasleger/nice"
17
+ spec.metadata["changelog_uri"] = "https://github.com/nicolasleger/nice/blob/main/CHANGELOG.md"
18
+
19
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
20
+ `git ls-files -z`.split("\x0").reject do |f|
21
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
22
+ end
23
+ end
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+
28
+ # CKAN dependency
29
+ spec.add_dependency "ckan"
30
+
31
+ # Additional useful dependencies
32
+ spec.add_dependency "httparty", "~> 0.21"
33
+ spec.add_dependency "json", "~> 2.6"
34
+
35
+ # Development dependencies
36
+ spec.add_development_dependency "rake", "~> 13.0"
37
+ spec.add_development_dependency "rspec", "~> 3.12"
38
+ spec.add_development_dependency "rubocop", "~> 1.50"
39
+ spec.add_development_dependency "vcr", "~> 6.0"
40
+ spec.add_development_dependency "webmock", "~> 3.0"
41
+ spec.add_development_dependency "pry", "~> 0.14"
42
+ spec.add_development_dependency "pry-byebug", "~> 3.10"
43
+ end