-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Taskrabbit::Client class and refactored code.
- Loading branch information
1 parent
1b5ddd0
commit f89a5d6
Showing
11 changed files
with
72 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
module Taskrabbit | ||
class Account < User | ||
def fetch | ||
api.request('get', "account", self.class) | ||
reload('get', "account") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module Taskrabbit | ||
module Client | ||
def self.included(base) | ||
base.class_eval do | ||
include APISmith::Client | ||
include InstanceMethods | ||
end | ||
end | ||
|
||
module InstanceMethods | ||
def transform_response(response, options) | ||
transformer = options[:transform] || options[:transformer] | ||
if transformer | ||
obj = transformer.call response | ||
obj.api = self if obj.respond_to?(:api=) | ||
obj | ||
else | ||
response | ||
end | ||
end | ||
|
||
def check_response_errors(response) | ||
if response and response.respond_to?(:response) | ||
case response.response | ||
when Net::HTTPClientError, Net::HTTPServerError | ||
error = "#{response.response.code} #{response.response.message}" | ||
if response.is_a?(Hash) | ||
error = response['error'] | ||
# if errors key is present then it's a validation error | ||
raise Smash::Error.new(error, response) if response['errors'] | ||
end | ||
raise Taskrabbit::Error.new(error, response) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters