Skip to content

Commit

Permalink
Added redirect? and redirect_url to Smash object.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrichardlai committed Nov 10, 2011
1 parent a0a20ea commit 69cda79
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 73 deletions.
3 changes: 1 addition & 2 deletions README.md
Expand Up @@ -105,5 +105,4 @@ More informations: http://taskrabbit.github.com

Add:

- Picture and sound upload
- Offer
- Picture and sound upload
11 changes: 10 additions & 1 deletion lib/taskrabbit/smash.rb
Expand Up @@ -6,6 +6,7 @@ class Smash < APISmith::Smash
attr_accessor :loaded

property :errors
property :links
property :error

class << self
Expand Down Expand Up @@ -34,6 +35,14 @@ def valid?
errors.nil? and error.nil?
end

def redirect_url
links["redirect"] if links
end

def redirect?
!!redirect_url
end

# remove the errors from the object
def clear_errors
%w{error errors}.map { |k| self.delete(k) }
Expand All @@ -45,7 +54,7 @@ def reload(method, path, options = {})
response = request(method, path, self.class, options)
self.merge!(response)
clear_errors
true
!redirect?
rescue Smash::Error => e
self.merge!(e.response) if e.response.is_a?(Hash)
false
Expand Down
6 changes: 3 additions & 3 deletions spec/support/cassettes/tasks/create/without_credit_card.yml
Expand Up @@ -17,14 +17,14 @@
content-type:
- application/json; charset=utf-8
x-runtime:
- "3161"
- "3120"
server:
- WEBrick/1.3.1 (Ruby/1.8.7/2010-04-19)
date:
- Wed, 02 Nov 2011 02:36:03 GMT
- Thu, 10 Nov 2011 22:04:10 GMT
content-length:
- "693"
cache-control:
- no-cache
body: "{\"name\":\"My First Task\",\"city\":{\"name\":\"New York City\",\"lng\":-74.005973,\"id\":4,\"links\":{\"get\":\"/api/v1/cities/4\"},\"lat\":40.714353},\"named_price\":20,\"complete_by_time\":1320260400,\"id\":22563,\"state_changed_at\":1320201360,\"cost_in_cents\":0,\"links\":{\"html\":\"http://local.taskrabbit.com/tasks/my-first-task--16\",\"get\":\"/api/v1/tasks/22563\",\"delete\":\"/api/v1/tasks/22563\",\"put\":\"/api/v1/tasks/22563\",\"authenticated\":\"http://local.taskrabbit.com/go/da7fd050dcfee12472ed2741b0289689c65be13115a10f35c6143555c25d4cb392ef46353bda9f412ce0cf7ba34a4ca0738a\",\"redirect\":\"https://local.taskrabbit.com/tasks/my-first-task--16?card=true\"},\"state_label\":\"not posted\",\"assign_by_time\":1320246000,\"state\":\"unpaid\"}"
body: "{\"name\":\"My First Task\",\"city\":{\"name\":\"New York City\",\"lng\":-74.005973,\"id\":4,\"links\":{\"get\":\"/api/v1/cities/4\"},\"lat\":40.714353},\"named_price\":20,\"complete_by_time\":1321041600,\"id\":22590,\"state_changed_at\":1320962647,\"cost_in_cents\":0,\"links\":{\"html\":\"http://local.taskrabbit.com/tasks/my-first-task--43\",\"get\":\"/api/v1/tasks/22590\",\"delete\":\"/api/v1/tasks/22590\",\"put\":\"/api/v1/tasks/22590\",\"authenticated\":\"http://local.taskrabbit.com/go/8ebf16114f06cae4ded7c5206cd0a26e8aa8a0ea8d447d11215dffd9a4a50141ad8485e5eacf2bf9188d4bdd973a0f871c80\",\"redirect\":\"https://local.taskrabbit.com/tasks/my-first-task--43?card=true\"},\"state_label\":\"not posted\",\"assign_by_time\":1321027200,\"state\":\"unpaid\"}"
http_version: "1.1"
18 changes: 9 additions & 9 deletions spec/support/cassettes/tasks/delete.yml
Expand Up @@ -15,25 +15,25 @@
message: OK
headers:
etag:
- "\"7cf5618fa6432352d40ded9f5a7fce86\""
- "\"78480e93b88ebb012b502c830925ec3a\""
content-type:
- application/json; charset=utf-8
x-runtime:
- "2722"
- "3152"
server:
- WEBrick/1.3.1 (Ruby/1.8.7/2010-04-19)
date:
- Thu, 03 Nov 2011 17:45:51 GMT
- Thu, 10 Nov 2011 22:05:30 GMT
content-length:
- "613"
cache-control:
- private, max-age=0, must-revalidate
body: "{\"name\":\"My First Task\",\"city\":{\"name\":\"New York City\",\"lng\":-74.005973,\"id\":4,\"links\":{\"get\":\"/api/v1/cities/4\"},\"lat\":40.714353},\"named_price\":20,\"complete_by_time\":1320418800,\"id\":22569,\"state_changed_at\":1320342350,\"cost_in_cents\":0,\"links\":{\"html\":\"http://local.taskrabbit.com/tasks/my-first-task--22\",\"get\":\"/api/v1/tasks/22569\",\"delete\":\"/api/v1/tasks/22569\",\"put\":\"/api/v1/tasks/22569\",\"authenticated\":\"http://local.taskrabbit.com/go/b32969e8569f2f2b25c238236a3e2029f927f1f49a85f884ed15f7ac5b859ab23af60e40ef2680d8b1162d12d540c2451b9a\"},\"state_label\":\"posted\",\"assign_by_time\":1320361200,\"state\":\"opened\"}"
body: "{\"name\":\"My First Task\",\"city\":{\"name\":\"New York City\",\"lng\":-74.005973,\"id\":4,\"links\":{\"get\":\"/api/v1/cities/4\"},\"lat\":40.714353},\"named_price\":20,\"complete_by_time\":1321041600,\"id\":22591,\"state_changed_at\":1320962729,\"cost_in_cents\":0,\"links\":{\"html\":\"http://local.taskrabbit.com/tasks/my-first-task--44\",\"get\":\"/api/v1/tasks/22591\",\"delete\":\"/api/v1/tasks/22591\",\"put\":\"/api/v1/tasks/22591\",\"authenticated\":\"http://local.taskrabbit.com/go/96a72ee9e225d0b9548790e397c248c6d6a326e9c19bf6c3ccc8b0bfa62853f1cfe9d0930d34fd8da46b5da1679c1a5d5cd3\"},\"state_label\":\"posted\",\"assign_by_time\":1321027200,\"state\":\"opened\"}"
http_version: "1.1"
- !ruby/struct:VCR::HTTPInteraction
request: !ruby/struct:VCR::Request
method: :delete
uri: http://localhost:3000/api/v1/tasks/22569?
uri: http://localhost:3000/api/v1/tasks/22591?
body:
headers:
x-client-application:
Expand All @@ -46,18 +46,18 @@
message: OK
headers:
etag:
- "\"1cd8a693f792f3e295776166c6d07be8\""
- "\"c684ccb7b19feb1ea8d9189a1c00413e\""
content-type:
- application/json; charset=utf-8
x-runtime:
- "1595"
- "2244"
server:
- WEBrick/1.3.1 (Ruby/1.8.7/2010-04-19)
date:
- Thu, 03 Nov 2011 17:45:53 GMT
- Thu, 10 Nov 2011 22:05:32 GMT
content-length:
- "558"
cache-control:
- private, max-age=0, must-revalidate
body: "{\"name\":\"My First Task\",\"city\":{\"name\":\"New York City\",\"lng\":-74.005973,\"id\":4,\"links\":{\"get\":\"/api/v1/cities/4\"},\"lat\":40.714353},\"named_price\":20,\"complete_by_time\":1320418800,\"id\":22569,\"state_changed_at\":1320342352,\"cost_in_cents\":0,\"links\":{\"html\":\"http://local.taskrabbit.com/tasks/my-first-task--22\",\"get\":\"/api/v1/tasks/22569\",\"authenticated\":\"http://local.taskrabbit.com/go/b32969e8569f2f2b25c238236a3e2029f927f1f49a85f884ed15f7ac5b859ab23af60e40ef2680d8b1162d12d540c2451b9a\"},\"state_label\":\"canceled\",\"assign_by_time\":1320361200,\"state\":\"canceled\"}"
body: "{\"name\":\"My First Task\",\"city\":{\"name\":\"New York City\",\"lng\":-74.005973,\"id\":4,\"links\":{\"get\":\"/api/v1/cities/4\"},\"lat\":40.714353},\"named_price\":20,\"complete_by_time\":1321041600,\"id\":22591,\"state_changed_at\":1320962731,\"cost_in_cents\":0,\"links\":{\"html\":\"http://local.taskrabbit.com/tasks/my-first-task--44\",\"get\":\"/api/v1/tasks/22591\",\"authenticated\":\"http://local.taskrabbit.com/go/96a72ee9e225d0b9548790e397c248c6d6a326e9c19bf6c3ccc8b0bfa62853f1cfe9d0930d34fd8da46b5da1679c1a5d5cd3\"},\"state_label\":\"canceled\",\"assign_by_time\":1321027200,\"state\":\"canceled\"}"
http_version: "1.1"

0 comments on commit 69cda79

Please sign in to comment.