Permalink
Browse files

Added response class to be returned after a request instead of reques…

…t object.
  • Loading branch information...
1 parent 2b24b50 commit cfd723c5bdb693a8bd1d685ac18ba8d459fab48d Chavez committed Dec 28, 2011
View
BIN al_papi-0.0.2.gem
Binary file not shown.
View
BIN al_papi-0.0.1.gem → al_papi-0.0.3.gem
Binary file not shown.
View
2 al_papi.gemspec
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = 'al_papi'
- s.version = '0.0.2'
+ s.version = '0.0.3'
s.date = '2011-12-26'
s.summary = "AuthorityLabs Partner API Wrapper"
s.description = "Wraps AuthorityLabs Partner API calls in a gem."
View
1 lib/al_papi.rb
@@ -10,5 +10,6 @@ module AlPapi
require File.dirname(__FILE__) + '/al_papi/http'
require File.dirname(__FILE__) + '/al_papi/request'
require File.dirname(__FILE__) + '/al_papi/request_error'
+require File.dirname(__FILE__) + '/al_papi/response'
require File.dirname(__FILE__) + '/al_papi/locales'
require File.dirname(__FILE__) + '/al_papi/engines'
View
3 lib/al_papi/config.rb
@@ -5,7 +5,8 @@ class Config
DEFAULT_HOST = 'http://api.authoritylabs.com'
DEFAULT_PORT = 80
- attr_reader :api_key, :host, :port
+ attr_accessor :api_key
+ attr_reader :host, :port
##
#
View
22 lib/al_papi/http.rb
@@ -2,8 +2,10 @@ module AlPapi
class Http # :nodoc:all:
- def initialize(req)
- @api_req, @config = req, req.config
+ attr_accessor :errors, :response, :success, :config
+
+ def initialize(_config)
+ @config, @errors, @success = _config, [], false
end
def get(path, params = {})
@@ -28,22 +30,22 @@ def request(http_verb, path, params = nil)
body = raw_res.body
code = raw_res.code.to_i
- @api_req.response = body
- @api_req.errors = []
+ self.response = body
+ self.errors = []
case code
when 200
- @api_req.response = JSON.parse body
- @api_req.success = true
+ self.response = JSON.parse body
+ self.success = true
when 204
- @api_req.errors << RequestError.new('No Content', code, path, params)
+ self.errors << RequestError.new('No Content', code, path, params)
when 401
- @api_req.errors << RequestError.new('Invalid Auth Token Provided', code, path, params)
+ self.errors << RequestError.new('Invalid Auth Token Provided', code, path, params)
else
- @api_req.errors << RequestError.new(body, code, path, params)
+ self.errors << RequestError.new(body, code, path, params)
end
- @api_req
+ Response.new(self, code, path, params)
end
end
View
4 lib/al_papi/locales.rb
@@ -190,7 +190,7 @@ class Locales
'es-mx',
'es-pe',
'es-us',
- 'es-ve'
+ 'es-ve',
'fr-ca',
'fr-ch',
'fr-fr',
@@ -206,7 +206,7 @@ class Locales
'ru-ru',
'sv-se',
'tl-ph',
- 'vi-vn'
+ 'vi-vn',
'zh-cn',
'zh-cn-tw',
'zh-hk'
View
13 lib/al_papi/request.rb
@@ -2,7 +2,6 @@ module AlPapi
class Request
- attr_accessor :response, :success, :errors
attr_reader :config
##
@@ -16,7 +15,7 @@ def initialize(config)
end
def http # :nodoc:
- Http.new(self)
+ Http.new(@config)
end
##
@@ -37,7 +36,7 @@ def http # :nodoc:
# is sent a POST when results are returned.
def post(params = {}, priority = false)
- path = priority ? '/keywords/priority' : '/keyword'
+ path = priority ? '/keywords/priority' : '/keywords'
http.post path, params
end
@@ -71,14 +70,6 @@ def get(params = {})
http.get '/keywords/get', params
end
- ##
- #
- # Convenience method to determine if request was successfull or not
-
- def success?
- return @success
- end
-
end
end
View
22 lib/al_papi/response.rb
@@ -0,0 +1,22 @@
+module AlPapi
+
+ class Response
+
+ attr_reader :success, :body, :errors, :code, :path, :params
+
+ def initialize(http, _code, _path, _params) # :nodoc:
+ @success, @body, @errors = http.success, http.response, http.errors
+ @code, @path, @params = _code, _path, _params
+ end
+
+ ##
+ #
+ # Convenience method to determine if request was successfull or not
+
+ def success?
+ return @success
+ end
+
+ end
+
+end

0 comments on commit cfd723c

Please sign in to comment.