Class: Ocs::Client
- Inherits:
-
Object
- Object
- Ocs::Client
- Defined in:
- lib/ocs/client.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#secret_key ⇒ Object
readonly
Returns the value of attribute secret_key.
-
#ssl ⇒ Object
readonly
Returns the value of attribute ssl.
Instance Method Summary collapse
- #call(name, options = {}) ⇒ Object
- #connection ⇒ Object
-
#initialize(host:, api_key:, secret_key:, path: "/client/api", logger: nil, ssl: true) ⇒ Client
constructor
A new instance of Client.
- #new(resource_name, options = {}) ⇒ Object
- #send(name, options = {}) ⇒ Object
Constructor Details
#initialize(host:, api_key:, secret_key:, path: "/client/api", logger: nil, ssl: true) ⇒ Client
Returns a new instance of Client.
5 6 7 8 9 10 11 12 |
# 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 |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object (private)
52 53 54 55 56 57 58 59 60 61 62 |
# 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 |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
3 4 5 |
# File 'lib/ocs/client.rb', line 3 def api_key @api_key end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
3 4 5 |
# File 'lib/ocs/client.rb', line 3 def host @host end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
3 4 5 |
# File 'lib/ocs/client.rb', line 3 def logger @logger end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
3 4 5 |
# File 'lib/ocs/client.rb', line 3 def path @path end |
#secret_key ⇒ Object (readonly)
Returns the value of attribute secret_key.
3 4 5 |
# File 'lib/ocs/client.rb', line 3 def secret_key @secret_key end |
#ssl ⇒ Object (readonly)
Returns the value of attribute ssl.
3 4 5 |
# File 'lib/ocs/client.rb', line 3 def ssl @ssl end |
Instance Method Details
#call(name, options = {}) ⇒ Object
14 15 16 |
# File 'lib/ocs/client.rb', line 14 def call(name, = {}) send(name, ).content end |
#connection ⇒ Object
18 19 20 21 22 23 24 |
# 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 = {}) ⇒ Object
26 27 28 |
# File 'lib/ocs/client.rb', line 26 def new(resource_name, = {}) resource_class(resource_name).new(self, ) end |