api_class.R 2.74 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
library(hash)
library(methods)
library(glue)

api <- setRefClass(
  "Api", 
  
  fields = list(
    api_type = "character", 
    export_format = "character", 
    root_url = "character",
    parameters = "character",
    id = "character",
    language = "character",
    version_format="numeric",
    path = "character",
    api_url = "character"
  ),
  
  methods = list(
    api_call = function(){
      request_function <- REQUEST_FUNCTION_MAPPING[[export_format]]
      request_function(f("{root_url}/api/{api_url}"))
    }, 
    get_url = function() {
      url_mapping <- hash(
        # i14y
        'codelist'=
          glue('CodeLists/{id}/exports/{export_format}/{version_format}'),
        'content_configuration' =
          glue('ContentConfigurations'),
        'content_configuration_identifier' =
          glue('ContentConfigurations/{id}'),
        'dcat_dataset_description' =
          glue('Datasets/{id}/{language}/description'),
        'dcat_dataset_information' =
          glue('Datasets/{id}/{language}/distributions'),
        'data_structure' =
          glue('DataStructures/{id}/{language}'),
        'nomenclature_path_nodes' =
          glue('Nomenclatures/Childnodes/{id}/{language}/{path}'),
        'nomenclature_one_level' =
          glue('Nomenclatures/{id}/levelexport/CSV'),
        'nomenclature_multiple_levels' =
          glue('Nomenclatures/{id}/multiplelevels/CSV'),
        'nomenclature_search' =
          glue('Nomenclatures/{id}/search'),
        
        # dcat
        'agents_list' =
          glue('Agent'),
        'agent_id' =
          glue('Agent/{id}'),
        'dataset_list' =
          glue('Dataset'),
        'dataset_id_distributions' =
          glue('Dataset/{id}/distributions'),
        'dataset_id' =
          glue('Dataset/{id}'),
        'dataset_identifier' =
          glue('Datataset/identifier/{id}'),
        'dataset_identifier_distributions' =
          glue('Datataset/identifier/{id}/distributions'),
        'distributions_list' =
          glue('Distribution'),
        'distribution_id' = 
          glue('Distribution/{id}')
      )
      api_url <<- url_mapping[[api_type]]
    }
  )
)


api_call <- api(
  api_type = "nomenclature_one_level", 
  export_format = "CSV", 
  root_url = BASE_URL,
  parameters = "CL_NOGA_SECTION",
  id = "CL_NOGA_SECTION",
  language = "fr",
  version_format=2.1,
  path = "."
)

api_call$get_url()
api_call$api_url

name <- "Fred"
age <- 50
anniversary <- as.Date("1991-10-12")
glue('My name is {name},',
     'my age next year is {age + 1},',
     'my anniversary is {format(anniversary, "%A, %B %d, %Y")}.')


url_mapping <- hash(
  # blablah
  'codelist'= 
    glue('CodeLists/{name}'),
  'content_configuration' = 
    glue('ContentConfigurations')
)
url_mapping[['codelist']]