Class: Nice::DataGouv::Client
- Inherits:
-
Object
- Object
- Nice::DataGouv::Client
- Includes:
- HTTParty
- Defined in:
- lib/nice/data_gouv/client.rb
Constant Summary collapse
- ORGANIZATION_SLUGS =
Manually curated list of organization slugs for the Nice Côte d'Azur region, sorted alphabetically.
%w[ association-mediterraneenne-de-secourisme-du-06-1 banque-populaire-mediterranee communaute-dagglomeration-cannes-lerins-1 communaute-urbaine-nice-cote-dazur commune-de-cagnes-sur-mer commune-de-fontan compagnie-autobus-de-monaco compagnie-des-autobus-de-monaco conseil-departemental-du-var ddtm-alpes-maritimes departement-des-alpes-maritimes eau-dazur ecole-nationale-superieure-d-art-villa-arson-de-nice groupement-dassociations-de-defense-de-lenvironnement-et-des-sites-de-la-cote-dazur innovevents-reseau-national-dagences-evenementielles mairie-de-cannes mairie-de-grasse mairie-de-la-gaude metropole-toulon-provence-mediterranee nice-cote-dazur office-de-tourisme-metropolitain-nice-cote-dazur parc-national-de-port-cros prise-de-nice-1 regie-ligne-dazur service-departemental-dincendie-et-de-secours-des-alpes-maritimes sictiam ville-dantibes ville-de-frejus ville-de-nice ]
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
Instance Method Summary collapse
-
#dataset(id_or_slug) ⇒ Object
Get dataset by ID or slug.
-
#initialize(api_key: nil) ⇒ Client
constructor
A new instance of Client.
-
#organization(id_or_slug) ⇒ Object
Get organization by ID or slug.
-
#organization_datasets(org_id_or_slug, page: 1, page_size: 20) ⇒ Object
List organization datasets.
Constructor Details
#initialize(api_key: nil) ⇒ Client
Returns a new instance of Client.
50 51 52 |
# File 'lib/nice/data_gouv/client.rb', line 50 def initialize(api_key: nil) @api_key = api_key || ENV['DATA_GOUV_API_KEY'] end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
15 16 17 |
# File 'lib/nice/data_gouv/client.rb', line 15 def api_key @api_key end |
Instance Method Details
#dataset(id_or_slug) ⇒ Object
Get dataset by ID or slug
77 78 79 80 81 82 83 |
# File 'lib/nice/data_gouv/client.rb', line 77 def dataset(id_or_slug) validate_id_or_slug!(id_or_slug) response = self.class.get("/datasets/#{id_or_slug}/", headers: headers) handle_response(response) do |data| Dataset.new(data) end end |
#organization(id_or_slug) ⇒ Object
Get organization by ID or slug
55 56 57 58 59 60 61 |
# File 'lib/nice/data_gouv/client.rb', line 55 def organization(id_or_slug) validate_id_or_slug!(id_or_slug) response = self.class.get("/organizations/#{id_or_slug}", headers: headers) handle_response(response) do |data| Organization.new(data) end end |
#organization_datasets(org_id_or_slug, page: 1, page_size: 20) ⇒ Object
List organization datasets
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/nice/data_gouv/client.rb', line 64 def organization_datasets(org_id_or_slug, page: 1, page_size: 20) validate_id_or_slug!(org_id_or_slug) response = self.class.get( "/organizations/#{org_id_or_slug}/datasets", query: { page: page, page_size: page_size }, headers: headers ) handle_response(response) do |data| (data['data'] || []).map { |d| Dataset.new(d) } end end |