lib/hoptoad-api/client.rb in hoptoad-api-2.1.0 vs lib/hoptoad-api/client.rb in hoptoad-api-2.2.0

- old
+ new

@@ -23,11 +23,11 @@ # # with pagination: # Hoptoad::Error.find(:all, :params => { :page => 2 }) # # find individual error by ID -# Hoptoad::Error.find(44) +# Hoptoad::Error.find(44) # # Find *all* notices by error_id # # notices = Hoptoad::Notice.all(1234) # 1234 == error id # @@ -37,67 +37,67 @@ module Hoptoad class Base include HTTParty format :xml - + private - + def self.setup - base_uri Hoptoad.account + base_uri Hoptoad.account_path default_params :auth_token => Hoptoad.auth_token - + check_configuration end - + def self.check_configuration raise HoptoadError.new('API Token cannot be nil') if default_options.nil? || default_options[:default_params].nil? || !default_options[:default_params].has_key?(:auth_token) raise HoptoadError.new('Account cannot be nil') unless default_options.has_key?(:base_uri) end - + def self.fetch(path, options) response = get(path, { :query => options }) if response.code == 403 raise HoptoadError.new('SSL should be enabled - use Hoptoad.secure = true in configuration') end - + Hashie::Mash.new(response) end end class Error < Base def self.find(*args) setup - + results = case args.first when Fixnum find_individual(args) when :all find_all(args) else raise HoptoadError.new('Invalid argument') end - + raise HoptoadError.new('No results found.') if results.nil? raise HoptoadError.new(results.errors.error) if results.errors - + results.group || results.groups end def self.update(error, options) setup - + self.class.put(collection_path, options) end private def self.find_all(args) options = args.extract_options! - + fetch(collection_path, options) end def self.find_individual(args) id = args.shift @@ -118,34 +118,34 @@ class Notice < Base def self.find(id, error_id, options={}) setup - + hash = fetch(find_path(id, error_id), options) - + if hash.errors raise HoptoadError.new(results.errors.error) end - + hash.notice end - + def self.find_all_by_error_id(error_id) setup - + options = {} notices = [] page = 1 while true options[:page] = page hash = fetch(all_path(error_id), options) if hash.errors raise HoptoadError.new(results.errors.error) end notice_stubs = hash.notices - + notice_stubs.map do |notice| notices << find(notice.id, error_id) end break if notice_stubs.size < 30 page += 1 @@ -153,15 +153,15 @@ notices end def self.find_by_error_id(error_id, options={ 'page' => 1}) setup - + hash = fetch(all_path(error_id), options) if hash.errors raise HoptoadError.new(results.errors.error) end - + hash.notices end private \ No newline at end of file