"using a 3rd party API"

sgenzer
sgenzer
Altair Employee
edited November 5 in Community Q&A
Hi...I am foolishly trying to do something beyond my comp sci abilities - extending RM.  Specifically I am trying to use this API within "Execute Script" in order to pull data into RM:
import com.benwaffle.pslib.PSlib;
PSlib api = new PSlib("https://ps01.bergen.org");
api.login("username","password");
Grade[] grades = api.getCourses()[0].getGrades();

for (Grade g : grades)
 System.out.printf("%s - %d%%", g.name(), g.score());
I put the PSlib.jar file into the /lib folder and I get an error that says..."unable to resolve class com.benwaffle.pslib.PSlib..."
 
Help?  I have NOT done the tutorial on how to build RM extensions as I am not a programmer and certainly do not know how to program in Groovy or Gradle.  The API was pulled from here: https://github.com/benwaffle/PSlib

Thanks!

Answers

  • Marco_Boeck
    Marco_Boeck New Altair Community Member
    Hi,

    you are on the right track - however the .jar you added to your /lib folder does not contain the class "com.benwaffle.pslib.PSlib". You can open a .jar with any tool used to extract .zip files. You can then have a look at the folders and .class files in there. Folders represent the package structure (e.g. "com.benwaffle.pslib"), and the .class files are the actual Java classes (e.g. "PSlib").
    You will see that neither the folders nor the class exist in the .jar which is why you Studio complained it knew nothing about the imported class.

    Regards,
    Marco
  • sgenzer
    sgenzer
    Altair Employee
    HI Marco -

    I was hoping you would chime in to help.  :)

    Yes that part I understand but I believe the file is in the jar file.  Here is a screenshot of the file structure when I unzip:

    http://bit.ly/17b8snJ

    so as far as I can see, the class "com.benwaffle.pslib.PSlib" seems to be in psapi.jar.  Am I missing something?

    Scott
  • Marco_Boeck
    Marco_Boeck New Altair Community Member
    Hi,

    I cannot access that link. I checked the jar available for download on github. Anyway, I quickly threw together an example. Simply place the test.jar in the lib folder and execute the process below. A popup dialog should appear and convince you that it works ;)
    Download: test.jar

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <process version="6.3.000">
     <context>
       <input/>
       <output/>
       <macros/>
     </context>
     <operator activated="true" class="process" compatibility="6.3.000" expanded="true" name="Process">
       <process expanded="true">
         <operator activated="true" class="retrieve" compatibility="6.3.000" expanded="true" height="60" name="Retrieve Deals" width="90" x="45" y="30">
           <parameter key="repository_entry" value="//Samples/data/Deals"/>
         </operator>
         <operator activated="true" class="execute_script" compatibility="6.3.000" expanded="true" height="76" name="Execute Script" width="90" x="179" y="30">
           <parameter key="script" value="import com.test.Test;&#10;&#10;Test.test();&#10;&#10;return input[0];"/>
         </operator>
         <connect from_op="Retrieve Deals" from_port="output" to_op="Execute Script" to_port="input 1"/>
         <connect from_op="Execute Script" from_port="output 1" to_port="result 1"/>
         <portSpacing port="source_input 1" spacing="0"/>
         <portSpacing port="sink_result 1" spacing="0"/>
         <portSpacing port="sink_result 2" spacing="0"/>
       </process>
     </operator>
    </process>
    Regards,
    Marco
  • sgenzer
    sgenzer
    Altair Employee
    Hi Marco -

    Thanks so much - I got that to work easily and will go back and see why this other file does not work.  The template is very useful.

    Scott
  • sgenzer
    sgenzer
    Altair Employee
    OK this is too hard for me.  Are there any developers out there who can help adapt an educational API to RapidMiner?  I have all the API documentation; I just do not have the skill set to make it happen.

    Thanks!!

    Scott