diff --git a/Gemfile b/Gemfile index 1bdb2a4..1260cfc 100644 --- a/Gemfile +++ b/Gemfile @@ -5,4 +5,5 @@ gem 'spree_auth_devise', github: 'spree/spree_auth_devise', :branch => '2-0-stab gemspec -gem 'httparty' \ No newline at end of file +gem 'httparty' +gem 'json' diff --git a/app/models/burst_net/service.rb b/app/models/burst_net/service.rb index da6e77b..615b972 100644 --- a/app/models/burst_net/service.rb +++ b/app/models/burst_net/service.rb @@ -8,7 +8,7 @@ module BurstNet self.hostname = params['hostname'] self.order_id = params['order'] self.status = params['status'] - self.product_id = params['pid '] + self.product_id = params['pid '] # Not a typo - the field really comes like this self.dedicatedip = params['dedicatedip'] self.assignedips = params['assignedips'] self.username = params['username'] diff --git a/lib/burst_net/api.rb b/lib/burst_net/api.rb index 0f8ffaf..d331dba 100644 --- a/lib/burst_net/api.rb +++ b/lib/burst_net/api.rb @@ -32,6 +32,10 @@ require 'json' PUT service/:id =end module BurstNet + + class APIResponseError < StandardError + end + class API include HTTParty base_uri 'https://rsapi.burst.net' @@ -55,8 +59,11 @@ module BurstNet if response.success? response.parsed_response else - raise response.response + raise APIResponseError.new(response.response) end + rescue TypeError + Rails.logger.error(response.inspect) + raise APIResponseError.new('Error in response. Please check your logs.') end def post(path, options = {}) @@ -64,8 +71,11 @@ module BurstNet if response.success? response.parsed_response else - raise response.response + raise APIResponseError.new(response.response) end + rescue TypeError + Rails.logger.error(response.inspect) + raise APIResponseError.new('Error in response. Please check your logs.') end def put(path, options = {}) @@ -73,8 +83,11 @@ module BurstNet if response.success? response.parsed_response else - raise response.response + raise APIResponseError.new(response.response) end + rescue TypeError + Rails.logger.error(response.inspect) + raise APIResponseError.new('Error in response. Please check your logs.') end def delete(path, options = {}) @@ -82,8 +95,11 @@ module BurstNet if response.success? response.parsed_response else - raise response.response + raise APIResponseError.new(response.response) end + rescue TypeError + Rails.logger.error(response.inspect) + raise APIResponseError.new('Error in response. Please check your logs.') end def get_products @@ -134,7 +150,7 @@ module BurstNet def get_services_by_status(status) possible_status = %w(active cancelled fraud pending suspended terminated) - raise('Unknown service status') unless possible_status.include?(status) + raise ArgumentError.new('Unknown service status') unless possible_status.include?(status) self.get("/service/#{status}") end @@ -144,7 +160,7 @@ module BurstNet def get_orders_by_status(status) possible_status = %w(active cancelled fraud pending) - raise('Unknown order status') unless possible_status.include?(status) + raise ArgumentError.new('Unknown order status') unless possible_status.include?(status) self.get("/order/#{status}") end