lib/osm/api.rb in osm-1.2.17 vs lib/osm/api.rb in osm-1.2.18.dev
- old
+ new
@@ -28,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, :osm_staging].include?(options[:default_site])
+ raise ArgumentError, ':default_site does not exist in options hash or is invalid, this should be set to either :osm or :ogm' unless Osm::Api::BASE_URLS.keys.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|
+ Osm::Api::BASE_URLS.keys.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?
@@ -71,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, :osm_staging].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::Api::BASE_URLS.keys.include?(site)
@site = site
set_user(user_id, secret)
nil
end
@@ -143,19 +143,18 @@
# Get the base URL for requests to OSM/OGM
# @param [Symbol] site For OSM or OGM (:osm or :ogm)
# @return [String] The base URL for requests
def self.base_url(site=@@site)
- raise ArgumentError, "Invalid site" unless [:osm, :ogm].include?(site)
+ raise ArgumentError, "Invalid site" unless Osm::Api::BASE_URLS.keys.include?(site)
BASE_URLS[site]
end
# Get the base URL for requests to OSM.OGM
# @param site For OSM or OGM (:osm or :ogm), defaults to the default for this api object
# @return [String] The base URL for requests
def base_url(site=@site)
- raise ArgumentError, "Invalid site" unless [:osm, :ogm].include?(site)
self.class.base_url(site)
end
# Make a query to the OSM/OGM API
# @param [String] url The script on the remote server to invoke
@@ -209,10 +208,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, :osm_staging].include?(site)
+ raise ArgumentError, 'site is invalid, this should be set to either :osm or :ogm' unless Osm::Api::BASE_URLS.keys.include?(site)
data = api_data.merge({
'apiid' => @@api_details[site][:id],
'token' => @@api_details[site][:token],
})