api-ai-ruby 1.2.2 → 1.2.3
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 +4 -4
- data/README.md +7 -27
- data/lib/api-ai-ruby.rb +1 -1
- data/lib/api-ai-ruby/client.rb +14 -14
- data/lib/api-ai-ruby/constants.rb +1 -1
- data/lib/api-ai-ruby/request/event_request.rb +13 -0
- data/lib/api-ai-ruby/request/request_query.rb +1 -1
- data/spec/api-ai-ruby/api_spec.rb +10 -0
- metadata +13 -13
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 730482838f5570e11f15f9dc035bd1660dcc9ee6
         | 
| 4 | 
            +
              data.tar.gz: 50f4c68548a98f9055f01e8196f5bb1cea2931ef
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: ec864af3471a6f93aa1bb898e7fc29ed341b4dfb4828da406beb2570538bcd3f21b71755fdd3eb66822bda1a1e5baac3ae6e6ba866a24957eeee16903504f238
         | 
| 7 | 
            +
              data.tar.gz: 9d1548277b2bb7a98b5f11bb789f91d80d050bfa3d9b7dad7fd29da6a63c87d2a48d3833648c594358124b623185cee0e87d5a0e68d2546c7cc2bc1d2dc9a53c
         | 
    
        data/README.md
    CHANGED
    
    | @@ -22,35 +22,14 @@ After that you can send text requests to the https://api.ai with command | |
| 22 22 | 
             
            response = client.text_request 'hello!'
         | 
| 23 23 | 
             
            ```
         | 
| 24 24 |  | 
| 25 | 
            -
             | 
| 25 | 
            +
            Or try to invocate intent via defined '[event](https://docs.api.ai/docs/concept-events)':
         | 
| 26 26 |  | 
| 27 27 | 
             
            ```ruby
         | 
| 28 | 
            -
            file = File.new 'hello.wav'
         | 
| 29 | 
            -
            response = client.voice_request(file)
         | 
| 30 | 
            -
            ```
         | 
| 31 28 |  | 
| 32 | 
            -
             | 
| 33 | 
            -
             | 
| 34 | 
            -
            {
         | 
| 35 | 
            -
             | 
| 36 | 
            -
              :timestamp => "2015-12-22T08:42:15.785Z",
         | 
| 37 | 
            -
              :result    => {
         | 
| 38 | 
            -
                :source        => "agent",
         | 
| 39 | 
            -
                :resolvedQuery => "Hello",
         | 
| 40 | 
            -
                :speech        => "Hi! How are you?",
         | 
| 41 | 
            -
                :action        => "greeting",
         | 
| 42 | 
            -
                :parameters    => {},
         | 
| 43 | 
            -
                :contexts      => [],
         | 
| 44 | 
            -
                :metadata      => {
         | 
| 45 | 
            -
                  :intentId   => "a5d685ab-1f19-46b0-9478-69f794553668",
         | 
| 46 | 
            -
                  :intentName => "hello"
         | 
| 47 | 
            -
                }
         | 
| 48 | 
            -
              },
         | 
| 49 | 
            -
              :status    => {
         | 
| 50 | 
            -
                :code      => 200,
         | 
| 51 | 
            -
                :errorType => "success"
         | 
| 52 | 
            -
              }
         | 
| 53 | 
            -
            }
         | 
| 29 | 
            +
            response_zero = client.event_request 'MY_CUSTOM_EVENT_NAME';
         | 
| 30 | 
            +
            response_one = client.event_request 'MY_EVENT_WITH_DATA_TO_STORE', {:param1 => 'value'}
         | 
| 31 | 
            +
            response_two = client.event_request 'MY_EVENT_WITH_DATA_TO_STORE', {:some_param => 'some_value'}, :resetContexts => true
         | 
| 32 | 
            +
             | 
| 54 33 | 
             
            ```
         | 
| 55 34 |  | 
| 56 35 | 
             
            **voice_request** and **text_request** methods returns symbolized https://api.ai response. Structure of response can be found at https://docs.api.ai/docs/query#response.
         | 
| @@ -73,7 +52,7 @@ And you also can send additional data to server during request, use second param | |
| 73 52 |  | 
| 74 53 | 
             
            ```ruby
         | 
| 75 54 | 
             
                response = client.text_request 'Hello', :contexts => ['firstContext'], :resetContexts => true
         | 
| 76 | 
            -
                response = client.voice_request file, :timezone =>  | 
| 55 | 
            +
                response = client.voice_request file, :timezone => 'America/New_York'
         | 
| 77 56 | 
             
            ```
         | 
| 78 57 |  | 
| 79 58 | 
             
            More information about possible parameters can be found at https://docs.api.ai/docs/query page
         | 
| @@ -162,6 +141,7 @@ Please see the [httprb wiki on timeouts](https://github.com/httprb/http/wiki/Tim | |
| 162 141 |  | 
| 163 142 | 
             
            #Changelog
         | 
| 164 143 |  | 
| 144 | 
            +
            * 1.2.3 - events support
         | 
| 165 145 | 
             
            * 1.2.2 - added configurable timeouts for requests (thanks [bramski](https://github.com/bramski))
         | 
| 166 146 | 
             
            * 1.2.1 - fixed UTF-8 in text-requests
         | 
| 167 147 | 
             
            * 1.2.0 - added configurable session_id and full userEntities support
         | 
    
        data/lib/api-ai-ruby.rb
    CHANGED
    
    | @@ -4,8 +4,8 @@ require 'api-ai-ruby/request_error' | |
| 4 4 | 
             
            require 'api-ai-ruby/client_error'
         | 
| 5 5 | 
             
            require 'api-ai-ruby/request/request_query'
         | 
| 6 6 | 
             
            require 'api-ai-ruby/request/text_request'
         | 
| 7 | 
            +
            require 'api-ai-ruby/request/event_request'
         | 
| 7 8 | 
             
            require 'api-ai-ruby/request/voice_request'
         | 
| 8 9 | 
             
            require 'api-ai-ruby/models/entry'
         | 
| 9 10 | 
             
            require 'api-ai-ruby/models/entity'
         | 
| 10 11 | 
             
            require 'api-ai-ruby/crud/user_entity_request'
         | 
| 11 | 
            -
             | 
    
        data/lib/api-ai-ruby/client.rb
    CHANGED
    
    | @@ -2,11 +2,10 @@ require 'securerandom' | |
| 2 2 |  | 
| 3 3 | 
             
            module ApiAiRuby
         | 
| 4 4 | 
             
              class Client
         | 
| 5 | 
            -
                attr_accessor :client_access_token, : | 
| 5 | 
            +
                attr_accessor :client_access_token, :timeout_options
         | 
| 6 6 | 
             
                attr_writer :user_agent, :api_version, :api_lang, :api_base_url, :api_session_id
         | 
| 7 7 |  | 
| 8 8 | 
             
                # Initializes a new Client object
         | 
| 9 | 
            -
                #
         | 
| 10 9 | 
             
                # @param options [Hash]
         | 
| 11 10 | 
             
                # @return [ApiAiRuby::Client]
         | 
| 12 11 | 
             
                def initialize(options = {})
         | 
| @@ -60,25 +59,26 @@ module ApiAiRuby | |
| 60 59 | 
             
                  ApiAiRuby::TextRequest.new(self, options).perform
         | 
| 61 60 | 
             
                end
         | 
| 62 61 |  | 
| 62 | 
            +
                # @param eventName [String]
         | 
| 63 | 
            +
                # @param data [Object]
         | 
| 64 | 
            +
                # @param options [Object]
         | 
| 65 | 
            +
                def event_request (eventName = '', data = {}, options = {})
         | 
| 66 | 
            +
                  raise ApiAiRuby::ClientError.new('Credentials missing') if !credentials?
         | 
| 67 | 
            +
                  options[:event] = {
         | 
| 68 | 
            +
                      name: eventName,
         | 
| 69 | 
            +
                      data: data
         | 
| 70 | 
            +
                  }
         | 
| 71 | 
            +
                  ApiAiRuby::EventRequest.new(self, options).perform
         | 
| 72 | 
            +
                end
         | 
| 73 | 
            +
             | 
| 63 74 | 
             
                def voice_request(file_stream, options = {})
         | 
| 64 75 | 
             
                  raise ApiAiRuby::ClientError.new('Credentials missing') if !credentials?
         | 
| 65 76 | 
             
                  options[:file] = file_stream
         | 
| 66 77 | 
             
                  ApiAiRuby::VoiceRequest.new(self, options).perform
         | 
| 67 78 | 
             
                end
         | 
| 68 79 |  | 
| 69 | 
            -
                 | 
| 70 | 
            -
                # @param entries [ApiAiRuby:Entry[]]
         | 
| 71 | 
            -
                # @param options [Hash]
         | 
| 72 | 
            -
             | 
| 73 | 
            -
                def user_entities_request #entity_name, entries, options = {}
         | 
| 80 | 
            +
                def user_entities_request
         | 
| 74 81 | 
             
                  ApiAiRuby::UserEntitiesRequest.new(self);
         | 
| 75 | 
            -
                  # raise ApiAiRuby::ClientError.new('Entity name required') if entity_name.nil?
         | 
| 76 | 
            -
                  # raise ApiAiRuby::ClientError.new('Entity entries array required') if !entries.nil? && entries.is_a?(Array)
         | 
| 77 | 
            -
                  # raise ApiAiRuby::ClientError.new('Entity name required') if !(options.has_key?(:entries) && options[:entries].is_a?(Array))
         | 
| 78 | 
            -
                  # options[:name] = entity_name
         | 
| 79 | 
            -
                  # options[:entries] = entries
         | 
| 80 | 
            -
                  # options[:extend] = options[:extend] || false
         | 
| 81 | 
            -
                  # ApiAiRuby::UserEntitiesRequest.new(self, options).perform
         | 
| 82 82 | 
             
                end
         | 
| 83 83 |  | 
| 84 84 | 
             
              end
         | 
| @@ -0,0 +1,13 @@ | |
| 1 | 
            +
            module ApiAiRuby
         | 
| 2 | 
            +
              class EventRequest < ApiAiRuby::RequestQuery
         | 
| 3 | 
            +
             | 
| 4 | 
            +
                # @param client [ApiAiRuby::Client]
         | 
| 5 | 
            +
                # @param options [Hash]
         | 
| 6 | 
            +
                # @return [ApiAiRuby::EventRequest]
         | 
| 7 | 
            +
                def initialize (client, options={})
         | 
| 8 | 
            +
                  options[:lang] = client.api_lang
         | 
| 9 | 
            +
                  super client, options
         | 
| 10 | 
            +
                  @headers['Content-Type'] = 'application/json; charset=UTF-8'
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
            end
         | 
| @@ -104,5 +104,15 @@ describe 'api' do | |
| 104 104 | 
             
                  @uer.delete('dwarfs')
         | 
| 105 105 | 
             
                  expect{@uer.retrieve('dwarfs')}.to raise_error(ApiAiRuby::RequestError)
         | 
| 106 106 | 
             
                end
         | 
| 107 | 
            +
             | 
| 108 | 
            +
                #
         | 
| 109 | 
            +
                # commented until test agent update
         | 
| 110 | 
            +
                #
         | 
| 111 | 
            +
                # it 'should invoke event' do
         | 
| 112 | 
            +
                # response = @client.event_request 'WELCOME'
         | 
| 113 | 
            +
                # expect(response[:result][:action]).to eq 'input.welcome'
         | 
| 114 | 
            +
                # puts(response)
         | 
| 115 | 
            +
                # end
         | 
| 116 | 
            +
             | 
| 107 117 | 
             
              end
         | 
| 108 118 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,55 +1,55 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: api-ai-ruby
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1.2. | 
| 4 | 
            +
              version: 1.2.3
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - api.ai
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2016- | 
| 11 | 
            +
            date: 2016-12-05 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: bundler
         | 
| 15 15 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 16 | 
             
                requirements:
         | 
| 17 | 
            -
                - - ~>
         | 
| 17 | 
            +
                - - "~>"
         | 
| 18 18 | 
             
                  - !ruby/object:Gem::Version
         | 
| 19 19 | 
             
                    version: '1.7'
         | 
| 20 20 | 
             
              type: :development
         | 
| 21 21 | 
             
              prerelease: false
         | 
| 22 22 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 23 | 
             
                requirements:
         | 
| 24 | 
            -
                - - ~>
         | 
| 24 | 
            +
                - - "~>"
         | 
| 25 25 | 
             
                  - !ruby/object:Gem::Version
         | 
| 26 26 | 
             
                    version: '1.7'
         | 
| 27 27 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 28 28 | 
             
              name: rake
         | 
| 29 29 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 30 | 
             
                requirements:
         | 
| 31 | 
            -
                - - ~>
         | 
| 31 | 
            +
                - - "~>"
         | 
| 32 32 | 
             
                  - !ruby/object:Gem::Version
         | 
| 33 33 | 
             
                    version: '10.0'
         | 
| 34 34 | 
             
              type: :development
         | 
| 35 35 | 
             
              prerelease: false
         | 
| 36 36 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 37 | 
             
                requirements:
         | 
| 38 | 
            -
                - - ~>
         | 
| 38 | 
            +
                - - "~>"
         | 
| 39 39 | 
             
                  - !ruby/object:Gem::Version
         | 
| 40 40 | 
             
                    version: '10.0'
         | 
| 41 41 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 42 42 | 
             
              name: http
         | 
| 43 43 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 44 44 | 
             
                requirements:
         | 
| 45 | 
            -
                - - ~>
         | 
| 45 | 
            +
                - - "~>"
         | 
| 46 46 | 
             
                  - !ruby/object:Gem::Version
         | 
| 47 47 | 
             
                    version: 0.9.4
         | 
| 48 48 | 
             
              type: :runtime
         | 
| 49 49 | 
             
              prerelease: false
         | 
| 50 50 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 51 51 | 
             
                requirements:
         | 
| 52 | 
            -
                - - ~>
         | 
| 52 | 
            +
                - - "~>"
         | 
| 53 53 | 
             
                  - !ruby/object:Gem::Version
         | 
| 54 54 | 
             
                    version: 0.9.4
         | 
| 55 55 | 
             
            description: Plugin makes it easy to integrate your Ruby application with https://api.ai
         | 
| @@ -60,7 +60,7 @@ executables: [] | |
| 60 60 | 
             
            extensions: []
         | 
| 61 61 | 
             
            extra_rdoc_files: []
         | 
| 62 62 | 
             
            files:
         | 
| 63 | 
            -
            - .gitignore
         | 
| 63 | 
            +
            - ".gitignore"
         | 
| 64 64 | 
             
            - Gemfile
         | 
| 65 65 | 
             
            - LICENSE
         | 
| 66 66 | 
             
            - README.md
         | 
| @@ -73,6 +73,7 @@ files: | |
| 73 73 | 
             
            - lib/api-ai-ruby/crud/user_entity_request.rb
         | 
| 74 74 | 
             
            - lib/api-ai-ruby/models/entity.rb
         | 
| 75 75 | 
             
            - lib/api-ai-ruby/models/entry.rb
         | 
| 76 | 
            +
            - lib/api-ai-ruby/request/event_request.rb
         | 
| 76 77 | 
             
            - lib/api-ai-ruby/request/request_query.rb
         | 
| 77 78 | 
             
            - lib/api-ai-ruby/request/text_request.rb
         | 
| 78 79 | 
             
            - lib/api-ai-ruby/request/voice_request.rb
         | 
| @@ -95,17 +96,17 @@ require_paths: | |
| 95 96 | 
             
            - lib
         | 
| 96 97 | 
             
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 97 98 | 
             
              requirements:
         | 
| 98 | 
            -
              - - ~>
         | 
| 99 | 
            +
              - - "~>"
         | 
| 99 100 | 
             
                - !ruby/object:Gem::Version
         | 
| 100 101 | 
             
                  version: '2.0'
         | 
| 101 102 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 102 103 | 
             
              requirements:
         | 
| 103 | 
            -
              - -  | 
| 104 | 
            +
              - - ">="
         | 
| 104 105 | 
             
                - !ruby/object:Gem::Version
         | 
| 105 106 | 
             
                  version: '0'
         | 
| 106 107 | 
             
            requirements: []
         | 
| 107 108 | 
             
            rubyforge_project: 
         | 
| 108 | 
            -
            rubygems_version: 2. | 
| 109 | 
            +
            rubygems_version: 2.5.1
         | 
| 109 110 | 
             
            signing_key: 
         | 
| 110 111 | 
             
            specification_version: 4
         | 
| 111 112 | 
             
            summary: ruby SDK for https://api.ai
         | 
| @@ -118,4 +119,3 @@ test_files: | |
| 118 119 | 
             
            - spec/api-ai-ruby/voice_request_spec.rb
         | 
| 119 120 | 
             
            - spec/fixtures/hello.wav
         | 
| 120 121 | 
             
            - spec/helper.rb
         | 
| 121 | 
            -
            has_rdoc: 
         |