wikirate4ruby 1.0.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 +7 -0
- data/.standard.yml +3 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +12 -0
- data/LICENSE +674 -0
- data/README.md +48 -0
- data/Rakefile +14 -0
- data/lib/wikirate4ruby/client.rb +395 -0
- data/lib/wikirate4ruby/entities/answer.rb +26 -0
- data/lib/wikirate4ruby/entities/card.rb +81 -0
- data/lib/wikirate4ruby/entities/checked_by.rb +19 -0
- data/lib/wikirate4ruby/entities/company.rb +25 -0
- data/lib/wikirate4ruby/entities/company_group.rb +21 -0
- data/lib/wikirate4ruby/entities/dataset.rb +21 -0
- data/lib/wikirate4ruby/entities/metric.rb +43 -0
- data/lib/wikirate4ruby/entities/region.rb +20 -0
- data/lib/wikirate4ruby/entities/relationship_answer.rb +23 -0
- data/lib/wikirate4ruby/entities/research_group.rb +19 -0
- data/lib/wikirate4ruby/entities/source.rb +27 -0
- data/lib/wikirate4ruby/entities/topic.rb +20 -0
- data/lib/wikirate4ruby/error.rb +98 -0
- data/lib/wikirate4ruby/request.rb +99 -0
- data/lib/wikirate4ruby/request_utils.rb +36 -0
- data/lib/wikirate4ruby/utils.rb +16 -0
- data/lib/wikirate4ruby/version.rb +3 -0
- data/lib/wikirate4ruby.rb +28 -0
- data/sig/wikirate4ruby.rbs +4 -0
- metadata +87 -0
data/README.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Wikirate4ruby
|
|
2
|
+
|
|
3
|
+
Wikirate4ruby is a ruby library for the [Wikirate API](https://wikirate.org/Use_the_API) licensed under GNU GPL v3.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
gem install wikirate4ruby
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
# Initializing client
|
|
13
|
+
client = Wikirate4ruby::REST::Client.new("YOUR_API_TOKEN")
|
|
14
|
+
|
|
15
|
+
#get a company given the name or wikirate id
|
|
16
|
+
company = client.get_company("Adidas_AG")
|
|
17
|
+
#get a company's answers
|
|
18
|
+
answers = client.get_company_answers(company.id, { 'year' => 2022 })
|
|
19
|
+
#create a new company
|
|
20
|
+
wikirate = client.add_company({ 'name' => 'Wikirate International e.V.', 'headquarters' => 'Germany' })
|
|
21
|
+
#add answer to metric
|
|
22
|
+
address = client.add_research_answer({ 'metric_name' => 'Address',
|
|
23
|
+
'metric_designer' => 'Commons',
|
|
24
|
+
'year' => 2023,
|
|
25
|
+
'value' => "Schlimannstrasse 29, Berlin",
|
|
26
|
+
'company' => wikirate.id,
|
|
27
|
+
'source' => 'Source-123' })
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Development
|
|
31
|
+
|
|
32
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can
|
|
33
|
+
also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
34
|
+
|
|
35
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the
|
|
36
|
+
version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version,
|
|
37
|
+
push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
38
|
+
|
|
39
|
+
## Contributing
|
|
40
|
+
|
|
41
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/wikirate/wikirate4ruby. This project is
|
|
42
|
+
intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to
|
|
43
|
+
the [code of conduct](https://github.com/[USERNAME]/wikirate4ruby/blob/master/CODE_OF_CONDUCT.md).
|
|
44
|
+
|
|
45
|
+
## Code of Conduct
|
|
46
|
+
|
|
47
|
+
Everyone interacting in the Wikirate4ruby project's codebases, issue trackers, chat rooms and mailing lists is expected
|
|
48
|
+
to follow the [code of conduct](https://github.com/wikirate/wikirate4ruby/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "bundler/gem_tasks"
|
|
4
|
+
require "rake/testtask"
|
|
5
|
+
|
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
|
7
|
+
t.libs << "test"
|
|
8
|
+
t.libs << "lib"
|
|
9
|
+
t.test_files = FileList["test/**/test_*.rb"]
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
require "standard/rake"
|
|
13
|
+
|
|
14
|
+
task default: %i[test standard]
|
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
require_relative 'entities/card'
|
|
2
|
+
require_relative 'entities/metric'
|
|
3
|
+
require_relative 'entities/company'
|
|
4
|
+
require_relative 'entities/source'
|
|
5
|
+
require_relative 'entities/topic'
|
|
6
|
+
require_relative 'entities/dataset'
|
|
7
|
+
require_relative 'entities/research_group'
|
|
8
|
+
require_relative 'entities/company_group'
|
|
9
|
+
require_relative 'entities/answer'
|
|
10
|
+
require_relative 'entities/relationship_answer'
|
|
11
|
+
require_relative 'entities/region'
|
|
12
|
+
require_relative 'entities/checked_by'
|
|
13
|
+
require_relative './request'
|
|
14
|
+
require_relative './utils'
|
|
15
|
+
require_relative './request_utils'
|
|
16
|
+
require 'json'
|
|
17
|
+
require 'logger'
|
|
18
|
+
|
|
19
|
+
module Wikirate4ruby
|
|
20
|
+
module REST
|
|
21
|
+
class Client
|
|
22
|
+
include Wikirate4ruby::Entities
|
|
23
|
+
include Wikirate4ruby::Utils
|
|
24
|
+
include Wikirate4ruby::RequestUtils
|
|
25
|
+
|
|
26
|
+
BASE_URL = 'https://wikirate.org'
|
|
27
|
+
attr :request
|
|
28
|
+
|
|
29
|
+
def initialize(api_key, wikirate_api_url = BASE_URL, auth = {})
|
|
30
|
+
@request = Request.new(api_key, wikirate_api_url, auth)
|
|
31
|
+
@logger = Logger.new(STDOUT)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def get_company(identifier)
|
|
35
|
+
get_entity(identifier, Company)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def get_metric(identifier)
|
|
39
|
+
get_entity(identifier, Metric)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def get_answer(identifier)
|
|
43
|
+
get_entity(identifier, Answer)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def get_relationship_answer(identifier)
|
|
47
|
+
get_entity(identifier, RelationshipAnswer)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def get_dataset(identifier)
|
|
51
|
+
get_entity(identifier, Dataset)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def get_company_group(identifier)
|
|
55
|
+
get_entity(identifier, CompanyGroup)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def get_topic(identifier)
|
|
59
|
+
get_entity(identifier, Topic)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def get_research_group(identifier)
|
|
63
|
+
get_entity(identifier, ResearchGroup)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def get_source(identifier)
|
|
67
|
+
get_entity(identifier, Source)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def get_region(identifier)
|
|
71
|
+
get_entity(identifier, Region)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def get_card(identifier)
|
|
75
|
+
get_entity(identifier, Card)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def get_checked_by(identifier)
|
|
79
|
+
get_entity(identifier, CheckedBy)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def get_project(identifier)
|
|
83
|
+
get_entity(identifier, Card)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def get_companies(params = {})
|
|
87
|
+
companies = []
|
|
88
|
+
response = @request.get('/Companies.json', endpoint_params = %w[limit offset],
|
|
89
|
+
filters = %w[name company_category company_group country], params)
|
|
90
|
+
|
|
91
|
+
response['items'].each do |item|
|
|
92
|
+
companies.append(Company.new(item))
|
|
93
|
+
end
|
|
94
|
+
companies
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def get_metrics(params = {})
|
|
98
|
+
metrics = []
|
|
99
|
+
response = @request.get('/Metrics.json', endpoint_params = %w[limit offset],
|
|
100
|
+
filters = %w[name bookmark wikirate_topic designer published metric_type value_type research_policy dataset], params)
|
|
101
|
+
|
|
102
|
+
response['items'].each do |item|
|
|
103
|
+
metrics.append(Metric.new(item))
|
|
104
|
+
end
|
|
105
|
+
metrics
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def get_topics(params = {})
|
|
109
|
+
topics = []
|
|
110
|
+
response = @request.get('/Topics.json', endpoint_params = %w[limit offset],
|
|
111
|
+
filters = %w[name bookmark], params)
|
|
112
|
+
|
|
113
|
+
response['items'].each do |item|
|
|
114
|
+
topics.append(Topic.new(item))
|
|
115
|
+
end
|
|
116
|
+
topics
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def get_datasets(params = {})
|
|
120
|
+
datasets = []
|
|
121
|
+
response = @request.get('/Data_Sets.json', endpoint_params = %w[limit offset],
|
|
122
|
+
filters = %w[name bookmark wikirate_topic], params)
|
|
123
|
+
|
|
124
|
+
response['items'].each do |item|
|
|
125
|
+
datasets.append(Dataset.new(item))
|
|
126
|
+
end
|
|
127
|
+
datasets
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def get_projects(params = {})
|
|
131
|
+
projects = []
|
|
132
|
+
response = @request.get('/Projects.json', endpoint_params = %w[limit offset],
|
|
133
|
+
filters = %w[name wikirate_status], params)
|
|
134
|
+
|
|
135
|
+
response['items'].each do |item|
|
|
136
|
+
projects.append(Card.new(item))
|
|
137
|
+
end
|
|
138
|
+
projects
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def get_sources(params = {})
|
|
142
|
+
sources = []
|
|
143
|
+
response = @request.get('/Sources.json', endpoint_params = %w[limit offset],
|
|
144
|
+
filters = %w[name wikirate_title wikirate_topic report_type year wikirate_link company_name], params)
|
|
145
|
+
|
|
146
|
+
response['items'].each do |item|
|
|
147
|
+
sources.append(Source.new(item))
|
|
148
|
+
end
|
|
149
|
+
sources
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def get_research_groups(params = {})
|
|
153
|
+
research_groups = []
|
|
154
|
+
response = @request.get('/Research_Groups.json', endpoint_params = %w[limit offset],
|
|
155
|
+
filters = %w[name], params)
|
|
156
|
+
|
|
157
|
+
response['items'].each do |item|
|
|
158
|
+
research_groups.append(ResearchGroup.new(item))
|
|
159
|
+
end
|
|
160
|
+
research_groups
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
def get_company_groups(params = {})
|
|
164
|
+
company_groups = []
|
|
165
|
+
response = @request.get('/Company_Groups.json', endpoint_params = %w[limit offset],
|
|
166
|
+
filters = %w[name], params)
|
|
167
|
+
|
|
168
|
+
response['items'].each do |item|
|
|
169
|
+
company_groups.append(CompanyGroup.new(item))
|
|
170
|
+
end
|
|
171
|
+
company_groups
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
def get_answers(metric_name, metric_designer, params = {})
|
|
175
|
+
answers = []
|
|
176
|
+
response = @request.get("/#{tranform_to_wr_friendly_name(metric_designer)}+#{tranform_to_wr_friendly_name(metric_name)}+Answers.json",
|
|
177
|
+
endpoint_params = %w[limit offset],
|
|
178
|
+
filters = %w[year verification value value_from value_to status source updated updater published
|
|
179
|
+
dataset company_id company_name company_category company_group country], params)
|
|
180
|
+
|
|
181
|
+
response['items'].each do |item|
|
|
182
|
+
answers.append(Answer.new(item))
|
|
183
|
+
end
|
|
184
|
+
answers
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
def get_answers_by_metric_id(metric_id, params = {})
|
|
188
|
+
answers = []
|
|
189
|
+
response = @request.get("/#{str_identifier(metric_id)}+Answers.json", endpoint_params = %w[limit offset],
|
|
190
|
+
filters = %w[year verification value value_from value_to status source updated updater published
|
|
191
|
+
dataset company_id company_name company_category company_group country], params)
|
|
192
|
+
|
|
193
|
+
response['items'].each do |item|
|
|
194
|
+
answers.append(Answer.new(item))
|
|
195
|
+
end
|
|
196
|
+
answers
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
def get_company_answers(identifier, params = {})
|
|
200
|
+
answers = []
|
|
201
|
+
endpoint = "/#{str_identifier(identifier)}+Answers.json"
|
|
202
|
+
response = @request.get(endpoint, endpoint_params = %w[limit offset],
|
|
203
|
+
filters = %w[metric_name designer metric_type value_type research_policy year verification value
|
|
204
|
+
value_from value_to status source updated updater published dataset company_id
|
|
205
|
+
company_name company_category company_group country], params)
|
|
206
|
+
|
|
207
|
+
response['items'].each do |item|
|
|
208
|
+
answers.append(Answer.new(item))
|
|
209
|
+
end
|
|
210
|
+
answers
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
def get_relationship_answers(metric_name, metric_designer, params = {})
|
|
214
|
+
answers = []
|
|
215
|
+
response = @request.get("/#{tranform_to_wr_friendly_name(metric_designer)}+#{tranform_to_wr_friendly_name(metric_name)}+RelationshipAnswers.json",
|
|
216
|
+
endpoint_params = %w[limit offset],
|
|
217
|
+
filters = %w[year name company_category company_group dataset updated updater source published], params)
|
|
218
|
+
|
|
219
|
+
response['items'].each do |item|
|
|
220
|
+
answers.append(RelationshipAnswer.new(item))
|
|
221
|
+
end
|
|
222
|
+
answers
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
def get_relationship_answers_by_metric_id(metric_id, params = {})
|
|
226
|
+
answers = []
|
|
227
|
+
response = @request.get("/#{str_identifier(metric_id)}+RelationshipAnswers.json", endpoint_params = %w[limit offset],
|
|
228
|
+
filters = %w[year name company_category company_group dataset updated updater source published], params)
|
|
229
|
+
|
|
230
|
+
response['items'].each do |item|
|
|
231
|
+
answers.append(RelationshipAnswer.new(item))
|
|
232
|
+
end
|
|
233
|
+
answers
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
# @param [Hash] data
|
|
237
|
+
# @return [Wikirate4ruby::Entities::Company]
|
|
238
|
+
def add_company(data = {})
|
|
239
|
+
required_params = %w[name headquarters]
|
|
240
|
+
required_params.each do |param|
|
|
241
|
+
if data[param].nil? || data[param] == ''
|
|
242
|
+
raise Wikirate4ruby::Error::Wikirate4rubyError, "Invalid set of params! You need to define all the following
|
|
243
|
+
params to import a new company: #{required_params.to_s}"
|
|
244
|
+
end
|
|
245
|
+
end
|
|
246
|
+
card_name = data['name']
|
|
247
|
+
data.delete('name')
|
|
248
|
+
params = creation_params('Company', data, %w[headquarters oar_id wikipedia open_corporates sec_cik])
|
|
249
|
+
params['card[name]'] = card_name
|
|
250
|
+
params['confirmed'] = true
|
|
251
|
+
params['card[skip]'] = 'update_oc_mapping_due_to_headquarters_entry' if data['open_corporates'].nil?
|
|
252
|
+
response = @request.post('/card/create', params)
|
|
253
|
+
Company.new(response)
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
def update_company(data = {})
|
|
257
|
+
if data['company'].nil? || data['company'] == ''
|
|
258
|
+
raise Wikirate4ruby::Error::Wikirate4rubyError, "Invalid set of params! You need to define all the following params to update a
|
|
259
|
+
company: [company]"
|
|
260
|
+
end
|
|
261
|
+
card_name = str_identifier(data['company'])
|
|
262
|
+
data.delete 'company'
|
|
263
|
+
|
|
264
|
+
params = creation_params('Company', data, %w[headquarters open_corporates oar_id wikipedia sec_cik])
|
|
265
|
+
params['card[name]'] = card_name
|
|
266
|
+
response = @request.post('/card/update', params)
|
|
267
|
+
Company.new(response)
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
def add_research_metric_answer(data = {})
|
|
271
|
+
required_params = %w[metric_designer metric_name company year value source]
|
|
272
|
+
required_params.each do |param|
|
|
273
|
+
if data[param].nil? || data[param] == ''
|
|
274
|
+
raise Wikirate4ruby::Error::Wikirate4rubyError, "Invalid set of params! You need to define all the following params to import a
|
|
275
|
+
new research answer: #{required_params.to_s}"
|
|
276
|
+
end
|
|
277
|
+
end
|
|
278
|
+
card_name = "#{data['metric_designer']}+#{data['metric_name']}+#{str_identifier(data['company'])}+#{data['year']}"
|
|
279
|
+
%w[metric_designer metric_name company year].each do |key|
|
|
280
|
+
data.delete key
|
|
281
|
+
end
|
|
282
|
+
params = creation_params('Answer', data, %w[source value discussion])
|
|
283
|
+
params['card[name]'] = card_name
|
|
284
|
+
response = @request.post('/card/create', params)
|
|
285
|
+
Answer.new(response)
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
def update_research_metric_answer(data = {})
|
|
289
|
+
required_params = %w[metric_designer metric_name company]
|
|
290
|
+
if data['answer_id'].nil?
|
|
291
|
+
required_params.each do |param|
|
|
292
|
+
if data[param].nil? || data[param] == ''
|
|
293
|
+
raise Wikirate4ruby::Error::Wikirate4rubyError, "Invalid set of params! You need to define all the following params to import a
|
|
294
|
+
new research answer: #{required_params.to_s}"
|
|
295
|
+
end
|
|
296
|
+
end
|
|
297
|
+
card_name = "#{data['metric_designer']}+#{data['metric_name']}+#{str_identifier(data['company'])}+#{data['year']}"
|
|
298
|
+
%w[metric_designer metric_name company year].each do |key|
|
|
299
|
+
data.delete key
|
|
300
|
+
end
|
|
301
|
+
allowed_params = %w[source value discussion]
|
|
302
|
+
else
|
|
303
|
+
card_name = str_identifier(data['answer_id'])
|
|
304
|
+
data.delete 'answer_id'
|
|
305
|
+
allowed_params = %w[year source value discussion]
|
|
306
|
+
end
|
|
307
|
+
|
|
308
|
+
params = creation_params('Answer', data, allowed_params)
|
|
309
|
+
params['card[name]'] = card_name
|
|
310
|
+
puts(params)
|
|
311
|
+
response = @request.post('/card/update', params)
|
|
312
|
+
Answer.new(response)
|
|
313
|
+
end
|
|
314
|
+
|
|
315
|
+
def add_relationship_metric_answer(data = {})
|
|
316
|
+
required_params = %w[metric_designer metric_name subject_company object_company year value source]
|
|
317
|
+
required_params.each do |param|
|
|
318
|
+
if data[param].nil? || data[param] == ''
|
|
319
|
+
raise Wikirate4ruby::Error::Wikirate4rubyError, "Invalid set of params! You need to define all the following params to import a
|
|
320
|
+
new research answer: #{required_params.to_s}"
|
|
321
|
+
end
|
|
322
|
+
end
|
|
323
|
+
card_name = "#{data['metric_designer']}+#{data['metric_name']}+#{str_identifier(data['subject_company'])}+#{data['year']}+#{str_identifier(data['object_company'])}"
|
|
324
|
+
%w[metric_designer metric_name subject_company object_company year].each do |key|
|
|
325
|
+
data.delete key
|
|
326
|
+
end
|
|
327
|
+
params = creation_params('RelationshipAnswer', data, %w[source value comments])
|
|
328
|
+
params['card[name]'] = card_name
|
|
329
|
+
response = @request.post('/card/create', params)
|
|
330
|
+
RelationshipAnswer.new(response)
|
|
331
|
+
end
|
|
332
|
+
|
|
333
|
+
def update_relationship_metric_answer(data = {})
|
|
334
|
+
required_params = %w[metric_designer metric_name subject_company object_company year]
|
|
335
|
+
if data['answer_id'].nil?
|
|
336
|
+
required_params.each do |param|
|
|
337
|
+
if data[param].nil? || data[param] == ''
|
|
338
|
+
raise Wikirate4ruby::Error::Wikirate4rubyError, "Invalid set of params! You need to define all the following params to import a
|
|
339
|
+
new research answer: #{required_params.to_s}"
|
|
340
|
+
end
|
|
341
|
+
end
|
|
342
|
+
card_name = "#{data['metric_designer']}+#{data['metric_name']}+#{str_identifier(data['company'])}+#{data['year']}"
|
|
343
|
+
%w[metric_designer metric_name subject_company year object_company].each do |key|
|
|
344
|
+
data.delete key
|
|
345
|
+
end
|
|
346
|
+
allowed_params = %w[source value discussion]
|
|
347
|
+
else
|
|
348
|
+
card_name = str_identifier(data['answer_id'])
|
|
349
|
+
data.delete 'answer_id'
|
|
350
|
+
allowed_params = %w[year source value discussion]
|
|
351
|
+
end
|
|
352
|
+
|
|
353
|
+
params = creation_params('RelationshipAnswer', data, allowed_params)
|
|
354
|
+
response = @request.post("/update/#{card_name}", params)
|
|
355
|
+
RelationshipAnswer.new(response)
|
|
356
|
+
end
|
|
357
|
+
|
|
358
|
+
# @param [Hash] data
|
|
359
|
+
# @return [Wikirate4ruby::Entities::Source]
|
|
360
|
+
def add_source(data = {})
|
|
361
|
+
required_params = %w[link title]
|
|
362
|
+
required_params.each do |param|
|
|
363
|
+
if data[param].nil? || data[param] == ''
|
|
364
|
+
raise Wikirate4ruby::Error::Wikirate4rubyError, "Invalid set of params! You need to define all the following params to import a
|
|
365
|
+
new source: #{required_params.to_s}"
|
|
366
|
+
end
|
|
367
|
+
end
|
|
368
|
+
params = creation_params('Source', data, %w[link title company report_type year])
|
|
369
|
+
params['card[skip]'] = 'requirements'
|
|
370
|
+
response = @request.post('/card/create', params)
|
|
371
|
+
Source.new(response)
|
|
372
|
+
end
|
|
373
|
+
|
|
374
|
+
def update_source(data = {})
|
|
375
|
+
if data['source'].nil? || data['source'] == ''
|
|
376
|
+
raise Wikirate4ruby::Error::Wikirate4rubyError, "Invalid set of params! You need to define all the following params to update a
|
|
377
|
+
source: [source]"
|
|
378
|
+
end
|
|
379
|
+
card_name = str_identifier(data['source'])
|
|
380
|
+
data.delete 'source'
|
|
381
|
+
params = creation_params('Source', data, %w[link title company report_type year])
|
|
382
|
+
params['card[skip]'] = 'requirements'
|
|
383
|
+
response = @request.post("/update/#{card_name}", params)
|
|
384
|
+
Source.new(response)
|
|
385
|
+
end
|
|
386
|
+
|
|
387
|
+
private
|
|
388
|
+
|
|
389
|
+
def get_entity(identifier, klass)
|
|
390
|
+
klass.new(@request.get("/#{str_identifier(identifier)}.json"))
|
|
391
|
+
end
|
|
392
|
+
|
|
393
|
+
end
|
|
394
|
+
end
|
|
395
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require_relative '../error'
|
|
2
|
+
|
|
3
|
+
module Wikirate4ruby
|
|
4
|
+
module Entities
|
|
5
|
+
class Answer < Entities::Card
|
|
6
|
+
ATTRIBUTES = %i[company year value comments record_url metric_name metric_designer sources checked_by].freeze
|
|
7
|
+
attr_reader(*ATTRIBUTES)
|
|
8
|
+
|
|
9
|
+
def initialize(answer)
|
|
10
|
+
super answer
|
|
11
|
+
raise parsing_error name = "IncompatibleCardType", message = "The input Card is not an Answer but a #{@type}" unless @type.include? 'Answer'
|
|
12
|
+
|
|
13
|
+
@metric_name = get_content('name').split('+')[1]
|
|
14
|
+
@metric_designer = get_content('name').split('+')[0]
|
|
15
|
+
@company = get_content 'company'
|
|
16
|
+
@value = get_content 'value'
|
|
17
|
+
@year = get_content 'year'
|
|
18
|
+
@sources = get_array_of 'sources', Source
|
|
19
|
+
@checked_by = get_content 'checked_by'
|
|
20
|
+
@comments = get_content 'comments'
|
|
21
|
+
@record_url = get_content 'record_url'
|
|
22
|
+
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
module Wikirate4ruby
|
|
2
|
+
module Entities
|
|
3
|
+
class Card
|
|
4
|
+
CARD_ATTRIBUTES = %i[id type name content url codename html_url created_at updated_at requested_at].freeze
|
|
5
|
+
attr_reader(*CARD_ATTRIBUTES)
|
|
6
|
+
|
|
7
|
+
def initialize(card)
|
|
8
|
+
@data = card
|
|
9
|
+
@id = get_content 'id'
|
|
10
|
+
@type = @data['type'].is_a?(String) ? @data['type'] : @data['type']['name']
|
|
11
|
+
@name = @data['name']
|
|
12
|
+
@content = @data['content']
|
|
13
|
+
@url = @data['url']
|
|
14
|
+
@codename = @data['codename']
|
|
15
|
+
@html_url = @data['html_url']
|
|
16
|
+
@created_at = @data['created_at']
|
|
17
|
+
@updated_at = @data['updated_at']
|
|
18
|
+
@requested_at = @data['requested_at']
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def raw_json
|
|
22
|
+
JSON.pretty_generate(@data)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# @return [Hash{String->Unknown}]
|
|
26
|
+
def as_json
|
|
27
|
+
{
|
|
28
|
+
'id' => @id,
|
|
29
|
+
'type' => @type,
|
|
30
|
+
'name' => @name,
|
|
31
|
+
'content' => @content,
|
|
32
|
+
'url' => @url,
|
|
33
|
+
'codename' => @codename,
|
|
34
|
+
'html_url' => @html_url,
|
|
35
|
+
'created_at' => @created_at,
|
|
36
|
+
'updated_at' => @updated_at,
|
|
37
|
+
'requested_at' => @requested_at
|
|
38
|
+
}
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def to_json(*_args)
|
|
42
|
+
JSON.pretty_generate(to_hash)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def to_s
|
|
46
|
+
to_json
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
protected
|
|
50
|
+
|
|
51
|
+
def to_hash
|
|
52
|
+
hash = {}
|
|
53
|
+
instance_variables.each { |var| var.to_s == '@data' || instance_variable_get(var).nil? ? nil : hash[var.to_s.delete('@')] = instance_variable_get(var) }
|
|
54
|
+
hash
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def get_content(field)
|
|
58
|
+
@data[field].is_a?(Hash) ? @data[field]['content'] : @data[field]
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def get_name(field)
|
|
62
|
+
@data[field].is_a?(Hash) ? @data[field]['name'] : @data[field]
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def get_array_of(field, klass)
|
|
66
|
+
return @data[field] unless @data[field].is_a? Array
|
|
67
|
+
|
|
68
|
+
list = []
|
|
69
|
+
@data[field].each do |item|
|
|
70
|
+
list.append(klass.new(item))
|
|
71
|
+
end
|
|
72
|
+
list
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def parsing_error(name, message)
|
|
76
|
+
error = Wikirate4ruby::Error::ParsingError.from_processing_response({ :name => name, :message => message })
|
|
77
|
+
return error
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require_relative '../error'
|
|
2
|
+
|
|
3
|
+
module Wikirate4ruby
|
|
4
|
+
module Entities
|
|
5
|
+
class CheckedBy < Entities::Card
|
|
6
|
+
ATTRIBUTES = %i[checks].freeze
|
|
7
|
+
attr_reader(*ATTRIBUTES)
|
|
8
|
+
|
|
9
|
+
def initialize(checked_by)
|
|
10
|
+
super checked_by
|
|
11
|
+
raise parsing_error name = 'IncompatibleCardType', message = "The input Card is not a Checked By but a #{@type}" unless @name.end_with? 'checked by'
|
|
12
|
+
|
|
13
|
+
@checks = get_content 'checks'
|
|
14
|
+
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require_relative '../error'
|
|
2
|
+
|
|
3
|
+
module Wikirate4ruby
|
|
4
|
+
module Entities
|
|
5
|
+
class Company < Entities::Card
|
|
6
|
+
ATTRIBUTES = %i[headquarters wikipedia aliases open_corporates os_id cik answers_url].freeze
|
|
7
|
+
attr_reader(*ATTRIBUTES)
|
|
8
|
+
|
|
9
|
+
def initialize(company)
|
|
10
|
+
super company
|
|
11
|
+
raise parsing_error name = "IncompatibleCardType", message = "The input Card is not a Company but a #{@type}" if @type != "Company"
|
|
12
|
+
|
|
13
|
+
@headquarters = get_content 'headquarters'
|
|
14
|
+
@wikipedia = get_content 'wikipedia'
|
|
15
|
+
@aliases = get_content 'aliases'
|
|
16
|
+
@open_corporates = get_content 'open_corporates'
|
|
17
|
+
@os_id = get_content 'oar_id'
|
|
18
|
+
@cik = get_content 'cik'
|
|
19
|
+
@answers_url = get_content 'answers_url'
|
|
20
|
+
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require_relative '../error'
|
|
2
|
+
|
|
3
|
+
module Wikirate4ruby
|
|
4
|
+
module Entities
|
|
5
|
+
class CompanyGroup < Entities::Card
|
|
6
|
+
ATTRIBUTES = %i[links companies specification].freeze
|
|
7
|
+
attr_reader(*ATTRIBUTES)
|
|
8
|
+
|
|
9
|
+
def initialize(company_group)
|
|
10
|
+
super company_group
|
|
11
|
+
raise parsing_error name = "IncompatibleCardType", message = "The input Card is not a Company Group but a #{@type}" if @type != 'Company Group'
|
|
12
|
+
|
|
13
|
+
@links = get_content 'links'
|
|
14
|
+
@companies = get_content 'companies'
|
|
15
|
+
@specification = get_content 'specification'
|
|
16
|
+
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require_relative '../error'
|
|
2
|
+
|
|
3
|
+
module Wikirate4ruby
|
|
4
|
+
module Entities
|
|
5
|
+
class Dataset < Entities::Card
|
|
6
|
+
ATTRIBUTES = %i[answers metrics companies license].freeze
|
|
7
|
+
attr_reader(*ATTRIBUTES)
|
|
8
|
+
|
|
9
|
+
def initialize(dataset)
|
|
10
|
+
super dataset
|
|
11
|
+
raise parsing_error name = "IncompatibleCardType", message = "The input Card is not a Dataset but a #{@type}" if @type != 'Data Set'
|
|
12
|
+
|
|
13
|
+
@answers = get_array_of 'items', Answer
|
|
14
|
+
@metrics = get_content 'metrics'
|
|
15
|
+
@companies = get_content 'companies'
|
|
16
|
+
@license = get_content 'license'
|
|
17
|
+
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|