lib/citygrid.rb in citygrid_api-0.0.6 vs lib/citygrid.rb in citygrid_api-0.0.7
- old
+ new
@@ -14,11 +14,29 @@
def publisher
raise PublisherNotConfigured if !defined?(@publisher) || @publisher.nil?
@publisher
end
+
+ # whether api calls will throw errors or fail silently
+ # by default, we will raise errors
+ def raise_errors= v
+ @raise_errors = v
+ end
+
+ def raise_errors?
+ !defined?(@raise_errors) || @raise_errors
+ end
+ def use_vcr= v
+ @use_vcr = v
+ end
+
+ def use_vcr?
+ defined?(VCR) && defined?(@use_vcr) && @use_vcr
+ end
+
def search opts = {}
Search.new opts
end
def find listing_id
@@ -68,15 +86,17 @@
elsif v.is_a? Hash
# if value is a Hash, fetch endpoint
# if hostname is set, use it
# otherwise if ssl is set then use ssl_hostname. fallback to default_hostname
hostname = v["hostname"] || (v["ssl"] ? ssl_hostname : default_hostname)
+ throw ParseConfigurationError.new file_path, "No endpoint defined for #{k}" unless v["endpoint"]
endpoint = v["endpoint"].start_with?("/") ? v["endpoint"] : "/#{v["endpoint"]}"
klass.endpoint endpoint
klass.base_uri hostname
else
# should not get here. value should be String or Hash
+ throw ParseConfigurationError.new file_path, "Invalid value type for #{k}"
end
# puts "#{klass.name} => #{klass.base_uri} : #{klass.endpoint}"
end
end
@@ -94,16 +114,23 @@
class EndpointsNotConfigured < StandardError
def initialize
super "Endpoint is not properly configured. Run 'CityGrid.load_config'"
end
end
+
+ class ParseConfigurationError < StandardError
+ def initialize path, msg = nil
+ super msg ? "#{msg} at '#{path}'" : "Error parsing configuration file at '#{path}'"
+ end
+ end
+
end
require "citygrid/abstraction"
require "citygrid/api"
require "yaml"
-require "citygrid/api/mutatable"
+require "citygrid/api/mutable"
require "citygrid/api/searchable"
require "citygrid/search"
require "citygrid/reviews"
require "citygrid/offers"
\ No newline at end of file