Ask A Question

Notifications

You’re not receiving notifications from this thread.

Can some explain this line of code

hkauroberoi asked in Ruby

Hello,

I'm following a RUBY code and writing a small script in php that will accept post request (json) and show values. However, the following line puzzles me - what does params["payload"] is doing ?

params = CGI::parse(post_body)
digest = Digest::SHA1.hexdigest(params[“payload”].to_json+secret_key)

{
"payload": {
"useriden": "900af657a65e",
"score": 50,
"Average": 25
},
"signature": "af886289"
}

Reply

Hi,

params is a json-blob that "basically" comes from the users browser. So for a HTTP GET request, if someone visits a URL like: /users?something=test&name=john - then params will look like:

{
something: "test",
name: "john"
}

The same basically goes for a HTTP POST request.

So params["payload"] in your example, references the content within:
"payload": {
"useriden": "900af657a65e",
"score": 50,
"Average": 25
},

so { useriden: "900af657a65e", score: 50, average: 25 }

I hope that makes sense? It's essentially data that hits the ruby backend via a HTTP request.

Reply

Perfect.. Thanks !!

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 82,329+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.