def update_comment(youtube, comment):
comment['snippet']['viewerRating'] = 'like'
comment['snippet']['textOriginal'] = 'some text' # Note this is important parameter
update_result = youtube.comments().update(
part='snippet',
body=comment
).execute()
This code simply updating comment and rate Like, if this comment is mine.
But, if i want rate another comment, Http Error 400 happens.
So, it it able/possible to rate comment, that is written by other user.
Well, based from the other SO question like this, the rating of comment can only be done in your own comment and not for the other user.
If you also check the documentation of Comments and CommentThreads, there is no way here to achieve the one that you like.
I suggest you to always check the Revision History of the YouTube API to know the latest features that you can do with it.
For more information, check also this SO question.
Related
I am not quite sure what would be a good API design for my scenario below.
We have a model ticket that has an ID and a QR code, both of which are always unique.
To query the status of a ticket, I'm sure this should look obviously like this:
GET /tickets/:id
But what should the design of the QR code API look like?
By also using GET /tickets/:id it would be unclear to the user which locator is being searched for.
GET /tickets?qr_code=:qr_code
would be the second option, but I find this so unpleasant because the returned element is always exactly one and not an array which usually would be the expected response of such a request.
How would a proper API design look like here to query the status of a single ticket by its QR code?
When there are multiple attributes that are unique then that means that each attribute can serve as an identifier in the URL.
Therefore I would document the route in the API like this
GET /tickets/:id_or_qr_code
What basically boils down to the default resource path
GET /tickets/:id
with a controller method like this
def show
#ticket = Ticket.find_by(id: params[:id]) ||
Ticket.find_by(qr_code: params[:id]) ||
# ...
end
I can mark a post by using unread gem.
post = Post.first
post.mark_as_read! for: current_user
But I couldn't find how to "unread" the post that is marked as "read".
How can I make it?
If you take a look at the issues page for the gem on github you'll see that this has been brought up there. There doesn't seem to be an official way to do this with the gem; however, user firedev over on github put up his solution.
def mark_as_unread_except current_user
ReadMark.where(readable_type: self.class.class_name, readable_id: id).each(&:destroy!)
mark_as_read!(for: current_user)
end
This might be what you need. But take a look at the full page for commentary and ideas. As of now, there is no offical way to do this with the gem.
My working approach is:
post.read_mark(current_user).destroy!
I have tried by using the following code,
client = Instagram.client(:access_token => "My_Access_Token")
result = client.create_media_comment("Media_Id", "Comment")
but i'm getting the following error,
POST https://api.instagram.com/v1/media/Media_Id/comments.json: 400: Please visit http://bit.ly/instacomments for commenting access
How can i resolve this?
You should be passing an actual id for the piece of Instagram media on which you want to create a comment rather than the "Media_Id" string.
Your code is correct (otherwise you won't get that error).
You need to go to http://bit.ly/instacomments and ask for commenting permission. Don't expect a reply anytime soon though, I've been waiting for a reply over a month, and seen people getting replies for that after three or four months.
As a learning experience for Ruby and Rails, I am creating a website for taking polls, stores the results, etc. As part of the polling process, a user has to go through a number of questions and provide answers to those questions. When they are done, they receive a list of recommendations based upon the answers they provided (of type Answer).
I have two parts to my question. One, I think I am heading down the right path. The other, I'm not even sure where to begin, and don't know if it is a good idea.
Here is my Answer model:
class Answer
attr_accessor :question_number, :description, :answer
end
Question 1
I am looking for a way that, when the user submits all the answers (I'm storing their responses in session storage), it goes to my search function - but it is encoded nicely.
Instead of:
http://localhost:3000/results/search?[biglongstringofdifferentanswers]
I would like something like:
http://localhost:3000/results/search/1-answer_2-answer_3-answer
After doing some searching, it seems that what I want to accomplish has to be done with the #parameterize method, but I'm not sure I understand how to do that exactly.
Question 2
The second part to my question is - can I encode my answers so that they aren't directly human readable. I want to do this to prevent people from browsing to each other's answers. For example, the first answer is always the person's unique ID and I don't want to someone to be able to just browse to any old set of results by switching around parameters.
So, I am hoping to get something along the lines of:
http://localhost:3000/results/search/798dh832rhhbe89rbfb289f9234972bdbdbbws3
For this second question, I'm not even sure if this is a good idea, so I'm open to suggestions for this one.
Appreciate any help and guidance on these questions as I continue to explore/learn Ruby and RoR.
If I get it right, there is not any login system and you want submitted answers that you store in your DB to be accessable via url for the user. You said you don't want users to navigate to other users' answers but the user getting the url can still share it.
What I would do is to submit answers via POST method, so you don't have to worry about encoding your params etc. It gets then real easy with Rails.
You can add a public_id column to your answer object that would be a generated big int. After the post methoded submit, once you save the answer in your DB, you could return a redirect to the answer public id url.
something like
def create
answer = Answer.new(params[:answer])
if answer.save
answer.generate_public_id # <= would be nice to add if in the answer model 'after_create' filter probably
return redirect_to public_id_answer_path
end
render :partial => 'error'
end
What do you think ?
I'm building a quiz. A user can pick a subject and answer 5 questions. After each question they view the answer. I'm trying to stick to a strict RESTful representation of this workflow but cant really settle on a url scheme. For example:
User Joe picks the subject sport and is ready to see the first question. The url is
user/joe/subject/sport/question/1
When he submits his answer 'B' ( its a multiple choice quiz) , Joe is creating a new answer, we POST to
user/joe/subject/sport/question/1/answer/B
before viewing the correct answer at
user/joe/subject/sport/answer/1
we then view the next question at
user/joe/subject/sport/question/2
This is all obviously too complicated. How would you approach this problem in a RESTful manner?
Start with this presentation. It's is a great resource for RESTful API design. With that in mind, here are some starting suggestions:
RESTful URLs have an implicit hierarchy. Take the user information out of the URL. It belongs in the HTTP headers.
/subject/sport/question/1
/subject/sport/question/1/answer/B
/subject/sport/answer/1
/subject/sport/question/2
I don't see any useful information added by the subject part. The subject is identified by (in your example) sport.
/sport/question/1
/sport/question/1/answer/B
/sport/answer/1
/sport/question/2
Categories should be plural.
/sports/questions/1
/sports/questions/1/answers/B
/sports/answers/1
/sports/questions/2
When you POST to answer a question, you're not POSTing to add a new answer resource (that is, defining a new possible answer). Aren't you are POSTing to an existing resource?
You haven't mentioned anything about HATEOAS. If you're really going to implement REST, you should be doing things like providing "next" links in the hypermedia.
For me the basic idea in a REST service is the "resource". First you need to identify your resources.
So there is a user and she starts a new quiz.
POST /user/joe/quiz.
It returns: Location: /user/joe/quiz/1
Then the user selects a sports question, so you update your quiz to include a random (server selected) question.
POST /user/joe/quiz/1 -> Subject:sport
It returns: Location: /user/joe/quiz/1/question/1
The user answers:
PUT /user/joe/quiz/1/question/1 -> Answer B
Now rinse and repeat.
The resources we've got:
Users
Quiz for a user
Questions in a Quiz (The question is updated with an answer)
I would remove /user/joe from the routes entirely. You can get the current_user using Devise, Authlogic, or some other authentication framework.
Otherwise this looks okay to me, as it's only two nests which is readable enough. So you'd have:
GET subjects/sports/questions/1
POST subjects/sports/questions/1 # pass along params with {:answer => 'B'}
GET subjects/sports/answers/1