ibm_watson 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
 - data/README.md +258 -0
 - data/bin/console +14 -0
 - data/bin/setup +8 -0
 - data/lib/ibm_watson.rb +16 -0
 - data/lib/ibm_watson/assistant_v1.rb +1997 -0
 - data/lib/ibm_watson/detailed_response.rb +21 -0
 - data/lib/ibm_watson/discovery_v1.rb +2039 -0
 - data/lib/ibm_watson/iam_token_manager.rb +166 -0
 - data/lib/ibm_watson/language_translator_v3.rb +411 -0
 - data/lib/ibm_watson/natural_language_classifier_v1.rb +309 -0
 - data/lib/ibm_watson/natural_language_understanding_v1.rb +297 -0
 - data/lib/ibm_watson/personality_insights_v3.rb +260 -0
 - data/lib/ibm_watson/speech_to_text_v1.rb +2153 -0
 - data/lib/ibm_watson/text_to_speech_v1.rb +716 -0
 - data/lib/ibm_watson/tone_analyzer_v3.rb +287 -0
 - data/lib/ibm_watson/version.rb +3 -0
 - data/lib/ibm_watson/visual_recognition_v3.rb +579 -0
 - data/lib/ibm_watson/watson_api_exception.rb +41 -0
 - data/lib/ibm_watson/watson_service.rb +180 -0
 - data/lib/ibm_watson/websocket/recognize_callback.rb +32 -0
 - data/lib/ibm_watson/websocket/speech_to_text_websocket_listener.rb +162 -0
 - data/rakefile +45 -0
 - data/test/integration/test_assistant_v1.rb +645 -0
 - data/test/integration/test_discovery_v1.rb +200 -0
 - data/test/integration/test_iam_assistant_v1.rb +707 -0
 - data/test/integration/test_language_translator_v3.rb +81 -0
 - data/test/integration/test_natural_language_classifier_v1.rb +69 -0
 - data/test/integration/test_natural_language_understanding_v1.rb +98 -0
 - data/test/integration/test_personality_insights_v3.rb +95 -0
 - data/test/integration/test_speech_to_text_v1.rb +187 -0
 - data/test/integration/test_text_to_speech_v1.rb +81 -0
 - data/test/integration/test_tone_analyzer_v3.rb +72 -0
 - data/test/integration/test_visual_recognition_v3.rb +64 -0
 - data/test/test_helper.rb +22 -0
 - data/test/unit/test_assistant_v1.rb +1598 -0
 - data/test/unit/test_discovery_v1.rb +1144 -0
 - data/test/unit/test_iam_token_manager.rb +165 -0
 - data/test/unit/test_language_translator_v3.rb +461 -0
 - data/test/unit/test_natural_language_classifier_v1.rb +187 -0
 - data/test/unit/test_natural_language_understanding_v1.rb +132 -0
 - data/test/unit/test_personality_insights_v3.rb +172 -0
 - data/test/unit/test_speech_to_text_v1.rb +755 -0
 - data/test/unit/test_text_to_speech_v1.rb +336 -0
 - data/test/unit/test_tone_analyzer_v3.rb +200 -0
 - data/test/unit/test_vcap_using_personality_insights.rb +150 -0
 - data/test/unit/test_visual_recognition_v3.rb +345 -0
 - metadata +302 -0
 
| 
         @@ -0,0 +1,187 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require("json")
         
     | 
| 
      
 4 
     | 
    
         
            +
            require_relative("./../test_helper.rb")
         
     | 
| 
      
 5 
     | 
    
         
            +
            require("webmock/minitest")
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            WebMock.disable_net_connect!(allow_localhost: true)
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            # Unit tests for the Natural Language Classifier V1 Service
         
     | 
| 
      
 10 
     | 
    
         
            +
            class NaturalLanguageClassifierV1Test < Minitest::Test
         
     | 
| 
      
 11 
     | 
    
         
            +
              def test_success
         
     | 
| 
      
 12 
     | 
    
         
            +
                service = IBMWatson::NaturalLanguageClassifierV1.new(
         
     | 
| 
      
 13 
     | 
    
         
            +
                  username: "username",
         
     | 
| 
      
 14 
     | 
    
         
            +
                  password: "password"
         
     | 
| 
      
 15 
     | 
    
         
            +
                )
         
     | 
| 
      
 16 
     | 
    
         
            +
                list_response = {
         
     | 
| 
      
 17 
     | 
    
         
            +
                  "classifiers" => [
         
     | 
| 
      
 18 
     | 
    
         
            +
                    {
         
     | 
| 
      
 19 
     | 
    
         
            +
                      "url" => "https://gateway.watsonplatform.net/natural-language-classifier-experimental/api/v1/classifiers/497EF2-nlc-00",
         
     | 
| 
      
 20 
     | 
    
         
            +
                      "classifier_id" => "497EF2-nlc-00"
         
     | 
| 
      
 21 
     | 
    
         
            +
                    }
         
     | 
| 
      
 22 
     | 
    
         
            +
                  ]
         
     | 
| 
      
 23 
     | 
    
         
            +
                }
         
     | 
| 
      
 24 
     | 
    
         
            +
                stub_request(:get, "https://gateway.watsonplatform.net/natural-language-classifier/api/v1/classifiers")
         
     | 
| 
      
 25 
     | 
    
         
            +
                  .with(
         
     | 
| 
      
 26 
     | 
    
         
            +
                    headers: {
         
     | 
| 
      
 27 
     | 
    
         
            +
                      "Accept" => "application/json",
         
     | 
| 
      
 28 
     | 
    
         
            +
                      "Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
         
     | 
| 
      
 29 
     | 
    
         
            +
                      "Host" => "gateway.watsonplatform.net"
         
     | 
| 
      
 30 
     | 
    
         
            +
                    }
         
     | 
| 
      
 31 
     | 
    
         
            +
                  ).to_return(status: 200, body: list_response.to_json, headers: { "Content-Type" => "application/json" })
         
     | 
| 
      
 32 
     | 
    
         
            +
                service_response = service.list_classifiers
         
     | 
