wit-ruby 0.0.1
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/MIT.LICENSE +22 -0
- data/README.md +20 -0
- data/lib/wit-ruby.rb +2 -0
- data/lib/wit/version.rb +3 -0
- data/lib/wit/wit.rb +59 -0
- data/spec/wit/wit_spec.rb +18 -0
- metadata +52 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 65f38b09d6036ef26cebf939021a5de5dbf069b4
|
4
|
+
data.tar.gz: 8e710c72d4a80c6bf6dba6bae98063185480459f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5f78942fae930ab0a8808a94ead5ea91ffa76d569bc732f9fe7cf5dba9c3e6ae0f5057802d1bd3879b438a5c1ad7586372988221166525b66537c8742cadad21
|
7
|
+
data.tar.gz: 42e0286fb7f1521113b287a659ae6229edf15f9c2dd4a6803cf42e95c9dc4c8aab886844e2afa8d4eaba336b94fc2d2dabbe46c8c916a4e5dcb59fb086370958
|
data/MIT.LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright 2012 Jeremy Jackson / ModeSet
|
2
|
+
|
3
|
+
https://github.com/modeset/wit-ruby
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
wit-ruby
|
2
|
+
========
|
3
|
+
|
4
|
+
[](http://badge.fury.io/rb/wit-ruby)
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
|
12
|
+
## License
|
13
|
+
|
14
|
+
Licensed under the [MIT License](http://creativecommons.org/licenses/MIT/)
|
15
|
+
|
16
|
+
Copyright 2012 [Mode Set](https://github.com/modeset)
|
17
|
+
|
18
|
+
|
19
|
+
## Make Code Not War
|
20
|
+

|
data/lib/wit-ruby.rb
ADDED
data/lib/wit/version.rb
ADDED
data/lib/wit/wit.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Wit
|
5
|
+
|
6
|
+
TOKEN = ENV['WIT_TOKEN']
|
7
|
+
|
8
|
+
def self.message(message = '')
|
9
|
+
uri = URI("https://api.wit.ai/message?q=#{URI.escape(message)}")
|
10
|
+
http = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
|
11
|
+
req = Net::HTTP::Get.new(uri)
|
12
|
+
req['Authorization'] = "Bearer #{TOKEN}"
|
13
|
+
http.request(req)
|
14
|
+
end
|
15
|
+
|
16
|
+
if http.is_a?(Net::HTTPUnauthorized)
|
17
|
+
raise Unauthorized, "incorrect token set for Wit::TOKEN set an env for WIT_TOKEN or set Wit::TOKEN manually"
|
18
|
+
end
|
19
|
+
|
20
|
+
if http.is_a?(Net::HTTPSuccess)
|
21
|
+
return Response.new(JSON.parse(http.body))
|
22
|
+
end
|
23
|
+
|
24
|
+
false
|
25
|
+
end
|
26
|
+
|
27
|
+
class Response
|
28
|
+
|
29
|
+
attr_reader :raw, :msg_id, :msg_body, :intent, :confidence, :entities
|
30
|
+
|
31
|
+
def initialize(hash)
|
32
|
+
@raw = hash
|
33
|
+
@msg_id = hash['msg_id']
|
34
|
+
@msg_body = hash['msg_body']
|
35
|
+
@intent = hash['outcome']['intent']
|
36
|
+
@confidence = hash['outcome']['confidence']
|
37
|
+
@entities = {}
|
38
|
+
hash['outcome']['entities'].each do |name, entity|
|
39
|
+
@entities[name.to_sym] = Entity.new(entity)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
class Entity
|
46
|
+
|
47
|
+
attr_reader :start, :end, :value, :body
|
48
|
+
|
49
|
+
def initialize(hash)
|
50
|
+
@start = hash['start']
|
51
|
+
@end = hash['end']
|
52
|
+
@value = hash['value']
|
53
|
+
@body = hash['body']
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
class Unauthorized < Exception; end
|
59
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'wit/wit'
|
2
|
+
|
3
|
+
describe Wit do
|
4
|
+
|
5
|
+
describe ".message" do
|
6
|
+
|
7
|
+
it "returns the expected output" do
|
8
|
+
res = Wit.message('deploy master foo to bar')
|
9
|
+
expect( res ).to be_a Wit::Response
|
10
|
+
expect( res.msg_body ).to eq 'deploy master foo to bar'
|
11
|
+
expect( res.intent ).to eq 'deploy'
|
12
|
+
expect( res.entities[:branch] ).to be_a Wit::Entity
|
13
|
+
expect( res.entities[:branch].value ).to eq 'master'
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wit-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jeremy Jackson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-18 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A simple library for interacting with wit.ai -- will expand as the api
|
14
|
+
does
|
15
|
+
email:
|
16
|
+
- info@modeset.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- lib/wit/version.rb
|
22
|
+
- lib/wit/wit.rb
|
23
|
+
- lib/wit-ruby.rb
|
24
|
+
- MIT.LICENSE
|
25
|
+
- README.md
|
26
|
+
- spec/wit/wit_spec.rb
|
27
|
+
homepage: https://github.com/modeset/teaspoon
|
28
|
+
licenses:
|
29
|
+
- MIT
|
30
|
+
metadata: {}
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
requirements: []
|
46
|
+
rubyforge_project:
|
47
|
+
rubygems_version: 2.0.3
|
48
|
+
signing_key:
|
49
|
+
specification_version: 4
|
50
|
+
summary: 'wit-ruby: Easy interface for wit.ai'
|
51
|
+
test_files:
|
52
|
+
- spec/wit/wit_spec.rb
|