Class: Wikirate4ruby::REST::Client
- Inherits:
-
Object
- Object
- Wikirate4ruby::REST::Client
- Includes:
- Entities, Wikirate4ruby::RequestUtils, Utils
- Defined in:
- lib/wikirate4ruby/client.rb
Constant Summary collapse
- BASE_URL =
'https://wikirate.org'
Instance Attribute Summary collapse
-
#request ⇒ Object
readonly
Returns the value of attribute request.
Instance Method Summary collapse
- #add_company(data = {}) ⇒ Wikirate4ruby::Entities::Company
- #add_relationship_metric_answer(data = {}) ⇒ Object
- #add_research_metric_answer(data = {}) ⇒ Object
- #add_source(data = {}) ⇒ Wikirate4ruby::Entities::Source
- #get_answer(identifier) ⇒ Object
- #get_answers(metric_name, metric_designer, params = {}) ⇒ Object
- #get_answers_by_metric_id(metric_id, params = {}) ⇒ Object
- #get_card(identifier) ⇒ Object
- #get_checked_by(identifier) ⇒ Object
- #get_companies(params = {}) ⇒ Object
- #get_company(identifier) ⇒ Object
- #get_company_answers(identifier, params = {}) ⇒ Object
- #get_company_group(identifier) ⇒ Object
- #get_company_groups(params = {}) ⇒ Object
- #get_dataset(identifier) ⇒ Object
- #get_datasets(params = {}) ⇒ Object
- #get_metric(identifier) ⇒ Object
- #get_metrics(params = {}) ⇒ Object
- #get_project(identifier) ⇒ Object
- #get_projects(params = {}) ⇒ Object
- #get_region(identifier) ⇒ Object
- #get_relationship_answer(identifier) ⇒ Object
- #get_relationship_answers(metric_name, metric_designer, params = {}) ⇒ Object
- #get_relationship_answers_by_metric_id(metric_id, params = {}) ⇒ Object
- #get_research_group(identifier) ⇒ Object
- #get_research_groups(params = {}) ⇒ Object
- #get_source(identifier) ⇒ Object
- #get_sources(params = {}) ⇒ Object
- #get_topic(identifier) ⇒ Object
- #get_topics(params = {}) ⇒ Object
-
#initialize(api_key, wikirate_api_url = BASE_URL, auth = {}) ⇒ Client
constructor
A new instance of Client.
- #update_company(data = {}) ⇒ Object
- #update_relationship_metric_answer(data = {}) ⇒ Object
- #update_research_metric_answer(data = {}) ⇒ Object
- #update_source(data = {}) ⇒ Object
Constructor Details
#initialize(api_key, wikirate_api_url = BASE_URL, auth = {}) ⇒ Client
Returns a new instance of Client.
29 30 31 32 |
# File 'lib/wikirate4ruby/client.rb', line 29 def initialize(api_key, wikirate_api_url = BASE_URL, auth = {}) @request = Request.new(api_key, wikirate_api_url, auth) @logger = Logger.new(STDOUT) end |
Instance Attribute Details
#request ⇒ Object (readonly)
Returns the value of attribute request.
27 28 29 |
# File 'lib/wikirate4ruby/client.rb', line 27 def request @request end |
Instance Method Details
#add_company(data = {}) ⇒ Wikirate4ruby::Entities::Company
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/wikirate4ruby/client.rb', line 238 def add_company(data = {}) required_params = %w[name headquarters] required_params.each do |param| if data[param].nil? || data[param] == '' raise Wikirate4ruby::Error::Wikirate4rubyError, "Invalid set of params! You need to define all the following params to import a new company: #{required_params.to_s}" end end card_name = data['name'] data.delete('name') params = creation_params('Company', data, %w[headquarters oar_id wikipedia open_corporates sec_cik]) params['card[name]'] = card_name params['confirmed'] = true params['card[skip]'] = 'update_oc_mapping_due_to_headquarters_entry' if data['open_corporates'].nil? response = @request.post('/card/create', params) Company.new(response) end |
#add_relationship_metric_answer(data = {}) ⇒ Object
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
# File 'lib/wikirate4ruby/client.rb', line 315 def add_relationship_metric_answer(data = {}) required_params = %w[metric_designer metric_name subject_company object_company year value source] required_params.each do |param| if data[param].nil? || data[param] == '' raise Wikirate4ruby::Error::Wikirate4rubyError, "Invalid set of params! You need to define all the following params to import a new research answer: #{required_params.to_s}" end end card_name = "#{data['metric_designer']}+#{data['metric_name']}+#{str_identifier(data['subject_company'])}+#{data['year']}+#{str_identifier(data['object_company'])}" %w[metric_designer metric_name subject_company object_company year].each do |key| data.delete key end params = creation_params('RelationshipAnswer', data, %w[source value comments]) params['card[name]'] = card_name response = @request.post('/card/create', params) RelationshipAnswer.new(response) end |
#add_research_metric_answer(data = {}) ⇒ Object
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 |
# File 'lib/wikirate4ruby/client.rb', line 270 def add_research_metric_answer(data = {}) required_params = %w[metric_designer metric_name company year value source] required_params.each do |param| if data[param].nil? || data[param] == '' raise Wikirate4ruby::Error::Wikirate4rubyError, "Invalid set of params! You need to define all the following params to import a new research answer: #{required_params.to_s}" end end card_name = "#{data['metric_designer']}+#{data['metric_name']}+#{str_identifier(data['company'])}+#{data['year']}" %w[metric_designer metric_name company year].each do |key| data.delete key end params = creation_params('Answer', data, %w[source value discussion]) params['card[name]'] = card_name response = @request.post('/card/create', params) Answer.new(response) end |
#add_source(data = {}) ⇒ Wikirate4ruby::Entities::Source
360 361 362 363 364 365 366 367 368 369 370 371 372 |
# File 'lib/wikirate4ruby/client.rb', line 360 def add_source(data = {}) required_params = %w[link title] required_params.each do |param| if data[param].nil? || data[param] == '' raise Wikirate4ruby::Error::Wikirate4rubyError, "Invalid set of params! You need to define all the following params to import a new source: #{required_params.to_s}" end end params = creation_params('Source', data, %w[link title company report_type year]) params['card[skip]'] = 'requirements' response = @request.post('/card/create', params) Source.new(response) end |
#get_answer(identifier) ⇒ Object
42 43 44 |
# File 'lib/wikirate4ruby/client.rb', line 42 def get_answer(identifier) get_entity(identifier, Answer) end |
#get_answers(metric_name, metric_designer, params = {}) ⇒ Object
174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/wikirate4ruby/client.rb', line 174 def get_answers(metric_name, metric_designer, params = {}) answers = [] response = @request.get("/#{tranform_to_wr_friendly_name(metric_designer)}+#{tranform_to_wr_friendly_name(metric_name)}+Answers.json", endpoint_params = %w[limit offset], filters = %w[year verification value value_from value_to status source updated updater published dataset company_id company_name company_category company_group country], params) response['items'].each do |item| answers.append(Answer.new(item)) end answers end |
#get_answers_by_metric_id(metric_id, params = {}) ⇒ Object
187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/wikirate4ruby/client.rb', line 187 def get_answers_by_metric_id(metric_id, params = {}) answers = [] response = @request.get("/#{str_identifier(metric_id)}+Answers.json", endpoint_params = %w[limit offset], filters = %w[year verification value value_from value_to status source updated updater published dataset company_id company_name company_category company_group country], params) response['items'].each do |item| answers.append(Answer.new(item)) end answers end |
#get_card(identifier) ⇒ Object
74 75 76 |
# File 'lib/wikirate4ruby/client.rb', line 74 def get_card(identifier) get_entity(identifier, Card) end |
#get_checked_by(identifier) ⇒ Object
78 79 80 |
# File 'lib/wikirate4ruby/client.rb', line 78 def get_checked_by(identifier) get_entity(identifier, CheckedBy) end |
#get_companies(params = {}) ⇒ Object
86 87 88 89 90 91 92 93 94 95 |
# File 'lib/wikirate4ruby/client.rb', line 86 def get_companies(params = {}) companies = [] response = @request.get('/Companies.json', endpoint_params = %w[limit offset], filters = %w[name company_category company_group country], params) response['items'].each do |item| companies.append(Company.new(item)) end companies end |
#get_company(identifier) ⇒ Object
34 35 36 |
# File 'lib/wikirate4ruby/client.rb', line 34 def get_company(identifier) get_entity(identifier, Company) end |
#get_company_answers(identifier, params = {}) ⇒ Object
199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/wikirate4ruby/client.rb', line 199 def get_company_answers(identifier, params = {}) answers = [] endpoint = "/#{str_identifier(identifier)}+Answers.json" response = @request.get(endpoint, endpoint_params = %w[limit offset], filters = %w[metric_name designer metric_type value_type research_policy year verification value value_from value_to status source updated updater published dataset company_id company_name company_category company_group country], params) response['items'].each do |item| answers.append(Answer.new(item)) end answers end |
#get_company_group(identifier) ⇒ Object
54 55 56 |
# File 'lib/wikirate4ruby/client.rb', line 54 def get_company_group(identifier) get_entity(identifier, CompanyGroup) end |
#get_company_groups(params = {}) ⇒ Object
163 164 165 166 167 168 169 170 171 172 |
# File 'lib/wikirate4ruby/client.rb', line 163 def get_company_groups(params = {}) company_groups = [] response = @request.get('/Company_Groups.json', endpoint_params = %w[limit offset], filters = %w[name], params) response['items'].each do |item| company_groups.append(CompanyGroup.new(item)) end company_groups end |
#get_dataset(identifier) ⇒ Object
50 51 52 |
# File 'lib/wikirate4ruby/client.rb', line 50 def get_dataset(identifier) get_entity(identifier, Dataset) end |
#get_datasets(params = {}) ⇒ Object
119 120 121 122 123 124 125 126 127 128 |
# File 'lib/wikirate4ruby/client.rb', line 119 def get_datasets(params = {}) datasets = [] response = @request.get('/Data_Sets.json', endpoint_params = %w[limit offset], filters = %w[name bookmark wikirate_topic], params) response['items'].each do |item| datasets.append(Dataset.new(item)) end datasets end |
#get_metric(identifier) ⇒ Object
38 39 40 |
# File 'lib/wikirate4ruby/client.rb', line 38 def get_metric(identifier) get_entity(identifier, Metric) end |
#get_metrics(params = {}) ⇒ Object
97 98 99 100 101 102 103 104 105 106 |
# File 'lib/wikirate4ruby/client.rb', line 97 def get_metrics(params = {}) metrics = [] response = @request.get('/Metrics.json', endpoint_params = %w[limit offset], filters = %w[name bookmark wikirate_topic designer published metric_type value_type research_policy dataset], params) response['items'].each do |item| metrics.append(Metric.new(item)) end metrics end |
#get_project(identifier) ⇒ Object
82 83 84 |
# File 'lib/wikirate4ruby/client.rb', line 82 def get_project(identifier) get_entity(identifier, Card) end |
#get_projects(params = {}) ⇒ Object
130 131 132 133 134 135 136 137 138 139 |
# File 'lib/wikirate4ruby/client.rb', line 130 def get_projects(params = {}) projects = [] response = @request.get('/Projects.json', endpoint_params = %w[limit offset], filters = %w[name wikirate_status], params) response['items'].each do |item| projects.append(Card.new(item)) end projects end |
#get_region(identifier) ⇒ Object
70 71 72 |
# File 'lib/wikirate4ruby/client.rb', line 70 def get_region(identifier) get_entity(identifier, Region) end |
#get_relationship_answer(identifier) ⇒ Object
46 47 48 |
# File 'lib/wikirate4ruby/client.rb', line 46 def get_relationship_answer(identifier) get_entity(identifier, RelationshipAnswer) end |
#get_relationship_answers(metric_name, metric_designer, params = {}) ⇒ Object
213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/wikirate4ruby/client.rb', line 213 def get_relationship_answers(metric_name, metric_designer, params = {}) answers = [] response = @request.get("/#{tranform_to_wr_friendly_name(metric_designer)}+#{tranform_to_wr_friendly_name(metric_name)}+RelationshipAnswers.json", endpoint_params = %w[limit offset], filters = %w[year name company_category company_group dataset updated updater source published], params) response['items'].each do |item| answers.append(RelationshipAnswer.new(item)) end answers end |
#get_relationship_answers_by_metric_id(metric_id, params = {}) ⇒ Object
225 226 227 228 229 230 231 232 233 234 |
# File 'lib/wikirate4ruby/client.rb', line 225 def get_relationship_answers_by_metric_id(metric_id, params = {}) answers = [] response = @request.get("/#{str_identifier(metric_id)}+RelationshipAnswers.json", endpoint_params = %w[limit offset], filters = %w[year name company_category company_group dataset updated updater source published], params) response['items'].each do |item| answers.append(RelationshipAnswer.new(item)) end answers end |
#get_research_group(identifier) ⇒ Object
62 63 64 |
# File 'lib/wikirate4ruby/client.rb', line 62 def get_research_group(identifier) get_entity(identifier, ResearchGroup) end |
#get_research_groups(params = {}) ⇒ Object
152 153 154 155 156 157 158 159 160 161 |
# File 'lib/wikirate4ruby/client.rb', line 152 def get_research_groups(params = {}) research_groups = [] response = @request.get('/Research_Groups.json', endpoint_params = %w[limit offset], filters = %w[name], params) response['items'].each do |item| research_groups.append(ResearchGroup.new(item)) end research_groups end |
#get_source(identifier) ⇒ Object
66 67 68 |
# File 'lib/wikirate4ruby/client.rb', line 66 def get_source(identifier) get_entity(identifier, Source) end |
#get_sources(params = {}) ⇒ Object
141 142 143 144 145 146 147 148 149 150 |
# File 'lib/wikirate4ruby/client.rb', line 141 def get_sources(params = {}) sources = [] response = @request.get('/Sources.json', endpoint_params = %w[limit offset], filters = %w[name wikirate_title wikirate_topic report_type year wikirate_link company_name], params) response['items'].each do |item| sources.append(Source.new(item)) end sources end |
#get_topic(identifier) ⇒ Object
58 59 60 |
# File 'lib/wikirate4ruby/client.rb', line 58 def get_topic(identifier) get_entity(identifier, Topic) end |
#get_topics(params = {}) ⇒ Object
108 109 110 111 112 113 114 115 116 117 |
# File 'lib/wikirate4ruby/client.rb', line 108 def get_topics(params = {}) topics = [] response = @request.get('/Topics.json', endpoint_params = %w[limit offset], filters = %w[name bookmark], params) response['items'].each do |item| topics.append(Topic.new(item)) end topics end |
#update_company(data = {}) ⇒ Object
256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/wikirate4ruby/client.rb', line 256 def update_company(data = {}) if data['company'].nil? || data['company'] == '' raise Wikirate4ruby::Error::Wikirate4rubyError, "Invalid set of params! You need to define all the following params to update a company: [company]" end card_name = str_identifier(data['company']) data.delete 'company' params = creation_params('Company', data, %w[headquarters open_corporates oar_id wikipedia sec_cik]) params['card[name]'] = card_name response = @request.post('/card/update', params) Company.new(response) end |
#update_relationship_metric_answer(data = {}) ⇒ Object
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 |
# File 'lib/wikirate4ruby/client.rb', line 333 def update_relationship_metric_answer(data = {}) required_params = %w[metric_designer metric_name subject_company object_company year] if data['answer_id'].nil? required_params.each do |param| if data[param].nil? || data[param] == '' raise Wikirate4ruby::Error::Wikirate4rubyError, "Invalid set of params! You need to define all the following params to import a new research answer: #{required_params.to_s}" end end card_name = "#{data['metric_designer']}+#{data['metric_name']}+#{str_identifier(data['company'])}+#{data['year']}" %w[metric_designer metric_name subject_company year object_company].each do |key| data.delete key end allowed_params = %w[source value discussion] else card_name = str_identifier(data['answer_id']) data.delete 'answer_id' allowed_params = %w[year source value discussion] end params = creation_params('RelationshipAnswer', data, allowed_params) response = @request.post("/update/#{card_name}", params) RelationshipAnswer.new(response) end |
#update_research_metric_answer(data = {}) ⇒ Object
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
# File 'lib/wikirate4ruby/client.rb', line 288 def update_research_metric_answer(data = {}) required_params = %w[metric_designer metric_name company] if data['answer_id'].nil? required_params.each do |param| if data[param].nil? || data[param] == '' raise Wikirate4ruby::Error::Wikirate4rubyError, "Invalid set of params! You need to define all the following params to import a new research answer: #{required_params.to_s}" end end card_name = "#{data['metric_designer']}+#{data['metric_name']}+#{str_identifier(data['company'])}+#{data['year']}" %w[metric_designer metric_name company year].each do |key| data.delete key end allowed_params = %w[source value discussion] else card_name = str_identifier(data['answer_id']) data.delete 'answer_id' allowed_params = %w[year source value discussion] end params = creation_params('Answer', data, allowed_params) params['card[name]'] = card_name puts(params) response = @request.post('/card/update', params) Answer.new(response) end |
#update_source(data = {}) ⇒ Object
374 375 376 377 378 379 380 381 382 383 384 385 |
# File 'lib/wikirate4ruby/client.rb', line 374 def update_source(data = {}) if data['source'].nil? || data['source'] == '' raise Wikirate4ruby::Error::Wikirate4rubyError, "Invalid set of params! You need to define all the following params to update a source: [source]" end card_name = str_identifier(data['source']) data.delete 'source' params = creation_params('Source', data, %w[link title company report_type year]) params['card[skip]'] = 'requirements' response = @request.post("/update/#{card_name}", params) Source.new(response) end |