| 
      
 33 
     | 
    
         
            +
                assert_equal(list_response, service_response.result)
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                status_response = {
         
     | 
| 
      
 36 
     | 
    
         
            +
                  "url" => "https://gateway.watsonplatform.net/natural-language-classifier/api/v1/classifiers/497EF2-nlc-00",
         
     | 
| 
      
 37 
     | 
    
         
            +
                  "status" => "Available",
         
     | 
| 
      
 38 
     | 
    
         
            +
                  "status_description" => "The classifier instance is now available and is ready to take classifier requests.",
         
     | 
| 
      
 39 
     | 
    
         
            +
                  "classifier_id" => "497EF2-nlc-00"
         
     | 
| 
      
 40 
     | 
    
         
            +
                }
         
     | 
| 
      
 41 
     | 
    
         
            +
                stub_request(:get, "https://gateway.watsonplatform.net/natural-language-classifier/api/v1/classifiers/497EF2-nlc-00")
         
     | 
| 
      
 42 
     | 
    
         
            +
                  .with(
         
     | 
| 
      
 43 
     | 
    
         
            +
                    headers: {
         
     | 
| 
      
 44 
     | 
    
         
            +
                      "Accept" => "application/json",
         
     | 
| 
      
 45 
     | 
    
         
            +
                      "Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
         
     | 
| 
      
 46 
     | 
    
         
            +
                      "Host" => "gateway.watsonplatform.net"
         
     | 
| 
      
 47 
     | 
    
         
            +
                    }
         
     | 
| 
      
 48 
     | 
    
         
            +
                  ).to_return(status: 200, body: status_response.to_json, headers: { "Content-Type" => "application/json" })
         
     | 
| 
      
 49 
     | 
    
         
            +
                service_response = service.get_classifier(
         
     | 
| 
      
 50 
     | 
    
         
            +
                  classifier_id: "497EF2-nlc-00"
         
     | 
| 
      
 51 
     | 
    
         
            +
                )
         
     | 
| 
      
 52 
     | 
    
         
            +
                assert_equal(status_response, service_response.result)
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
                classify_response = {
         
     | 
| 
      
 55 
     | 
    
         
            +
                  "url" => "https://gateway.watsonplatform.net/natural-language-classifier/api/v1",
         
     | 
| 
      
 56 
     | 
    
         
            +
                  "text" => "test",
         
     | 
| 
      
 57 
     | 
    
         
            +
                  "classes" =>
         
     | 
| 
      
 58 
     | 
    
         
            +
                  [
         
     | 
| 
      
 59 
     | 
    
         
            +
                    {
         
     | 
| 
      
 60 
     | 
    
         
            +
                      "class_name" => "conditions",
         
     | 
| 
      
 61 
     | 
    
         
            +
                      "confidence" => 0.6575315710901418
         
     | 
| 
      
 62 
     | 
    
         
            +
                    },
         
     | 
| 
      
 63 
     | 
    
         
            +
                    {
         
     | 
| 
      
 64 
     | 
    
         
            +
                      "class_name" => "temperature",
         
     | 
| 
      
 65 
     | 
    
         
            +
                      "confidence" => 0.3424684289098582
         
     | 
| 
      
 66 
     | 
    
         
            +
                    }
         
     | 
| 
      
 67 
     | 
    
         
            +
                  ],
         
     | 
| 
      
 68 
     | 
    
         
            +
                  "classifier_id" => "497EF2-nlc-00",
         
     | 
| 
      
 69 
     | 
    
         
            +
                  "top_class" => "conditions"
         
     | 
| 
      
 70 
     | 
    
         
            +
                }
         
     | 
| 
      
 71 
     | 
    
         
            +
                stub_request(:post, "https://gateway.watsonplatform.net/natural-language-classifier/api/v1/classifiers/497EF2-nlc-00/classify")
         
     | 
| 
      
 72 
     | 
    
         
            +
                  .with(
         
     | 
| 
      
 73 
     | 
    
         
            +
                    body: "{\"text\":\"test\"}",
         
     | 
| 
      
 74 
     | 
    
         
            +
                    headers: {
         
     | 
| 
      
 75 
     | 
    
         
            +
                      "Accept" => "application/json",
         
     | 
| 
      
 76 
     | 
    
         
            +
                      "Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
         
     | 
| 
      
 77 
     | 
    
         
            +
                      "Content-Type" => "application/json",
         
     | 
| 
      
 78 
     | 
    
         
            +
                      "Host" => "gateway.watsonplatform.net"
         
     | 
| 
      
 79 
     | 
    
         
            +
                    }
         
     | 
| 
      
 80 
     | 
    
         
            +
                  ).to_return(status: 200, body: classify_response.to_json, headers: { "Content-Type" => "application/json" })
         
     | 
| 
      
 81 
     | 
    
         
            +
                service_response = service.classify(
         
     | 
| 
      
 82 
     | 
    
         
            +
                  classifier_id: "497EF2-nlc-00",
         
     | 
| 
      
 83 
     | 
    
         
            +
                  text: "test"
         
     | 
| 
      
 84 
     | 
    
         
            +
                )
         
     | 
| 
      
 85 
     | 
    
         
            +
                assert_equal(classify_response, service_response.result)
         
     | 
| 
      
 86 
     | 
    
         
            +
             
     | 
| 
      
 87 
     | 
    
         
            +
                create_response = {
         
     | 
| 
      
 88 
     | 
    
         
            +
                  "url" => "https://gateway.watsonplatform.net/natural-language-classifier/api/v1/classifiers/497EF2-nlc-00",
         
     | 
| 
      
 89 
     | 
    
         
            +
                  "status" => "Available",
         
     | 
| 
      
 90 
     | 
    
         
            +
                  "status_description" => "The classifier instance is now available and is ready to take classifier requests.",
         
     | 
| 
      
 91 
     | 
    
         
            +
                  "classifier_id" => "497EF2-nlc-00"
         
     | 
| 
      
 92 
     | 
    
         
            +
                }
         
     | 
| 
      
 93 
     | 
    
         
            +
                stub_request(:post, "https://gateway.watsonplatform.net/natural-language-classifier/api/v1/classifiers")
         
     | 
| 
      
 94 
     | 
    
         
            +
                  .with(
         
     | 
| 
      
 95 
     | 
    
         
            +
                    headers: {
         
     | 
| 
      
 96 
     | 
    
         
            +
                      "Accept" => "application/json",
         
     | 
| 
      
 97 
     | 
    
         
            +
                      "Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
         
     | 
| 
      
 98 
     | 
    
         
            +
                      "Host" => "gateway.watsonplatform.net"
         
     | 
| 
      
 99 
     | 
    
         
            +
                    }
         
     | 
| 
      
 100 
     | 
    
         
            +
                  ).to_return(status: 200, body: create_response.to_json, headers: { "Content-Type" => "application/json" })
         
     | 
