How to use ibm watson tone analyzer api with Rails 5 and JS?












0














I am working on a project that uses Ruby on Rails 5 for the backend and plain Javascript/HTML (no JQuery or Node.js yet) for the frontend. My backend and frontend are required to be in two separate files.



I want to use an external api, IBM Watson Tone Analyzer, to detect emotion from text. I am not sure how to proceed with fetching the api url or what the base uri even is (I think it's 'https://gateway.watsonplatform.net/tone-analyzer/api'). So far, I have this following code in my TextInputsController:



tone_analyzer = IBMWatson::ToneAnalyzerV3.new(
iam_apikey: ENV['IBMWATSON_API_KEY'],
version: "2017-09-21"
)

result = tone_analyzer.tone(
tone_input: "I am very happy. It is a good day.",
content_type: "text/plain"
).result

render json: result


When I navigate to localhost:3000/text_inputs, this is what I see:



localhost:3000/text_inputs



My question is, how would I grab text input (which is handled by Javascript/HTML) and use it within the 'tone_input' key?



Please keep in mind, I am a beginner in programming with Rails and JS!










share|improve this question





























    0














    I am working on a project that uses Ruby on Rails 5 for the backend and plain Javascript/HTML (no JQuery or Node.js yet) for the frontend. My backend and frontend are required to be in two separate files.



    I want to use an external api, IBM Watson Tone Analyzer, to detect emotion from text. I am not sure how to proceed with fetching the api url or what the base uri even is (I think it's 'https://gateway.watsonplatform.net/tone-analyzer/api'). So far, I have this following code in my TextInputsController:



    tone_analyzer = IBMWatson::ToneAnalyzerV3.new(
    iam_apikey: ENV['IBMWATSON_API_KEY'],
    version: "2017-09-21"
    )

    result = tone_analyzer.tone(
    tone_input: "I am very happy. It is a good day.",
    content_type: "text/plain"
    ).result

    render json: result


    When I navigate to localhost:3000/text_inputs, this is what I see:



    localhost:3000/text_inputs



    My question is, how would I grab text input (which is handled by Javascript/HTML) and use it within the 'tone_input' key?



    Please keep in mind, I am a beginner in programming with Rails and JS!










    share|improve this question



























      0












      0








      0







      I am working on a project that uses Ruby on Rails 5 for the backend and plain Javascript/HTML (no JQuery or Node.js yet) for the frontend. My backend and frontend are required to be in two separate files.



      I want to use an external api, IBM Watson Tone Analyzer, to detect emotion from text. I am not sure how to proceed with fetching the api url or what the base uri even is (I think it's 'https://gateway.watsonplatform.net/tone-analyzer/api'). So far, I have this following code in my TextInputsController:



      tone_analyzer = IBMWatson::ToneAnalyzerV3.new(
      iam_apikey: ENV['IBMWATSON_API_KEY'],
      version: "2017-09-21"
      )

      result = tone_analyzer.tone(
      tone_input: "I am very happy. It is a good day.",
      content_type: "text/plain"
      ).result

      render json: result


      When I navigate to localhost:3000/text_inputs, this is what I see:



      localhost:3000/text_inputs



      My question is, how would I grab text input (which is handled by Javascript/HTML) and use it within the 'tone_input' key?



      Please keep in mind, I am a beginner in programming with Rails and JS!










      share|improve this question















      I am working on a project that uses Ruby on Rails 5 for the backend and plain Javascript/HTML (no JQuery or Node.js yet) for the frontend. My backend and frontend are required to be in two separate files.



      I want to use an external api, IBM Watson Tone Analyzer, to detect emotion from text. I am not sure how to proceed with fetching the api url or what the base uri even is (I think it's 'https://gateway.watsonplatform.net/tone-analyzer/api'). So far, I have this following code in my TextInputsController:



      tone_analyzer = IBMWatson::ToneAnalyzerV3.new(
      iam_apikey: ENV['IBMWATSON_API_KEY'],
      version: "2017-09-21"
      )

      result = tone_analyzer.tone(
      tone_input: "I am very happy. It is a good day.",
      content_type: "text/plain"
      ).result

      render json: result


      When I navigate to localhost:3000/text_inputs, this is what I see:



      localhost:3000/text_inputs



      My question is, how would I grab text input (which is handled by Javascript/HTML) and use it within the 'tone_input' key?



      Please keep in mind, I am a beginner in programming with Rails and JS!







      javascript ruby-on-rails api






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 13 '18 at 7:44









      Krupesh Kotecha

      2,05011134




      2,05011134










      asked Nov 13 '18 at 7:35









      J.KJ.K

      1




      1
























          1 Answer
          1






          active

          oldest

          votes


















          0














          You already got a response from the API, which is great! You just need to take a deeper look at the entire Rails MVC architecture: start with defining actions in your controller and creating basic views for your TextInputsController. Let's say, 3 actions:





          1. index (where you ask users to input the desired text)


          2. process (an action that accepts the form input, sends an API request and retrieves the response)


          3. show display output to the user


          Rails Guides is a good source of information on everything you need.



          Try reading through Getting Started and see if you can change the example to accomplish your task.






          share|improve this answer





















          • I am not using views for this project because my frontend is taken care by Javascript only.
            – J.K
            Nov 13 '18 at 16:37











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53275994%2fhow-to-use-ibm-watson-tone-analyzer-api-with-rails-5-and-js%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          You already got a response from the API, which is great! You just need to take a deeper look at the entire Rails MVC architecture: start with defining actions in your controller and creating basic views for your TextInputsController. Let's say, 3 actions:





          1. index (where you ask users to input the desired text)


          2. process (an action that accepts the form input, sends an API request and retrieves the response)


          3. show display output to the user


          Rails Guides is a good source of information on everything you need.



          Try reading through Getting Started and see if you can change the example to accomplish your task.






          share|improve this answer





















          • I am not using views for this project because my frontend is taken care by Javascript only.
            – J.K
            Nov 13 '18 at 16:37
















          0














          You already got a response from the API, which is great! You just need to take a deeper look at the entire Rails MVC architecture: start with defining actions in your controller and creating basic views for your TextInputsController. Let's say, 3 actions:





          1. index (where you ask users to input the desired text)


          2. process (an action that accepts the form input, sends an API request and retrieves the response)


          3. show display output to the user


          Rails Guides is a good source of information on everything you need.



          Try reading through Getting Started and see if you can change the example to accomplish your task.






          share|improve this answer





















          • I am not using views for this project because my frontend is taken care by Javascript only.
            – J.K
            Nov 13 '18 at 16:37














          0












          0








          0






          You already got a response from the API, which is great! You just need to take a deeper look at the entire Rails MVC architecture: start with defining actions in your controller and creating basic views for your TextInputsController. Let's say, 3 actions:





          1. index (where you ask users to input the desired text)


          2. process (an action that accepts the form input, sends an API request and retrieves the response)


          3. show display output to the user


          Rails Guides is a good source of information on everything you need.



          Try reading through Getting Started and see if you can change the example to accomplish your task.






          share|improve this answer












          You already got a response from the API, which is great! You just need to take a deeper look at the entire Rails MVC architecture: start with defining actions in your controller and creating basic views for your TextInputsController. Let's say, 3 actions:





          1. index (where you ask users to input the desired text)


          2. process (an action that accepts the form input, sends an API request and retrieves the response)


          3. show display output to the user


          Rails Guides is a good source of information on everything you need.



          Try reading through Getting Started and see if you can change the example to accomplish your task.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 13 '18 at 8:15









          mkrlmkrl

          470214




          470214












          • I am not using views for this project because my frontend is taken care by Javascript only.
            – J.K
            Nov 13 '18 at 16:37


















          • I am not using views for this project because my frontend is taken care by Javascript only.
            – J.K
            Nov 13 '18 at 16:37
















          I am not using views for this project because my frontend is taken care by Javascript only.
          – J.K
          Nov 13 '18 at 16:37




          I am not using views for this project because my frontend is taken care by Javascript only.
          – J.K
          Nov 13 '18 at 16:37


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53275994%2fhow-to-use-ibm-watson-tone-analyzer-api-with-rails-5-and-js%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Bressuire

          Vorschmack

          Quarantine