Skip to content
This repository was archived by the owner on Jul 30, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/validic.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
require 'validic/client'

module Validic
BASE_URL = "https://api.validic.com/v1"
API_URL = 'https://api.validic.com'
API_VERSION = 'v1'
BASE_URL = "#{API_URL}/#{API_VERSION}"

class << self
attr_accessor :api_url,
:api_version,
Expand All @@ -18,3 +21,7 @@ def configure
end
end
end

Validic.api_url = Validic::API_URL
Validic.api_version = Validic::API_VERSION

15 changes: 4 additions & 11 deletions lib/validic/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ class Client
#
# @params options[Hash]
def initialize(options={})
@api_url = options.fetch(:api_url, 'https://api.validic.com')
@api_version = options.fetch(:api_version, 'v1')
@access_token = options.fetch(:access_token, Validic.access_token)
@organization_id = options.fetch(:organization_id, Validic.organization_id)
@api_url = options[:api_url] || Validic.api_url
@api_version = options[:api_version] || Validic.api_version
@access_token = options[:access_token] || Validic.access_token
@organization_id = options[:organization_id] || Validic.organization_id
end

##
Expand All @@ -72,12 +72,5 @@ def default_headers
user_agent: "Ruby Gem by Validic #{Validic::VERSION}"
}
end

def reload_config
Validic.api_url = api_url
Validic.api_version = api_version
Validic.access_token = access_token
Validic.organization_id = organization_id
end
end
end
27 changes: 14 additions & 13 deletions lib/validic/rest/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ module Validic
module REST
module Request
def latest(type, options = {})
organization_id = options[:organization_id] || Validic.organization_id
local_organization_id = options[:organization_id] || organization_id
user_id = options.delete(:user_id)
if user_id
path = "/#{Validic.api_version}/organizations/#{organization_id}/users/#{user_id}/#{type.to_s}/latest.json"
path = "/#{api_version}/organizations/#{local_organization_id}/users/#{user_id}/#{type.to_s}/latest.json"
else
path = "/#{Validic.api_version}/organizations/#{organization_id}/#{type.to_s}/latest.json"
path = "/#{api_version}/organizations/#{local_organization_id}/#{type.to_s}/latest.json"
end
get(path, options)
end
Expand Down Expand Up @@ -38,25 +38,26 @@ def delete_request(type, options = {})
end

def construct_path(type, options)
organization_id = options.delete(:organization_id) || Validic.organization_id
local_organization_id = options.delete(:organization_id) ||
organization_id
user_id = options.delete(:user_id)
activity_id = options.delete(:_id)

if activity_id
path = "/#{Validic.api_version}/organizations/#{organization_id}/users/#{user_id}/#{type.to_s}/#{activity_id}.json"
"/#{api_version}/organizations/#{local_organization_id}/users/#{user_id}/#{type.to_s}/#{activity_id}.json"
elsif user_id && type == :users
path = "/#{Validic.api_version}/organizations/#{organization_id}/users/#{user_id}.json"
"/#{api_version}/organizations/#{local_organization_id}/users/#{user_id}.json"
elsif user_id
path = "/#{Validic.api_version}/organizations/#{organization_id}/users/#{user_id}/#{type.to_s}.json"
"/#{api_version}/organizations/#{local_organization_id}/users/#{user_id}/#{type.to_s}.json"
elsif type == :me
path = "/#{Validic.api_version}/me.json"
"/#{api_version}/me.json"
elsif type == :profile
path = "/#{Validic.api_version}/profile.json"
"/#{api_version}/profile.json"
elsif type == :organizations
path = "/#{Validic.api_version}/organizations/#{organization_id}.json"
"/#{api_version}/organizations/#{local_organization_id}.json"
else
path = "/#{Validic.api_version}/organizations/#{organization_id}/#{type.to_s}.json"
"/#{api_version}/organizations/#{local_organization_id}/#{type.to_s}.json"
end
path
end

def get(path, options)
Expand All @@ -76,7 +77,7 @@ def delete(path, options)
end

def request(method, path, options)
options[:access_token] = options[:access_token].nil? ? Validic.access_token : options[:access_token]
options[:access_token] ||= access_token
response = connection.send(method) do |request|
case method
when :get
Expand Down