| 
      
 101 
     | 
    
         
            +
                training_data = File.open(Dir.getwd + "/resources/weather_data_train.csv")
         
     | 
| 
      
 102 
     | 
    
         
            +
                service_response = service.create_classifier(
         
     | 
| 
      
 103 
     | 
    
         
            +
                  training_data: training_data,
         
     | 
| 
      
 104 
     | 
    
         
            +
                  training_data_filename: "weather_data_train.csv",
         
     | 
| 
      
 105 
     | 
    
         
            +
                  metadata: { "language" => "en" },
         
     | 
| 
      
 106 
     | 
    
         
            +
                  metadata_filename: "metadata"
         
     | 
| 
      
 107 
     | 
    
         
            +
                )
         
     | 
| 
      
 108 
     | 
    
         
            +
                assert_equal(create_response, service_response.result)
         
     | 
| 
      
 109 
     | 
    
         
            +
             
     | 
| 
      
 110 
     | 
    
         
            +
                service_response = service.create_classifier(
         
     | 
| 
      
 111 
     | 
    
         
            +
                  training_data: { "training" => "data" },
         
     | 
| 
      
 112 
     | 
    
         
            +
                  metadata: { "language" => "en" }
         
     | 
| 
      
 113 
     | 
    
         
            +
                )
         
     | 
| 
      
 114 
     | 
    
         
            +
                assert_equal(create_response, service_response.result)
         
     | 
| 
      
 115 
     | 
    
         
            +
             
     | 
| 
      
 116 
     | 
    
         
            +
                stub_request(:delete, "https://gateway.watsonplatform.net/natural-language-classifier/api/v1/classifiers/497EF2-nlc-00")
         
     | 
| 
      
 117 
     | 
    
         
            +
                  .with(
         
     | 
| 
      
 118 
     | 
    
         
            +
                    headers: {
         
     | 
| 
      
 119 
     | 
    
         
            +
                      "Accept" => "application/json",
         
     | 
| 
      
 120 
     | 
    
         
            +
                      "Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
         
     | 
| 
      
 121 
     | 
    
         
            +
                      "Host" => "gateway.watsonplatform.net"
         
     | 
| 
      
 122 
     | 
    
         
            +
                    }
         
     | 
| 
      
 123 
     | 
    
         
            +
                  ).to_return(status: 200, body: "", headers: {})
         
     | 
| 
      
 124 
     | 
    
         
            +
                service_response = service.delete_classifier(
         
     | 
| 
      
 125 
     | 
    
         
            +
                  classifier_id: "497EF2-nlc-00"
         
     | 
| 
      
 126 
     | 
    
         
            +
                )
         
     | 
| 
      
 127 
     | 
    
         
            +
                assert_nil(service_response)
         
     | 
| 
      
 128 
     | 
    
         
            +
              end
         
     | 
| 
      
 129 
     | 
    
         
            +
             
     | 
| 
      
 130 
     | 
    
         
            +
              def test_classify_collection
         
     | 
| 
      
 131 
     | 
    
         
            +
                service = IBMWatson::NaturalLanguageClassifierV1.new(
         
     | 
| 
      
 132 
     | 
    
         
            +
                  username: "username",
         
     | 
| 
      
 133 
     | 
    
         
            +
                  password: "password"
         
     | 
| 
      
 134 
     | 
    
         
            +
                )
         
     | 
| 
      
 135 
     | 
    
         
            +
                classify_collection_response = {
         
     | 
| 
      
 136 
     | 
    
         
            +
                  "classifier_id" => "497EF2-nlc-00",
         
     | 
| 
      
 137 
     | 
    
         
            +
                  "url" => "https://gateway.watsonplatform.net/natural-language-classifier/api/v1/classifiers/10D41B-nlc-1",
         
     | 
| 
      
 138 
     | 
    
         
            +
                  "collection" => [
         
     | 
| 
      
 139 
     | 
    
         
            +
                    {
         
     | 
| 
      
 140 
     | 
    
         
            +
                      "text" => "How hot will it be today?",
         
     | 
| 
      
 141 
     | 
    
         
            +
                      "top_class" => "temperature",
         
     | 
| 
      
 142 
     | 
    
         
            +
                      "classes" => [
         
     | 
| 
      
 143 
     | 
    
         
            +
                        {
         
     | 
| 
      
 144 
     | 
    
         
            +
                          "class_name" => "temperature",
         
     | 
| 
      
 145 
     | 
    
         
            +
                          "confidence" => 0.9930558798985937
         
     | 
| 
      
 146 
     | 
    
         
            +
                        },
         
     | 
| 
      
 147 
     | 
    
         
            +
                        {
         
     | 
| 
      
 148 
     | 
    
         
            +
                          "class_name" => "conditions",
         
     | 
| 
      
 149 
     | 
    
         
            +
                          "confidence" => 0.006944120101406304
         
     | 
| 
      
 150 
     | 
    
         
            +
                        }
         
     | 
| 
      
 151 
     | 
    
         
            +
                      ]
         
     | 
| 
      
 152 
     | 
    
         
            +
                    },
         
     | 
| 
      
 153 
     | 
    
         
            +
                    {
         
     | 
| 
      
 154 
     | 
    
         
            +
                      "text" => "Is it hot outside?",
         
     | 
| 
      
 155 
     | 
    
         
            +
                      "top_class" => "temperature",
         
     | 
| 
      
 156 
     | 
    
         
            +
                      "classes" => [
         
     | 
| 
      
 157 
     | 
    
         
            +
                        {
         
     | 
| 
      
 158 
     | 
    
         
            +
                          "class_name" => "temperature",
         
     | 
| 
      
 159 
     | 
    
         
            +
                          "confidence" => 1
         
     | 
| 
      
 160 
     | 
    
         
            +
                        },
         
     | 
| 
      
 161 
     | 
    
         
            +
                        {
         
     | 
| 
      
 162 
     | 
    
         
            +
                          "class_name" => "conditions",
         
     | 
| 
      
 163 
     | 
    
         
            +
                          "confidence" => 0
         
     | 
| 
      
 164 
     | 
    
         
            +
                        }
         
     | 
| 
      
 165 
     | 
    
         
            +
                      ]
         
     | 
| 
      
 166 
     | 
    
         
            +
                    }
         
     | 
| 
      
 167 
     | 
    
         
            +
                  ]
         
     | 
| 
      
 168 
     | 
    
         
            +
                }
         
     | 
| 
      
 169 
     | 
    
         
            +
                classifier_id = "497EF2-nlc-00"
         
     | 
| 
      
 170 
     | 
    
         
            +
                collection = [{ "text" => "How hot will it be today?" }, { "text" => "Is it hot outside?" }]
         
     | 
| 
      
 171 
     | 
    
         
            +
                stub_request(:post, "https://gateway.watsonplatform.net/natural-language-classifier/api/v1/classifiers/497EF2-nlc-00/classify_collection")
         
     | 
| 
      
 172 
     | 
    
         
            +
                  .with(
         
     | 
| 
      
 173 
     | 
    
         
            +
                    body: "{\"collection\":[{\"text\":\"How hot will it be today?\"},{\"text\":\"Is it hot outside?\"}]}",
         
     | 
| 
      
 174 
     | 
    
         
            +
                    headers: {
         
     | 
| 
      
 175 
     | 
    
         
            +
                      "Accept" => "application/json",
         
     | 
| 
      
 176 
     | 
    
         
            +
                      "Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
         
     | 
| 
      
 177 
     | 
    
         
            +
                      "Content-Type" => "application/json",
         
     | 
| 
      
 178 
     | 
    
         
            +
                      "Host" => "gateway.watsonplatform.net"
         
     | 
| 
      
 179 
     | 
    
         
            +
                    }
         
     | 
| 
      
 180 
     | 
    
         
            +
                  ).to_return(status: 200, body: classify_collection_response.to_json, headers: { "Content-Type" => "application/json" })
         
     | 
| 
      
 181 
     | 
    
         
            +
                service_response = service.classify_collection(
         
     | 
| 
      
 182 
     | 
    
         
            +
                  classifier_id: classifier_id,
         
     | 
| 
      
 183 
     | 
    
         
            +
                  collection: collection
         
     | 
| 
      
 184 
     | 
    
         
            +
                )
         
     | 
| 
      
 185 
     | 
    
         
            +
                assert_equal(classify_collection_response, service_response.result)
         
     | 
| 
      
 186 
     | 
    
         
            +
              end
         
     | 
| 
      
 187 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,132 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require("json")
         
     | 
| 
      
 4 
     | 
    
         
            +
            require_relative("./../test_helper.rb")
         
     | 
| 
      
 5 
     | 
    
         
            +
            require("webmock/minitest")
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            WebMock.disable_net_connect!(allow_localhost: true)
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            # Unit tests for the Natural Language Understanding V1 Service
         
     | 
| 
      
 10 
     | 
    
         
            +
            class NaturalLanguageUnderstandingV1Test < Minitest::Test
         
     | 
| 
      
 11 
     | 
    
         
            +
              def test_text_analyze
         
     | 
| 
      
 12 
     | 
    
         
            +
                service = IBMWatson::NaturalLanguageUnderstandingV1.new(
         
     | 
| 
      
 13 
     | 
    
         
            +
                  version: "2018-03-16",
         
     | 
| 
      
 14 
     | 
    
         
            +
                  username: "username",
         
     | 
| 
      
 15 
     | 
    
         
            +
                  password: "password"
         
     | 
| 
      
 16 
     | 
    
         
            +
                )
         
     | 
| 
      
 17 
     | 
    
         
            +
                stub_request(:post, "https://gateway.watsonplatform.net/natural-language-understanding/api/v1/analyze?version=2018-03-16")
         
     | 
| 
      
 18 
     | 
    
         
            +
                  .with(
         
     | 
| 
      
 19 
     | 
    
         
            +
                    body: "{\"features\":{\"sentiment\":{}},\"text\":\"hello this is a test\"}",
         
     | 
| 
      
 20 
     | 
    
         
            +
                    headers: {
         
     | 
| 
      
 21 
     | 
    
         
            +
                      "Accept" => "application/json",
         
     | 
| 
      
 22 
     | 
    
         
            +
                      "Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
         
     | 
| 
      
 23 
     | 
    
         
            +
                      "Content-Type" => "application/json",
         
     | 
| 
      
 24 
     | 
    
         
            +
                      "Host" => "gateway.watsonplatform.net"
         
     | 
| 
      
 25 
     | 
    
         
            +
                    }
         
     | 
| 
      
 26 
     | 
    
         
            +
                  ).to_return(status: 200, body: { resulting_key: true }.to_json, headers: { "Content-Type" => "application/json" })
         
     | 
| 
      
 27 
     | 
    
         
            +
                service_response = service.analyze(
         
     | 
| 
      
 28 
     | 
    
         
            +
                  features: {
         
     | 
| 
      
 29 
     | 
    
         
            +
                    sentiment: {}
         
     | 
| 
      
 30 
     | 
    
         
            +
                  },
         
     | 
| 
      
 31 
     | 
    
         
            +
                  text: "hello this is a test"
         
     | 
| 
      
 32 
     | 
    
         
            +
                )
         
     | 
| 
      
 33 
     | 
    
         
            +
                assert_equal({ "resulting_key" => true }, service_response.result)
         
     | 
| 
      
 34 
     | 
    
         
            +
              end
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
              def test_html_analyze
         
     | 
| 
      
 37 
     | 
    
         
            +
                service = IBMWatson::NaturalLanguageUnderstandingV1.new(
         
     | 
| 
      
 38 
     | 
    
         
            +
                  version: "2018-03-16",
         
     | 
| 
      
 39 
     | 
    
         
            +
                  username: "username",
         
     | 
| 
      
 40 
     | 
    
         
            +
                  password: "password"
         
     | 
| 
      
 41 
     | 
    
         
            +
                )
         
     | 
| 
      
 42 
     | 
    
         
            +
                stub_request(:post, "https://gateway.watsonplatform.net/natural-language-understanding/api/v1/analyze?version=2018-03-16")
         
     | 
