diff --git a/lib/postnord.rb b/lib/postnord.rb index 85eea2f..cee5e73 100644 --- a/lib/postnord.rb +++ b/lib/postnord.rb @@ -4,6 +4,7 @@ require 'json' require 'openssl' +require 'postnord/config' require 'postnord/client' require 'postnord/response' require 'postnord/base' diff --git a/lib/postnord/client.rb b/lib/postnord/client.rb index 25eb305..719ff84 100644 --- a/lib/postnord/client.rb +++ b/lib/postnord/client.rb @@ -1,24 +1,20 @@ module Postnord class Client - POSTNORD_API_KEY = '' - POSTNORD_API_VERSION = 'v1' - POSTNORD_API_ENDPOINT = 'https://api2.postnord.com/rest' - POSTNORD_LOCALE = 'en' - POSTNORD_RETURN_TYPE = 'json' def initialize(options={}) - @api_version = options[:api_version] || POSTNORD_API_VERSION - @api_key = options[:api_key] || POSTNORD_API_KEY - @locale = options[:locale] || POSTNORD_LOCALE || 'en' - @returntype = options[:returntype] || POSTNORD_RETURN_TYPE || 'json' + @api_version = options[:api_version] || Config.api_version + @api_key = options[:api_key] || Config.api_key + @api_endpoint = options[:api_endpoint] || Config.api_endpoint + @locale = options[:locale] || Config.locale + @return_type = options[:return_type] || Config.return_type end def do_request(service, endpoint, params={}) uri = build_uri(service, endpoint) params.merge!( - apikey: POSTNORD_API_KEY, - locale: POSTNORD_LOCALE, + apikey: @api_key, + locale: @locale, ) uri.query = URI.encode_www_form(params) @@ -35,11 +31,11 @@ def do_request(service, endpoint, params={}) def build_uri(service, endpoint) URI( - POSTNORD_API_ENDPOINT + + @api_endpoint + '/' + service + - '/' + POSTNORD_API_VERSION + + '/' + @api_version + '/' + endpoint + - '.' + POSTNORD_RETURN_TYPE + '.' + @return_type ) end end