Skip to content

Commit

Permalink
Use config file in client
Browse files Browse the repository at this point in the history
  • Loading branch information
loveapoex committed Aug 24, 2016
1 parent 630b343 commit 8030d93
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
1 change: 1 addition & 0 deletions lib/postnord.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require 'json'
require 'openssl'

require 'postnord/config'
require 'postnord/client'
require 'postnord/response'
require 'postnord/base'
Expand Down
24 changes: 10 additions & 14 deletions lib/postnord/client.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 8030d93

Please sign in to comment.