| 
      
 43 
     | 
    
         
            +
                  .with(
         
     | 
| 
      
 44 
     | 
    
         
            +
                    body: "{\"features\":{\"sentiment\":{},\"emotion\":{\"document\":false}},\"html\":\"<span>hello this is a test </span>\"}",
         
     | 
| 
      
 45 
     | 
    
         
            +
                    headers: {
         
     | 
| 
      
 46 
     | 
    
         
            +
                      "Accept" => "application/json",
         
     | 
| 
      
 47 
     | 
    
         
            +
                      "Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
         
     | 
| 
      
 48 
     | 
    
         
            +
                      "Content-Type" => "application/json",
         
     | 
| 
      
 49 
     | 
    
         
            +
                      "Host" => "gateway.watsonplatform.net"
         
     | 
| 
      
 50 
     | 
    
         
            +
                    }
         
     | 
| 
      
 51 
     | 
    
         
            +
                  ).to_return(status: 200, body: { resulting_key: true }.to_json, headers: { "Content-Type" => "application/json" })
         
     | 
| 
      
 52 
     | 
    
         
            +
                service_response = service.analyze(
         
     | 
| 
      
 53 
     | 
    
         
            +
                  features: {
         
     | 
| 
      
 54 
     | 
    
         
            +
                    sentiment: {},
         
     | 
| 
      
 55 
     | 
    
         
            +
                    emotion: {
         
     | 
| 
      
 56 
     | 
    
         
            +
                      document: false
         
     | 
| 
      
 57 
     | 
    
         
            +
                    }
         
     | 
| 
      
 58 
     | 
    
         
            +
                  },
         
     | 
| 
      
 59 
     | 
    
         
            +
                  html: "<span>hello this is a test </span>"
         
     | 
| 
      
 60 
     | 
    
         
            +
                )
         
     | 
| 
      
 61 
     | 
    
         
            +
                assert_equal({ "resulting_key" => true }, service_response.result)
         
     | 
| 
      
 62 
     | 
    
         
            +
              end
         
     | 
| 
      
 63 
     | 
    
         
            +
             
     | 
| 
      
 64 
     | 
    
         
            +
              def test_url_analyze
         
     | 
| 
      
 65 
     | 
    
         
            +
                service = IBMWatson::NaturalLanguageUnderstandingV1.new(
         
     | 
| 
      
 66 
     | 
    
         
            +
                  version: "2018-03-16",
         
     | 
| 
      
 67 
     | 
    
         
            +
                  username: "username",
         
     | 
| 
      
 68 
     | 
    
         
            +
                  password: "password"
         
     | 
| 
      
 69 
     | 
    
         
            +
                )
         
     | 
| 
      
 70 
     | 
    
         
            +
                stub_request(:post, "https://gateway.watsonplatform.net/natural-language-understanding/api/v1/analyze?version=2018-03-16")
         
     | 
| 
      
 71 
     | 
    
         
            +
                  .with(
         
     | 
| 
      
 72 
     | 
    
         
            +
                    body: "{\"features\":{\"sentiment\":{},\"emotion\":{\"document\":false}},\"url\":\"http://cnn.com\",\"xpath\":\"/bogus/xpath\",\"language\":\"en\"}",
         
     | 
| 
      
 73 
     | 
    
         
            +
                    headers: {
         
     | 
| 
      
 74 
     | 
    
         
            +
                      "Accept" => "application/json",
         
     | 
| 
      
 75 
     | 
    
         
            +
                      "Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
         
     | 
| 
      
 76 
     | 
    
         
            +
                      "Content-Type" => "application/json",
         
     | 
| 
      
 77 
     | 
    
         
            +
                      "Host" => "gateway.watsonplatform.net"
         
     | 
| 
      
 78 
     | 
    
         
            +
                    }
         
     | 
| 
      
 79 
     | 
    
         
            +
                  ).to_return(status: 200, body: { resulting_key: true }.to_json, headers: { "Content-Type" => "application/json" })
         
     | 
| 
      
 80 
     | 
    
         
            +
                service_response = service.analyze(
         
     | 
| 
      
 81 
     | 
    
         
            +
                  features: {
         
     | 
| 
      
 82 
     | 
    
         
            +
                    sentiment: {},
         
     | 
| 
      
 83 
     | 
    
         
            +
                    emotion: {
         
     | 
| 
      
 84 
     | 
    
         
            +
                      document: false
         
     | 
| 
      
 85 
     | 
    
         
            +
                    }
         
     | 
| 
      
 86 
     | 
    
         
            +
                  },
         
     | 
| 
      
 87 
     | 
    
         
            +
                  url: "http://cnn.com",
         
     | 
| 
      
 88 
     | 
    
         
            +
                  xpath: "/bogus/xpath",
         
     | 
| 
      
 89 
     | 
    
         
            +
                  language: "en"
         
     | 
| 
      
 90 
     | 
    
         
            +
                )
         
     | 
| 
      
 91 
     | 
    
         
            +
                assert_equal({ "resulting_key" => true }, service_response.result)
         
     | 
| 
      
 92 
     | 
    
         
            +
              end
         
     | 
| 
      
 93 
     | 
    
         
            +
             
     | 
| 
      
 94 
     | 
    
         
            +
              def test_list_models
         
     | 
| 
      
 95 
     | 
    
         
            +
                service = IBMWatson::NaturalLanguageUnderstandingV1.new(
         
     | 
| 
      
 96 
     | 
    
         
            +
                  version: "2018-03-16",
         
     | 
| 
      
 97 
     | 
    
         
            +
                  username: "username",
         
     | 
| 
      
 98 
     | 
    
         
            +
                  password: "password"
         
     | 
| 
      
 99 
     | 
    
         
            +
                )
         
     | 
| 
      
 100 
     | 
    
         
            +
                stub_request(:get, "https://gateway.watsonplatform.net/natural-language-understanding/api/v1/models?version=2018-03-16")
         
     | 
| 
      
 101 
     | 
    
         
            +
                  .with(
         
     | 
| 
      
 102 
     | 
    
         
            +
                    headers: {
         
     | 
| 
      
 103 
     | 
    
         
            +
                      "Accept" => "application/json",
         
     | 
| 
      
 104 
     | 
    
         
            +
                      "Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
         
     | 
| 
      
 105 
     | 
    
         
            +
                      "Host" => "gateway.watsonplatform.net"
         
     | 
| 
      
 106 
     | 
    
         
            +
                    }
         
     | 
| 
      
 107 
     | 
    
         
            +
                  ).to_return(status: 200, body: { resulting_key: true }.to_json, headers: { "Content-Type" => "application/json" })
         
     | 
| 
      
 108 
     | 
    
         
            +
                service_response = service.list_models
         
     | 
| 
      
 109 
     | 
    
         
            +
                assert_equal({ "resulting_key" => true }, service_response.result)
         
     | 
| 
      
 110 
     | 
    
         
            +
              end
         
     | 
| 
      
 111 
     | 
    
         
            +
             
     | 
| 
      
 112 
     | 
    
         
            +
              def test_delete_model
         
     | 
| 
      
 113 
     | 
    
         
            +
                model_id = "invalid_model_id"
         
     | 
| 
      
 114 
     | 
    
         
            +
                service = IBMWatson::NaturalLanguageUnderstandingV1.new(
         
     | 
| 
      
 115 
     | 
    
         
            +
                  version: "2018-03-16",
         
     | 
| 
      
 116 
     | 
    
         
            +
                  username: "username",
         
     | 
| 
      
 117 
     | 
    
         
            +
                  password: "password"
         
     | 
| 
      
 118 
     | 
    
         
            +
                )
         
     | 
| 
      
 119 
     | 
    
         
            +
                stub_request(:delete, "https://gateway.watsonplatform.net/natural-language-understanding/api/v1/models/invalid_model_id?version=2018-03-16")
         
     | 
| 
      
 120 
     | 
    
         
            +
                  .with(
         
     | 
| 
      
 121 
     | 
    
         
            +
                    headers: {
         
     | 
| 
      
 122 
     | 
    
         
            +
                      "Accept" => "application/json",
         
     | 
| 
      
 123 
     | 
    
         
            +
                      "Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
         
     | 
| 
      
 124 
     | 
    
         
            +
                      "Host" => "gateway.watsonplatform.net"
         
     | 
| 
      
 125 
     | 
    
         
            +
                    }
         
     | 
| 
      
 126 
     | 
    
         
            +
                  ).to_return(status: 200, body: { deleted: model_id }.to_json, headers: { "Content-Type" => "application/json" })
         
     | 
| 
      
 127 
     | 
    
         
            +
                service_response = service.delete_model(
         
     | 
| 
      
 128 
     | 
    
         
            +
                  model_id: model_id
         
     | 
| 
      
 129 
     | 
    
         
            +
                )
         
     | 
| 
      
 130 
     | 
    
         
            +
                assert_equal({ "deleted" => model_id }, service_response.result)
         
     | 
| 
      
 131 
     | 
    
         
            +
              end
         
     | 
| 
      
 132 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,172 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require("json")
         
     | 
| 
      
 4 
     | 
    
         
            +
            require_relative("./../test_helper.rb")
         
     | 
| 
      
 5 
     | 
    
         
            +
            require("webmock/minitest")
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            WebMock.disable_net_connect!(allow_localhost: true)
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            # Unit tests for the Personality Insights V3 Service
         
     | 
| 
      
 10 
     | 
    
         
            +
            class PersonalityInsightsV3Test < Minitest::Test
         
     | 
| 
      
 11 
     | 
    
         
            +
              def test_plain_to_json
         
     | 
| 
      
 12 
     | 
    
         
            +
                profile_response = File.read(Dir.getwd + "/resources/personality-v3-expect1.txt")
         
     | 
| 
      
 13 
     | 
    
         
            +
                personality_text = File.read(Dir.getwd + "/resources/personality-v3.txt")
         
     | 
| 
      
 14 
     | 
    
         
            +
                headers = {
         
     | 
| 
      
 15 
     | 
    
         
            +
                  "Content-Type" => "application/json"
         
     | 
| 
      
 16 
     | 
    
         
            +
                }
         
     | 
| 
      
 17 
     | 
    
         
            +
                expected_response = DetailedResponse.new(status: 200, body: JSON.parse(profile_response), headers: headers)
         
     | 
| 
      
 18 
     | 
    
         
            +
                stub_request(:post, "https://gateway.watsonplatform.net/personality-insights/api/v3/profile?version=2017-10-13")
         
     | 
| 
      
 19 
     | 
    
         
            +
                  .with(
         
     | 
| 
      
 20 
     | 
    
         
            +
                    body: personality_text,
         
     | 
| 
      
 21 
     | 
    
         
            +
                    headers: {
         
     | 
| 
      
 22 
     | 
    
         
            +
                      "Accept" => "application/json",
         
     | 
| 
      
 23 
     | 
    
         
            +
                      "Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
         
     | 
| 
      
 24 
     | 
    
         
            +
                      "Content-Type" => "text/plain;charset=utf-8",
         
     | 
| 
      
 25 
     | 
    
         
            +
                      "Host" => "gateway.watsonplatform.net"
         
     | 
| 
      
 26 
     | 
    
         
            +
                    }
         
     | 
| 
      
 27 
     | 
    
         
            +
                  ).to_return(status: 200, body: profile_response, headers: headers)
         
     | 
| 
      
 28 
     | 
    
         
            +
                service = IBMWatson::PersonalityInsightsV3.new(
         
     | 
| 
      
 29 
     | 
    
         
            +
                  version: "2017-10-13",
         
     | 
| 
      
 30 
     | 
    
         
            +
                  username: "username",
         
     | 
| 
      
 31 
     | 
    
         
            +
                  password: "password"
         
     | 
| 
      
 32 
     | 
    
         
            +
                )
         
     | 
| 
      
 33 
     | 
    
         
            +
                service_response = service.profile(
         
     | 
| 
      
 34 
     | 
    
         
            +
                  content: personality_text,
         
     | 
| 
      
 35 
     | 
    
         
            +
                  content_type: "text/plain;charset=utf-8"
         
     | 
| 
      
 36 
     | 
    
         
            +
                )
         
     | 
| 
      
 37 
     | 
    
         
            +
                assert_equal(expected_response.status, service_response.status)
         
     | 
| 
      
 38 
     | 
    
         
            +
                assert_equal(expected_response.result, service_response.result)
         
     | 
| 
      
 39 
     | 
    
         
            +
                expected_response.headers.each_key do |key|
         
     | 
| 
      
 40 
     | 
    
         
            +
                  assert(service_response.headers.key?(key))
         
     | 
| 
      
 41 
     | 
    
         
            +
                  assert(expected_response.headers[key] == service_response.headers[key])
         
     | 
| 
      
 42 
     | 
    
         
            +
                end
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
                stub_request(:post, "https://gateway.watsonplatform.net/personality-insights/api/v3/profile?version=2017-10-13")
         
     | 
| 
      
 45 
     | 
    
         
            +
                  .with(
         
     | 
| 
      
 46 
     | 
    
         
            +
                    body: { "personality" => "text" }.to_json,
         
     | 
| 
      
 47 
     | 
    
         
            +
                    headers: {
         
     | 
| 
      
 48 
     | 
    
         
            +
                      "Accept" => "application/json",
         
     | 
| 
      
 49 
     | 
    
         
            +
                      "Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
         
     | 
| 
      
 50 
     | 
    
         
            +
                      "Content-Type" => "application/json",
         
     | 
| 
      
 51 
     | 
    
         
            +
                      "Host" => "gateway.watsonplatform.net"
         
     | 
| 
      
 52 
     | 
    
         
            +
                    }
         
     | 
| 
      
 53 
     | 
    
         
            +
                  ).to_return(status: 200, body: { "profile" => "response" }.to_json, headers: headers)
         
     | 
| 
      
 54 
     | 
    
         
            +
                service_response = service.profile(
         
     | 
| 
      
 55 
     | 
    
         
            +
                  content: { "personality" => "text" },
         
     | 
| 
      
 56 
     | 
    
         
            +
                  content_type: "application/json"
         
     | 
| 
      
 57 
     | 
    
         
            +
                )
         
     | 
| 
      
 58 
     | 
    
         
            +
                assert_equal({ "profile" => "response" }, service_response.result)
         
     | 
| 
      
 59 
     | 
    
         
            +
              end
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
      
 61 
     | 
    
         
            +
              def test_json_to_json
         
     | 
| 
      
 62 
     | 
    
         
            +
                profile_response = File.read(Dir.getwd + "/resources/personality-v3-expect2.txt")
         
     | 
| 
      
 63 
     | 
    
         
            +
                personality_text = File.read(Dir.getwd + "/resources/personality-v3.json")
         
     | 
| 
      
 64 
     | 
    
         
            +
                headers = {
         
     | 
| 
      
 65 
     | 
    
         
            +
                  "Content-Type" => "applicaiton/json"
         
     | 
| 
      
 66 
     | 
    
         
            +
                }
         
     | 
| 
      
 67 
     | 
    
         
            +
                expected_response = DetailedResponse.new(status: 200, body: profile_response, headers: headers)
         
     | 
| 
      
 68 
     | 
    
         
            +
                stub_request(:post, "https://gateway.watsonplatform.net/personality-insights/api/v3/profile?consumption_preferences=true&raw_scores=true&version=2017-10-13")
         
     | 
| 
      
 69 
     | 
    
         
            +
                  .with(
         
     | 
| 
      
 70 
     | 
    
         
            +
                    body: personality_text,
         
     | 
| 
      
 71 
     | 
    
         
            +
                    headers: {
         
     | 
| 
      
 72 
     | 
    
         
            +
                      "Accept" => "application/json",
         
     | 
| 
      
 73 
     | 
    
         
            +
                      "Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
         
     | 
| 
      
 74 
     | 
    
         
            +
                      "Content-Type" => "application/json",
         
     | 
| 
      
 75 
     | 
    
         
            +
                      "Host" => "gateway.watsonplatform.net"
         
     | 
| 
      
 76 
     | 
    
         
            +
                    }
         
     | 
| 
      
 77 
     | 
    
         
            +
                  ).to_return(status: 200, body: profile_response, headers: headers)
         
     | 
| 
      
 78 
     | 
    
         
            +
                service = IBMWatson::PersonalityInsightsV3.new(
         
     | 
| 
      
 79 
     | 
    
         
            +
                  version: "2017-10-13",
         
     | 
| 
      
 80 
     | 
    
         
            +
                  username: "username",
         
     | 
| 
      
 81 
     | 
    
         
            +
                  password: "password"
         
     | 
| 
      
 82 
     | 
    
         
            +
                )
         
     | 
| 
      
 83 
     | 
    
         
            +
                service_response = service.profile(
         
     | 
| 
      
 84 
     | 
    
         
            +
                  content: personality_text,
         
     | 
| 
      
 85 
     | 
    
         
            +
                  content_type: "application/json",
         
     | 
| 
      
 86 
     | 
    
         
            +
                  raw_scores: true,
         
     | 
| 
      
 87 
     | 
    
         
            +
                  consumption_preferences: true
         
     | 
| 
      
 88 
     | 
    
         
            +
                )
         
     | 
| 
      
 89 
     | 
    
         
            +
                assert_equal(expected_response.status, service_response.status)
         
     | 
| 
      
 90 
     | 
    
         
            +
                assert_equal(expected_response.result, service_response.result)
         
     | 
| 
      
 91 
     | 
    
         
            +
                expected_response.headers.each_key do |key|
         
     | 
| 
      
 92 
     | 
    
         
            +
                  assert(service_response.headers.key?(key))
         
     | 
| 
      
 93 
     | 
    
         
            +
                  assert(expected_response.headers[key] == service_response.headers[key])
         
     | 
| 
      
 94 
     | 
    
         
            +
                end
         
     | 
| 
      
 95 
     | 
    
         
            +
              end
         
     | 
| 
      
 96 
     | 
    
         
            +
             
     | 
| 
      
 97 
     | 
    
         
            +
              def test_json_to_csv
         
     | 
| 
      
 98 
     | 
    
         
            +
                profile_response = File.read(Dir.getwd + "/resources/personality-v3-expect3.txt")
         
     | 
| 
      
 99 
     | 
    
         
            +
                personality_text = File.read(Dir.getwd + "/resources/personality-v3.json")
         
     | 
| 
      
 100 
     | 
    
         
            +
                headers = {
         
     | 
| 
      
 101 
     | 
    
         
            +
                  "Content-Type" => "application/json"
         
     | 
| 
      
 102 
     | 
    
         
            +
                }
         
     | 
| 
      
 103 
     | 
    
         
            +
                expected_response = DetailedResponse.new(status: 200, body: profile_response, headers: headers)
         
     | 
| 
      
 104 
     | 
    
         
            +
                stub_request(:post, "https://gateway.watsonplatform.net/personality-insights/api/v3/profile?consumption_preferences=true&csv_headers=true&raw_scores=true&version=2017-10-13")
         
     | 
