lib/govdelivery/tms/client.rb in govdelivery-tms-0.8.2 vs lib/govdelivery/tms/client.rb in govdelivery-tms-0.8.3
- old
+ new
@@ -4,11 +4,11 @@
include GovDelivery::TMS::Util::HalLinkParser
include GovDelivery::TMS::CoreExt
attr_accessor :connection, :href, :api_root, :logger
- DEFAULTS = {api_root: 'https://tms.govdelivery.com', logger: nil}.freeze
+ DEFAULTS = { api_root: 'https://tms.govdelivery.com', logger: nil }.freeze
# Create a new client and issue a request for the available resources for a given account.
#
# @param [String] auth_token The auth_token of your account
# @param [Hash] options
@@ -27,30 +27,30 @@
@logger = options.fetch(:logger, setup_logging(options[:debug]))
connect!(auth_token, options.except(:api_root, :logger, :debug))
discover!
end
- def connect!(auth_token, options={})
- self.connection = GovDelivery::TMS::Connection.new({auth_token: auth_token, api_root: api_root, logger: logger}.merge!(options))
+ def connect!(auth_token, options = {})
+ self.connection = GovDelivery::TMS::Connection.new({ auth_token: auth_token, api_root: api_root, logger: logger }.merge!(options))
end
def discover!
services = get('/').body
parse_links(services['_links'])
end
def get(href)
response = raw_connection.get(href)
case response.status
- when 500..599
- raise GovDelivery::TMS::Request::Error.new(response.status)
- when 401..499
- raise GovDelivery::TMS::Request::Error.new(response.status)
- when 202
- raise GovDelivery::TMS::Request::InProgress.new(response.body['message'])
- else
- return response
+ when 500..599
+ fail GovDelivery::TMS::Request::Error.new(response.status)
+ when 401..499
+ fail GovDelivery::TMS::Request::Error.new(response.status)
+ when 202
+ fail GovDelivery::TMS::Request::InProgress.new(response.body['message'])
+ else
+ return response
end
end
def post(obj)
raw_connection.post do |req|
@@ -69,14 +69,14 @@
end
def delete(href)
response = raw_connection.delete(href)
case response.status
- when 200...299
- return response
- else
- raise GovDelivery::TMS::Request::Error.new(response.status)
+ when 200...299
+ return response
+ else
+ fail GovDelivery::TMS::Request::Error.new(response.status)
end
end
def raw_connection
connection.connection
@@ -91,7 +91,6 @@
def setup_logging(debug)
logger = Logger.new(STDOUT)
logger.level = debug ? Logger::DEBUG : Logger::INFO
logger
end
-
end