<commit_before>#
# Author:: <NAME> (<<EMAIL>>)
# Copyright:: Copyright (c) 2015 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require 'ffi_yajl'
require 'json'
require 'rest-client'

module OracleCloud
  class Client # rubocop:disable Metrics/ClassLength
    attr_reader :identity_domain, :password, :username

    def initialize(opts)
      @api_url         = opts[:api_url]
      @identity_domain = opts[:identity_domain]
      @private_cloud   = opts[:private_cloud] || false
      @username        = opts[:username]
      @password        = opts[:password]
      @verify_ssl      = opts.fetch(:verify_ssl, true)
      @cookie          = nil

      validate_client_options!
    end

    #################################
    #
    # methods to other API objects
    #

    def imagelists
      OracleCloud::ImageLists.new(self)
    end

    def instance_request(*args)
      OracleCloud::InstanceRequest.new(self, *args)
    end

    def instances
      OracleCloud::Instances.new(self)
    end

    def ip_associations
      OracleCloud::IPAssociations.new(self)
    end

    def orchestrations
      OracleCloud::Orchestrations.new(self)
    end

    def shapes
      OracleCloud::Shapes.new(self)
    end

    def sshkeys
      OracleCloud::SSHKeys.new(self)
    end

    #################################
    #
    # client methods
    #

    def validate_client_options!
      raise ArgumentError, 'Username, password and identity_domain are required' if
        @username.nil? || @password.nil? || @identity_domain.nil?
      raise ArgumentError, 'An API URL is required' if @api_url.nil?
      raise ArgumentError, "API URL #{@api_url} is not a valid URI." unless valid_uri?(@api_url)
    end

    def valid_uri?(uri)
      uri = URI.parse(uri)
      uri.is_a?(URI::HTTP)
    rescue URI::InvalidURIError
      false
    end

    def private_cloud?
      @private_cloud
    end

    def username_with_domain
      "#{full_identity_domain}/#{@username}"
    end

    def full_identity_domain
      if private_cloud?
        @identity_domain
      else<commit_msg>fixing small travis error in #private_cloud?<commit_after>#
# Author:: <NAME> (<<EMAIL>>)
# Copyright:: Copyright (c) 2015 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require 'ffi_yajl'
require 'json'
require 'rest-client'

module OracleCloud
  class Client # rubocop:disable Metrics/ClassLength
    attr_reader :identity_domain, :password, :username

    def initialize(opts)
      @api_url         = opts[:api_url]
      @identity_domain = opts[:identity_domain]
      @private_cloud   = opts[:private_cloud] || false
      @username        = opts[:username]
      @password        = opts[:password]
      @verify_ssl      = opts.fetch(:verify_ssl, true)
      @cookie          = nil

      validate_client_options!
    end

    #################################
    #
    # methods to other API objects
    #

    def imagelists
      OracleCloud::ImageLists.new(self)
    end

    def instance_request(*args)
      OracleCloud::InstanceRequest.new(self, *args)
    end

    def instances
      OracleCloud::Instances.new(self)
    end

    def ip_associations
      OracleCloud::IPAssociations.new(self)
    end

    def orchestrations
      OracleCloud::Orchestrations.new(self)
    end

    def shapes
      OracleCloud::Shapes.new(self)
    end

    def sshkeys
      OracleCloud::SSHKeys.new(self)
    end

    #################################
    #
    # client methods
    #

    def validate_client_options!
      raise ArgumentError, 'Username, password and identity_domain are required' if
        @username.nil? || @password.nil? || @identity_domain.nil?
      raise ArgumentError, 'An API URL is required' if @api_url.nil?
      raise ArgumentError, "API URL #{@api_url} is not a valid URI." unless valid_uri?(@api_url)
    end

    def valid_uri?(uri)
      uri = URI.parse(uri)
      uri.is_a?(URI::HTTP)
    rescue URI::InvalidURIError
      false
    end

    def private_cloud?
      @private_cloud == true
    end

    def username_with_domain
      "#{full_identity_domain}/#{@username}"
    end

    def full_identity_domain
      if private_cloud?
        @identity_domain
      else
{'fraction_non_alphanumeric': 0.11192764273600904, 'fraction_numerical': 0.003768607499528924, 'mean_word_length': 2.996987951807229, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4195070', 'n_tokens_mistral': 1560, 'n_tokens_neox': 1521, 'n_words': 455}