| 
      
 105 
     | 
    
         
            +
                  .with(
         
     | 
| 
      
 106 
     | 
    
         
            +
                    body: personality_text,
         
     | 
| 
      
 107 
     | 
    
         
            +
                    headers: {
         
     | 
| 
      
 108 
     | 
    
         
            +
                      "Accept" => "application/json",
         
     | 
| 
      
 109 
     | 
    
         
            +
                      "Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
         
     | 
| 
      
 110 
     | 
    
         
            +
                      "Content-Type" => "application/json",
         
     | 
| 
      
 111 
     | 
    
         
            +
                      "Host" => "gateway.watsonplatform.net"
         
     | 
| 
      
 112 
     | 
    
         
            +
                    }
         
     | 
| 
      
 113 
     | 
    
         
            +
                  ).to_return(status: 200, body: profile_response.to_json, headers: headers)
         
     | 
| 
      
 114 
     | 
    
         
            +
                service = IBMWatson::PersonalityInsightsV3.new(
         
     | 
| 
      
 115 
     | 
    
         
            +
                  version: "2017-10-13",
         
     | 
| 
      
 116 
     | 
    
         
            +
                  username: "username",
         
     | 
| 
      
 117 
     | 
    
         
            +
                  password: "password"
         
     | 
| 
      
 118 
     | 
    
         
            +
                )
         
     | 
| 
      
 119 
     | 
    
         
            +
                service_response = service.profile(
         
     | 
| 
      
 120 
     | 
    
         
            +
                  content: personality_text,
         
     | 
| 
      
 121 
     | 
    
         
            +
                  content_type: "application/json",
         
     | 
| 
      
 122 
     | 
    
         
            +
                  accept: "text/csv",
         
     | 
| 
      
 123 
     | 
    
         
            +
                  csv_headers: true,
         
     | 
| 
      
 124 
     | 
    
         
            +
                  raw_scores: true,
         
     | 
| 
      
 125 
     | 
    
         
            +
                  consumption_preferences: true
         
     | 
| 
      
 126 
     | 
    
         
            +
                )
         
     | 
| 
      
 127 
     | 
    
         
            +
                assert_equal(expected_response.status, service_response.status)
         
     | 
| 
      
 128 
     | 
    
         
            +
                assert_equal(expected_response.result, service_response.result)
         
     | 
| 
      
 129 
     | 
    
         
            +
                expected_response.headers.each_key do |key|
         
     | 
| 
      
 130 
     | 
    
         
            +
                  assert(service_response.headers.key?(key))
         
     | 
| 
      
 131 
     | 
    
         
            +
                  assert(expected_response.headers[key] == service_response.headers[key])
         
     | 
| 
      
 132 
     | 
    
         
            +
                end
         
     | 
| 
      
 133 
     | 
    
         
            +
              end
         
     | 
| 
      
 134 
     | 
    
         
            +
             
     | 
| 
      
 135 
     | 
    
         
            +
              def test_plain_to_json_es
         
     | 
| 
      
 136 
     | 
    
         
            +
                profile_response = JSON.parse(File.read(Dir.getwd + "/resources/personality-v3-expect4.txt"))
         
     | 
| 
      
 137 
     | 
    
         
            +
                personality_text = File.read(Dir.getwd + "/resources/personality-v3-es.txt")
         
     | 
| 
      
 138 
     | 
    
         
            +
                headers = {
         
     | 
| 
      
 139 
     | 
    
         
            +
                  "Content-Type" => "application/json"
         
     | 
| 
      
 140 
     | 
    
         
            +
                }
         
     | 
| 
      
 141 
     | 
    
         
            +
                expected_response = DetailedResponse.new(status: 200, body: profile_response, headers: headers)
         
     | 
| 
      
 142 
     | 
    
         
            +
                stub_request(:post, "https://gateway.watsonplatform.net/personality-insights/api/v3/profile?version=2017-10-13")
         
     | 
| 
      
 143 
     | 
    
         
            +
                  .with(
         
     | 
| 
      
 144 
     | 
    
         
            +
                    body: personality_text,
         
     | 
| 
      
 145 
     | 
    
         
            +
                    headers: {
         
     | 
| 
      
 146 
     | 
    
         
            +
                      "Accept" => "application/json",
         
     | 
| 
      
 147 
     | 
    
         
            +
                      "Accept-Language" => "es",
         
     | 
| 
      
 148 
     | 
    
         
            +
                      "Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
         
     | 
| 
      
 149 
     | 
    
         
            +
                      "Content-Language" => "es",
         
     | 
| 
      
 150 
     | 
    
         
            +
                      "Content-Type" => "text/plain;charset=utf-8",
         
     | 
| 
      
 151 
     | 
    
         
            +
                      "Host" => "gateway.watsonplatform.net"
         
     | 
| 
      
 152 
     | 
    
         
            +
                    }
         
     | 
| 
      
 153 
     | 
    
         
            +
                  ).to_return(status: 200, body: profile_response.to_json, headers: headers)
         
     | 
| 
      
 154 
     | 
    
         
            +
                service = IBMWatson::PersonalityInsightsV3.new(
         
     | 
| 
      
 155 
     | 
    
         
            +
                  version: "2017-10-13",
         
     | 
| 
      
 156 
     | 
    
         
            +
                  username: "username",
         
     | 
| 
      
 157 
     | 
    
         
            +
                  password: "password"
         
     | 
| 
      
 158 
     | 
    
         
            +
                )
         
     | 
| 
      
 159 
     | 
    
         
            +
                service_response = service.profile(
         
     | 
| 
      
 160 
     | 
    
         
            +
                  content: personality_text,
         
     | 
| 
      
 161 
     | 
    
         
            +
                  content_type: "text/plain;charset=utf-8",
         
     | 
| 
      
 162 
     | 
    
         
            +
                  content_language: "es",
         
     | 
| 
      
 163 
     | 
    
         
            +
                  accept_language: "es"
         
     | 
| 
      
 164 
     | 
    
         
            +
                )
         
     | 
| 
      
 165 
     | 
    
         
            +
                assert_equal(expected_response.status, service_response.status)
         
     | 
| 
      
 166 
     | 
    
         
            +
                assert_equal(expected_response.result, service_response.result)
         
     | 
| 
      
 167 
     | 
    
         
            +
                expected_response.headers.each_key do |key|
         
     | 
| 
      
 168 
     | 
    
         
            +
                  assert(service_response.headers.key?(key))
         
     | 
| 
      
 169 
     | 
    
         
            +
                  assert(expected_response.headers[key] == service_response.headers[key])
         
     | 
| 
      
 170 
     | 
    
         
            +
                end
         
     | 
| 
      
 171 
     | 
    
         
            +
              end
         
     | 
| 
      
 172 
     | 
    
         
            +
            end
         
     |