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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
use Configuration;
use EntityType;
#[derive(Debug)]
pub struct EntityQuery {
ids: Vec<String>,
lang: String,
}
#[derive(Debug)]
pub struct SearchQuery {
query: String,
lang: String,
search_lang: String,
limit: u64,
entity_type: EntityType,
}
impl EntityQuery {
pub fn new<S: Into<String>>(ids: Vec<String>, lang: S) -> EntityQuery {
Self {
ids,
lang: lang.into(),
}
}
pub fn ids(&self) -> &[String] {
&self.ids
}
pub fn lang(&self) -> &str {
&self.lang
}
pub fn url(&self, configuration: &Configuration) -> String {
encode_url(&format!("{}?action=wbgetentities&ids={}&languages={}&uselang={}&format=json",
configuration.api_url(),
self.ids_piped(),
&self.lang,
&self.lang))
}
fn ids_piped(&self) -> String {
self.ids().join("|")
}
}
impl SearchQuery {
pub fn new<S: Into<String>>(query: S, lang: S, search_lang: S, limit: u64,
entity_type: EntityType) -> SearchQuery {
Self {
query: query.into(),
lang: lang.into(),
search_lang: search_lang.into(),
limit,
entity_type,
}
}
pub fn entity_type(&self) -> &EntityType {
&self.entity_type
}
pub fn lang(&self) -> &str {
&self.lang
}
pub fn limit(&self) -> &u64 {
&self.limit
}
pub fn query(&self) -> &str {
&self.query
}
pub fn search_lang(&self) -> &str {
&self.search_lang
}
pub fn url(&self, configuration: &Configuration) -> String {
encode_url(&format!("{}?action=wbsearchentities&search={}&language={}&limit={}&type={}&uselang={}&format=json",
configuration.api_url(),
&self.query,
&self.search_lang,
&self.limit,
&self.entity_type.string_value(),
&self.lang))
}
}
fn encode_url(url: &str) -> String {
str::replace(&url, " ", "%20")
}