Class: VcoWorkflows::VcoSession
- Inherits:
-
Object
- Object
- VcoWorkflows::VcoSession
- Defined in:
- lib/vcoworkflows/vcosession.rb
Overview
VcoSession is a simple wrapper for RestClient::Resource, and supports GET and POST operations against the vCO API.
Instance Attribute Summary collapse
-
#rest_resource ⇒ Object
readonly
Accessor for rest-client object, primarily for testing purposes.
Instance Method Summary collapse
-
#get(endpoint, headers = {}) ⇒ String
Perform a REST GET operation against the specified endpoint.
-
#initialize(config: nil, uri: nil, user: nil, password: nil, verify_ssl: true) ⇒ VcoSession
constructor
Initialize the session.
-
#post(endpoint, body, headers = {}) ⇒ String
Perform a REST POST operation against the specified endpoint with the given data body.
Constructor Details
#initialize(config: nil, uri: nil, user: nil, password: nil, verify_ssl: true) ⇒ VcoSession
Initialize the session
When specifying a config, do not provide other parameters. Likewise, if providing uri, user, and password, a config object is not necessary.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/vcoworkflows/vcosession.rb', line 25 def initialize(config: nil, uri: nil, user: nil, password: nil, verify_ssl: true) # If a configuration object was provided, use it. # If we got a URL and no config, build a new config with the URL and any # other options that passed in. # Otherwise, load the default config file if possible... if config config = config elsif uri && config.nil? config = VcoWorkflows::Config.new(url: uri, username: user, password: password, verify_ssl: verify_ssl) elsif uri.nil? && config.nil? config = VcoWorkflows::Config.new end RestClient.proxy = ENV['http_proxy'] # Set a proxy if present @rest_resource = RestClient::Resource.new(config.url, user: config.username, password: config.password, verify_ssl: config.verify_ssl) end |
Instance Attribute Details
#rest_resource ⇒ Object (readonly)
Accessor for rest-client object, primarily for testing purposes
11 12 13 |
# File 'lib/vcoworkflows/vcosession.rb', line 11 def rest_resource @rest_resource end |
Instance Method Details
#get(endpoint, headers = {}) ⇒ String
Perform a REST GET operation against the specified endpoint
54 55 56 57 |
# File 'lib/vcoworkflows/vcosession.rb', line 54 def get(endpoint, headers = {}) headers = { accept: :json }.merge(headers) @rest_resource[endpoint].get headers end |
#post(endpoint, body, headers = {}) ⇒ String
Perform a REST POST operation against the specified endpoint with the given data body
66 67 68 69 |
# File 'lib/vcoworkflows/vcosession.rb', line 66 def post(endpoint, body, headers = {}) headers = { accept: :json, content_type: :json }.merge(headers) @rest_resource[endpoint].post body, headers end |