[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: Matxin MT: Use an API key to access the service

2017-10-09 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/382111 )

Change subject: Matxin MT: Use an API key to access the service
..


Matxin MT: Use an API key to access the service

As Matxin maintainers suggested, the API is adding a key to
control the usage of service.

Change-Id: Ib5c40b907ffdc251f0e7af1de9b8b95f2201257a
---
M config.dev.yaml
M lib/mt/Matxin.js
2 files changed, 29 insertions(+), 1 deletion(-)

Approvals:
  jenkins-bot: Verified
  Nikerabbit: Looks good to me, approved



diff --git a/config.dev.yaml b/config.dev.yaml
index 38625ac..39fe097 100644
--- a/config.dev.yaml
+++ b/config.dev.yaml
@@ -86,6 +86,7 @@
 Matxin:
   api: http://matxin.elhuyar.eus/API
   languages: config/Matxin.yaml
+  key: null
   dictionary:
 Dictd:
   languages: config/Dictd.yaml
diff --git a/lib/mt/Matxin.js b/lib/mt/Matxin.js
index c48959d..c39e7dd 100644
--- a/lib/mt/Matxin.js
+++ b/lib/mt/Matxin.js
@@ -23,10 +23,37 @@
return preq.post( {
uri: this.conf.mt.Matxin.api,
body: {
+   key: this.conf.mt.Matxin.key,
direction: sourceLang + '-' + targetLang,
text: sourceText
}
-   } ).then( ( response ) => response.body.translation.replace( 
/\. ॥ ॥\. /g, '.॥॥.' ) );
+   } ).then( ( response ) => response.body.translation.replace( 
/\. ॥ ॥\. /g, '.॥॥.' ) )
+   .catch( ( response ) => {
+   throw new Error( 'Translation with Matxin 
failed. Error: ' +
+   this.getErrorName( response.status ) + 
' ' + sourceLang + '-' + targetLang );
+   } );
+   }
+
+   /**
+* Returns error name from error code.
+*
+* @param {number} code Error code
+* @return {string}
+*/
+   getErrorName( code ) {
+   const errormap = {
+   403: 'Invalid api key'
+   };
+
+   if ( code in errormap ) {
+   return errormap[ code ];
+   }
+
+   return `Unknown error: ${code}`;
+   }
+
+   requiresAuthorization() {
+   return true;
}
 }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/382111
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ib5c40b907ffdc251f0e7af1de9b8b95f2201257a
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/services/cxserver
Gerrit-Branch: master
Gerrit-Owner: Santhosh 
Gerrit-Reviewer: Catrope 
Gerrit-Reviewer: KartikMistry 
Gerrit-Reviewer: Nikerabbit 
Gerrit-Reviewer: jenkins-bot <>

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: Matxin MT: Use an API key to access the service

2017-10-03 Thread Santhosh (Code Review)
Santhosh has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/382111 )

Change subject: Matxin MT: Use an API key to access the service
..

Matxin MT: Use an API key to access the service

As Matchin maintainers suggested, the API is adding a key to
control the usage of service.

Change-Id: Ib5c40b907ffdc251f0e7af1de9b8b95f2201257a
---
M lib/mt/Matxin.js
1 file changed, 5 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver 
refs/changes/11/382111/1

diff --git a/lib/mt/Matxin.js b/lib/mt/Matxin.js
index c48959d..6b9546f 100644
--- a/lib/mt/Matxin.js
+++ b/lib/mt/Matxin.js
@@ -23,11 +23,16 @@
return preq.post( {
uri: this.conf.mt.Matxin.api,
body: {
+   key: this.conf.mt.Matxin.key,
direction: sourceLang + '-' + targetLang,
text: sourceText
}
} ).then( ( response ) => response.body.translation.replace( 
/\. ॥ ॥\. /g, '.॥॥.' ) );
}
+
+   requiresAuthorization() {
+   return true;
+   }
 }
 
 module.exports = Matxin;

-- 
To view, visit https://gerrit.wikimedia.org/r/382111
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib5c40b907ffdc251f0e7af1de9b8b95f2201257a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/cxserver
Gerrit-Branch: master
Gerrit-Owner: Santhosh 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits