How to use ibm watson tone analyzer api with Rails 5 and JS?
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
add a comment |
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
add a comment |
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
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
javascript ruby-on-rails api
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
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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:
index
(where you ask users to input the desired text)
process
(an action that accepts the form input, sends an API request and retrieves the response)
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.
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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:
index
(where you ask users to input the desired text)
process
(an action that accepts the form input, sends an API request and retrieves the response)
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.
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
add a comment |
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:
index
(where you ask users to input the desired text)
process
(an action that accepts the form input, sends an API request and retrieves the response)
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.
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
add a comment |
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:
index
(where you ask users to input the desired text)
process
(an action that accepts the form input, sends an API request and retrieves the response)
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.
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:
index
(where you ask users to input the desired text)
process
(an action that accepts the form input, sends an API request and retrieves the response)
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.
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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