class Ocs::Client
Attributes
api_key[R]
host[R]
logger[R]
path[R]
secret_key[R]
ssl[R]
Public Class Methods
new(host:, api_key:, secret_key:, path: "/client/api", logger: nil, ssl: true)
click to toggle source
# File lib/ocs/client.rb, line 5 def initialize(host:, api_key:, secret_key:, path: "/client/api", logger: nil, ssl: true) @host = host @api_key = api_key @secret_key = secret_key @path = path @logger = logger @ssl = ssl end
Public Instance Methods
call(name, options = {})
click to toggle source
# File lib/ocs/client.rb, line 14 def call(name, options = {}) send(name, options).content end
connection()
click to toggle source
# File lib/ocs/client.rb, line 18 def connection @connection ||= Faraday.new(url: url_prefix) do |connection| connection.response :json connection.adapter Faraday.default_adapter end end
new(resource_name, options = {})
click to toggle source
# File lib/ocs/client.rb, line 26 def new(resource_name, options = {}) resource_class(resource_name).new(self, options) end
send(name, options = {})
click to toggle source
# File lib/ocs/client.rb, line 30 def send(name, options = {}) Request.new( name: name, options: options, client: self ).send end
Private Instance Methods
method_missing(method, *args)
click to toggle source
Calls superclass method
# File lib/ocs/client.rb, line 52 def method_missing(method, *args) return super unless args.first.to_s =~ /^[a-zA-Z]/ raw_resource_name, *arguments = args resource_name = raw_resource_name.to_s.singularize if Ocs::Resources.const_defined?(resource_name.camelize) return resource_class(resource_name).public_send(method, self, *arguments) end super end
resource_class(resource_name)
click to toggle source
# File lib/ocs/client.rb, line 40 def resource_class(resource_name) "ocs/resources/#{resource_name}".camelize.constantize end
url_prefix()
click to toggle source
# File lib/ocs/client.rb, line 44 def url_prefix "#{url_protocol}://#{host}" end
url_protocol()
click to toggle source
# File lib/ocs/client.rb, line 48 def url_protocol ssl ? "https" : "http" end