lib/osm/api.rb in osm-1.2.14 vs lib/osm/api.rb in osm-1.2.15.dev

- old
+ new

@@ -10,10 +10,11 @@ BASE_URLS = { :osm => 'https://www.onlinescoutmanager.co.uk', :ogm => 'http://www.onlineguidemanager.co.uk', + :osm_staging => 'http://staging.onlinescoutmanager.co.uk' } # Configure the API options used by all instances of the class # @param [Hash] options @@ -27,13 +28,13 @@ # @option options[:ogm] [String] :token the token which goes with the above api # @option options[:ogm] [String] :name the name displayed in the External Access tab of OGM # @option options [Boolean] :debug if true debugging info is output (optional, default = false) # @return nil def self.configure(options) - raise ArgumentError, ':default_site does not exist in options hash or is invalid, this should be set to either :osm or :ogm' unless [:osm, :ogm].include?(options[:default_site]) - raise ArgumentError, ':osm and/or :ogm must be present' if options[:osm].nil? && options[:ogm].nil? - [:osm, :ogm].each do |api_key| + raise ArgumentError, ':default_site does not exist in options hash or is invalid, this should be set to either :osm or :ogm' unless [:osm, :ogm, :osm_staging].include?(options[:default_site]) + raise ArgumentError, ":#{options[:default_site]} does not exist in options hash" if options[options[:default_site]].nil? + [:osm, :ogm, :osm_staging].each do |api_key| if options[api_key] api_data = options[api_key] raise ArgumentError, ":#{api_key} must be a Hash" unless api_data.is_a?(Hash) [:id, :token, :name].each do |key| raise ArgumentError, ":#{api_key} must contain a key :#{key}" if api_data[key].nil? @@ -44,10 +45,11 @@ @@site = options[:default_site] @@debug = !!options[:debug] @@api_details = { :osm => (options[:osm] || {}), :ogm => (options[:ogm] || {}), + :osm_staging => (options[:osm_staging] || {}) } nil end # Configure the debug option @@ -69,11 +71,11 @@ # @param [Symbol] site Whether to use OSM (:osm) or OGM (:ogm), defaults to the value set for the class # @return nil def initialize(user_id, secret, site=@@site) raise ArgumentError, 'You must pass a secret (get this by using the authorize method)' if secret.nil? raise ArgumentError, 'You must pass a user_id (get this by using the authorize method)' if user_id.nil? - raise ArgumentError, 'site is invalid, if passed it should be either :osm or :ogm, if not passed then you forgot to run Api.configure' unless [:osm, :ogm].include?(site) + raise ArgumentError, 'site is invalid, if passed it should be either :osm or :ogm, if not passed then you forgot to run Api.configure' unless [:osm, :ogm, :osm_staging].include?(site) @site = site set_user(user_id, secret) nil end @@ -207,10 +209,10 @@ # @param [Hash] api_data A hash containing the values to be sent to the server in the body of the request # @return [Hash, Array, String] the parsed JSON returned by OSM # @raise [Osm::Error] If an error was returned by OSM # @raise [Osm::ConnectionError] If an error occured connecting to OSM def self.perform_query(site, url, api_data={}) - raise ArgumentError, 'site is invalid, this should be set to either :osm or :ogm' unless [:osm, :ogm].include?(site) + raise ArgumentError, 'site is invalid, this should be set to either :osm or :ogm' unless [:osm, :ogm, :osm_staging].include?(site) data = api_data.merge({ 'apiid' => @@api_details[site][:id], 'token' => @@api_details[site][:token], })