Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added support for /posts routes on Answer

this adds calls for suggested edits and revisions for answers
  • Loading branch information...
commit f53af23becf21ffdbd027ba461cf8e805aa0bd29 1 parent 9338794
@thomas-mcdonald authored
View
8 lib/serel/answer.rb
@@ -12,5 +12,13 @@ def comments
def question
type(:question, :singular).url("questions/#{question_id}").request
end
+
+ def revisions
+ type(:revision).url("posts/#{id}/revisions")
+ end
+
+ def suggested_edits
+ type(:suggested_edit).url("posts/#{id}/suggested-edits")
+ end
end
end
View
111 spec/cassettes/answer-revisions.yml
@@ -0,0 +1,111 @@
+---
+http_interactions:
+- request:
+ method: get
+ uri: http://api.stackexchange.com/2.0/answers/14545?key=0p65aJUHxHo0G19*YF272A((&site=gaming
+ body: ''
+ headers:
+ Accept:
+ - ! '*/*'
+ User-Agent:
+ - Ruby
+ response:
+ status:
+ code: 200
+ message: OK
+ headers:
+ Cache-Control:
+ - private
+ Content-Type:
+ - application/json; charset=utf-8
+ Content-Encoding:
+ - gzip
+ Access-Control-Allow-Origin:
+ - ! '*'
+ Access-Control-Allow-Methods:
+ - GET, POST
+ Access-Control-Allow-Credentials:
+ - 'false'
+ Date:
+ - Mon, 20 Feb 2012 20:29:40 GMT
+ Content-Length:
+ - '483'
+ body: !binary |-
+ H4sIAAAAAAAEAOy9B2AcSZYlJi9tynt/SvVK1+B0oQiAYBMk2JBAEOzBiM3m
+ kuwdaUcjKasqgcplVmVdZhZAzO2dvPfee++999577733ujudTif33/8/XGZk
+ AWz2zkrayZ4hgKrIHz9+fB8/In7xR0WbL5qPHn3vF3/0i9Z50xbV8vcvZh89
+ 2t2/v787+ihbNld5bT+5P/poWucZt5plbU6f7j3cf7i/9/D+p6OPyqxpf/98
+ VrTmu3s7e/sHOzu79/S7bNoWl0V7Hfm+mVY1PkIP1WKxXqJZdbXMZ5GOioZA
+ TfNVmxNebb3ORx+haf3Ro1/80bpRfPcI6qxoVmV2/fsvswWB+GiSzVYfjT6q
+ 89W65UFQq50HB3sjeau9XqHVoprlddZWNTVd1dV5Uea/f7HILvDdvG1Xj+7e
+ vbq6Gl/U2WXWZvWY8L0rv97NP92f7O7tnu/P9g4O8t3z+9m9/dk9+nN6kE/O
+ Jw9/j9lnxSxftsW0Wv7C+rOXn1MXZbF86yBfZItieTFu2mz6Nn83nWfLi5x7
+ AIbN3b17d3UQQoDfv2biPPj0l/yS749oBqs2+/3rfJEVS4Ly0aOH9JiPF9k7
+ ouIOPaOP5lnz+y+Y4OdZ2eS/5P8JAAD//y7OfosHAgAA
+ http_version:
+ recorded_at: Mon, 20 Feb 2012 20:29:41 GMT
+- request:
+ method: get
+ uri: http://api.stackexchange.com/2.0/posts/14545/revisions?key=0p65aJUHxHo0G19*YF272A((&site=gaming
+ body: ''
+ headers:
+ Accept:
+ - ! '*/*'
+ User-Agent:
+ - Ruby
+ response:
+ status:
+ code: 200
+ message: OK
+ headers:
+ Cache-Control:
+ - private
+ Content-Type:
+ - application/json; charset=utf-8
+ Content-Encoding:
+ - gzip
+ Access-Control-Allow-Origin:
+ - ! '*'
+ Access-Control-Allow-Methods:
+ - GET, POST
+ Access-Control-Allow-Credentials:
+ - 'false'
+ Date:
+ - Mon, 20 Feb 2012 20:29:42 GMT
+ Content-Length:
+ - '1389'
+ body: !binary |-
+ H4sIAAAAAAAEAOy9B2AcSZYlJi9tynt/SvVK1+B0oQiAYBMk2JBAEOzBiM3m
+ kuwdaUcjKasqgcplVmVdZhZAzO2dvPfee++999577733ujudTif33/8/XGZk
+ AWz2zkrayZ4hgKrIHz9+fB8/In7xR0WbL5qPHn3vF39U55dFU1TL3/9iXcw+
+ evTR/fvPnjw4fnh/+/TZ/pPt/Sd7D7YPdp/tbO8en9x7eO/g4d6ne3sfjdxr
+ y/ViktcfPTrwPmuvVzmBaorlRZn//uuGvh99tKqa1nyTLZsr9yH63d2/v39/
+ 9NG0WizyZUtNTqpplaVPcmqaTrNlOsnT82q9nKXFMp2tlxd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Yf
+ 7pAHsf/p/Z3t42f3Trf3Dx48O9jbPTggTRFji3vfMFvItN/bZC5iHoX9bud9
+ VMju3s6H88v+zu5e35RUS/KPn1X1Ilt2LQl5bd8c3xxk09kkv59N8/z+Q/Ku
+ s/u792af3s8+ffjpwb1JdvDBfIPh3a0xnO1zGU5crZC5OHlwerz98OkBhSjH
+ FKI8Of6UOGn/3qfPSNUc7z7YjfHP3g+Pf4bY4N7Bg08/nA1ISHpc8GZeLbIm
+ /WL6lOhXzjqMcG/3wTcZk+xPZ/fvZ5Pd7NO98/PJ7u69bHJAbsb5p/vTh/d2
+ dj+YEWiAd1se0PZiOpMBxVXJycmDhydPPt1++uzpwfb+7sH97ScIS+4Rfz57
+ enJwcnB6HGOF3W+GFWJTTNHFNzDF/z93Fr4/+ugXras2+/3rfJEVS3rpo0cP
+ Hz48MB8vsndEz50dxN3zrPn9F1WdK7F+yf8TAAD//+8rTaa+EAAA
+ http_version:
+ recorded_at: Mon, 20 Feb 2012 20:29:43 GMT
+recorded_with: VCR 2.0.0.rc1
View
92 spec/cassettes/answer-suggested-edits.yml
@@ -0,0 +1,92 @@
+---
+http_interactions:
+- request:
+ method: get
+ uri: http://api.stackexchange.com/2.0/answers/14264?key=0p65aJUHxHo0G19*YF272A((&site=gaming
+ body: ''
+ headers:
+ Accept:
+ - ! '*/*'
+ User-Agent:
+ - Ruby
+ response:
+ status:
+ code: 200
+ message: OK
+ headers:
+ Cache-Control:
+ - private
+ Content-Type:
+ - application/json; charset=utf-8
+ Content-Encoding:
+ - gzip
+ Access-Control-Allow-Origin:
+ - ! '*'
+ Access-Control-Allow-Methods:
+ - GET, POST
+ Access-Control-Allow-Credentials:
+ - 'false'
+ Date:
+ - Mon, 20 Feb 2012 20:51:26 GMT
+ Content-Length:
+ - '486'
+ body: !binary |-
+ H4sIAAAAAAAEAOy9B2AcSZYlJi9tynt/SvVK1+B0oQiAYBMk2JBAEOzBiM3m
+ kuwdaUcjKasqgcplVmVdZhZAzO2dvPfee++999577733ujudTif33/8/XGZk
+ AWz2zkrayZ4hgKrIHz9+fB8/In7xR0WbL5qPHn3vF3/0i9Z50xbV8vcvZh89
+ 2t3f+/Te6KNs2Vzltf1kf/TRtM4zbjXL2pw+3Xu4/+nep7sHB6OPyqxpf/98
+ VrTmu3t7Dx/cu39/575+l03b4rJoryPfN9Oqpo+og6KhdtN81ebU6XlWNvno
+ o+pqmdcfPfrFH60bxWbv3r2Ho49mRbMqs+vff5kt6OWP3mY/+EG2yMoy+2j0
+ UZ2v1i2jSj0d3H8wkpfb6xWa1vlF0bR5TZ2MPlrV1XlR5r9/scgu8OW8bVeP
+ 7t69uroaX9TZZdZm9XhaLe7Kr3cnnz6cTmb5vfzT6d75/v7DB9m9e+d7n86y
+ h+eTBwfT7PeYfVbM8mVbTKvlL6w/e/k5dVEWy7cO8kW2KJYX46bNpm/zd9N5
+ trzIuQeg2NzF4O4GgxGK/P410+3h7i/5Jd8f0XxVbfb71/kiK5YEjT5/+PBT
+ 8/Eie0fD3qFn9NE8a37/BZOXyflL/p8AAAD//6syv3b1AQAA
+ http_version:
+ recorded_at: Mon, 20 Feb 2012 20:51:27 GMT
+- request:
+ method: get
+ uri: http://api.stackexchange.com/2.0/posts/14264/suggested-edits?key=0p65aJUHxHo0G19*YF272A((&site=gaming
+ body: ''
+ headers:
+ Accept:
+ - ! '*/*'
+ User-Agent:
+ - Ruby
+ response:
+ status:
+ code: 200
+ message: OK
+ headers:
+ Cache-Control:
+ - private
+ Content-Type:
+ - application/json; charset=utf-8
+ Content-Encoding:
+ - gzip
+ Access-Control-Allow-Origin:
+ - ! '*'
+ Access-Control-Allow-Methods:
+ - GET, POST
+ Access-Control-Allow-Credentials:
+ - 'false'
+ Date:
+ - Mon, 20 Feb 2012 20:51:27 GMT
+ Content-Length:
+ - '522'
+ body: !binary |-
+ H4sIAAAAAAAEAOy9B2AcSZYlJi9tynt/SvVK1+B0oQiAYBMk2JBAEOzBiM3m
+ kuwdaUcjKasqgcplVmVdZhZAzO2dvPfee++999577733ujudTif33/8/XGZk
+ AWz2zkrayZ4hgKrIHz9+fB8/In7xR0WbL5qPHn3vF3/UrC8u8qbNZ79/Piva
+ 37+YffTo3v2dg9FHq6qRP3f39z7d17/b61X+0aOPsmVzldcfjT6aVotFvmzp
+ o5NqlqfnVb3I2rZYXozSOp+tp/ksXa4Xk7xOq/N0ldXZRZ2t5k2KV+s8a4tq
+ +fvPspZg7t7be/jg3v29+9RVtlrV1WVWhl/d37lPWNQVIUId/P7rhjB49Is/
+ wk9B++G9T0cfzYpmVWbXv/8yWwDT36dIv1NkywvqsM5X65a7JJAP9x6M5FUd
+ Up1fFEQGwvoj7uW8KPPfv1hkF/hy3rarR3fvXl1djWkAl1mb1WMa+l359W7+
+ 6ezTh7u7n+7vTh4efDo9mBzsHHz6YHI+zXdns93pzu8x+6yYEZmKabX8hfVn
+ Lz+nLspi+dZBvsgWNKZx02bTt/m76ZwwzrkHoNjcxdDuXhfbP61DyabTfNX+
+ /jWT5/6DX/JLvj/66Betqzb7/et8kRVLgvXRo4cPH943Hy+ydzToHXpGH82z
+ 5vdfVDW9eZ6VTf5L/p8AAAD//zSzt+kOAgAA
+ http_version:
+ recorded_at: Mon, 20 Feb 2012 20:51:27 GMT
+recorded_with: VCR 2.0.0.rc1
View
72 spec/serel/answer_spec.rb
@@ -1,41 +1,61 @@
require 'spec_helper'
describe Serel::Answer do
- context 'the class' do
- it 'should support finding an answer and accessing its attributes' do
- VCR.use_cassette('answer-find') do
- # Pick a random awesome answer
- answer = Serel::Answer.find(16573)
- answer.should be_a(Serel::Answer)
+ it 'should support finding an answer and accessing its attributes' do
+ VCR.use_cassette('answer-find') do
+ # Pick a random awesome answer
+ answer = Serel::Answer.find(16573)
+ answer.should be_a(Serel::Answer)
- answer.id.should == 16573
- answer.answer_id.should == 16573
- answer.question_id.should == 16568
- answer.is_accepted.should == true
- answer.score.should == 23
+ answer.id.should == 16573
+ answer.answer_id.should == 16573
+ answer.question_id.should == 16568
+ answer.is_accepted.should == true
+ answer.score.should == 23
- answer.owner.should be_a(Serel::User)
+ answer.owner.should be_a(Serel::User)
+ end
+ end
+
+ it 'should get the question the answer is on' do
+ VCR.use_cassette('answer-question') do
+ answer = Serel::Answer.find(16573)
+ question = answer.question
+ question.should be_a(Serel::Question)
+ answer.question_id.should == question.id
+ end
+ end
+
+ it 'should get the comments on an answer' do
+ VCR.use_cassette('answer-comments') do
+ # Random awesome answer with comments
+ answer = Serel::Answer.find(29552)
+ comments = answer.comments.request
+ comments.should be_a(Array)
+ comments.each do |comment|
+ comment.should be_a(Serel::Comment)
end
end
end
- context 'an instance' do
- it 'should have a comments scope' do
- VCR.use_cassette('answer-comments') do
- # Random awesome answer with comments
- answer = Serel::Answer.find(29552)
- comments = answer.comments.request
- comments.should be_a(Array)
- comments.first.should be_a(Serel::Comment)
+ it 'should get the revisions on an answer' do
+ VCR.use_cassette('answer-revisions') do
+ answer = Serel::Answer.find(14545)
+ revisions = answer.revisions.request
+ revisions.should be_a(Array)
+ revisions.each do |rev|
+ rev.should be_a(Serel::Revision)
end
end
+ end
- it 'should be able to get the question' do
- VCR.use_cassette('answer-question') do
- answer = Serel::Answer.find(16573)
- question = answer.question
- question.should be_a(Serel::Question)
- answer.question_id.should == question.id
+ it 'should get the suggested edits on an answer' do
+ VCR.use_cassette('answer-suggested-edits') do
+ answer = Serel::Answer.find(14264)
+ edits = answer.suggested_edits.request
+ edits.should be_a(Array)
+ edits.each do |edit|
+ edit.should be_a(Serel::SuggestedEdit)
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.