wit 0.0.1 → 1.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 +4 -4
- data/ext/wit/extconf.rb +36 -0
- data/ext/wit/wit.c +153 -0
- metadata +17 -130
- data/.gitignore +0 -17
- data/.rspec +0 -2
- data/.yardopts +0 -4
- data/CHANGES.md +0 -6
- data/Gemfile +0 -3
- data/LICENSE.txt +0 -22
- data/README.md +0 -75
- data/Rakefile +0 -8
- data/lib/wit.rb +0 -2
- data/lib/wit/client.rb +0 -53
- data/lib/wit/version.rb +0 -4
- data/spec/spec_helper.rb +0 -13
- data/spec/wit/version_spec.rb +0 -5
- data/wit.gemspec +0 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5677b3c1a4a9686259219e06b8e3674bf59f317f
|
4
|
+
data.tar.gz: 5e9c34e7d8de94a6789caaa0ce4b44e7f374783a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e10573aebfd4aed8cb7e6b72bb07b99b381d6bdc79e8159c553e8c39e900195c67677c04ef1ad86685983971983368cdc42bc3ff51eb9c981115f28a65c73c88
|
7
|
+
data.tar.gz: 17ebe06ed1b9f53319edcf40691152150b3c8827be63318b56edf826f504cdfc8be12d763db87106033bd69b889c80b06d6a0c1aedd84947cd4dcc3d5d447710
|
data/ext/wit/extconf.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require "mkmf"
|
2
|
+
|
3
|
+
PATH = File.expand_path(File.dirname(__FILE__))
|
4
|
+
|
5
|
+
abort "missing Cargo (http://crates.io)" unless system("cargo")
|
6
|
+
|
7
|
+
if not File.exist?(PATH + '/libwit')
|
8
|
+
p "Cloning libwit repository..."
|
9
|
+
abort "unable to clone libwit repository" unless system("git clone https://github.com/wit-ai/libwit.git", :chdir=> PATH)
|
10
|
+
p "Updating libwit..."
|
11
|
+
abort "unable to update libwit repository" unless system("git pull", :chdir=> PATH + "/libwit")
|
12
|
+
end
|
13
|
+
if not (File.exist?(PATH + '/libwit/include/libwit.a') and File.exist?(PATH + '/libwit/lib/wit.h'))
|
14
|
+
p "Compiling libwit..."
|
15
|
+
abort "could not build libwit" unless system("./build_c.sh;", :chdir=> PATH + "/libwit")
|
16
|
+
end
|
17
|
+
|
18
|
+
LIBDIR = RbConfig::CONFIG['libdir']
|
19
|
+
INCLUDEDIR = RbConfig::CONFIG['includedir']
|
20
|
+
HEADER_DIRS = [
|
21
|
+
PATH + '/libwit/include',
|
22
|
+
INCLUDEDIR
|
23
|
+
]
|
24
|
+
LIB_DIRS = [
|
25
|
+
PATH + '/libwit/lib',
|
26
|
+
LIBDIR
|
27
|
+
]
|
28
|
+
|
29
|
+
$LOCAL_LIBS = '-lwit -lsox -lcurl'
|
30
|
+
|
31
|
+
dir_config 'wit', HEADER_DIRS, LIB_DIRS
|
32
|
+
|
33
|
+
abort "missing wit.h" unless have_header "wit.h"
|
34
|
+
abort "missing libwit" unless have_library "wit", "wit_init"
|
35
|
+
|
36
|
+
create_makefile "wit"
|
data/ext/wit/wit.c
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
#include <ruby/thread.h>
|
3
|
+
#include "wit.h"
|
4
|
+
|
5
|
+
struct wit_context *context;
|
6
|
+
static VALUE e_WitError;
|
7
|
+
static VALUE rb_cb;
|
8
|
+
|
9
|
+
static VALUE libwit_init(int argc, VALUE *argv, VALUE obj) {
|
10
|
+
const char *device_opt = NULL;
|
11
|
+
VALUE device = Qnil;
|
12
|
+
rb_scan_args(argc, argv, "01", &device);
|
13
|
+
if (device != Qnil) {
|
14
|
+
Check_Type(device, T_STRING);
|
15
|
+
device_opt = StringValuePtr(device);
|
16
|
+
}
|
17
|
+
context = wit_init(device_opt);
|
18
|
+
return Qnil;
|
19
|
+
}
|
20
|
+
|
21
|
+
static VALUE libwit_close(VALUE obj) {
|
22
|
+
if (context != NULL) {
|
23
|
+
wit_close(context);
|
24
|
+
}
|
25
|
+
return Qnil;
|
26
|
+
}
|
27
|
+
|
28
|
+
static VALUE libwit_text_query(VALUE obj, VALUE text, VALUE access_token) {
|
29
|
+
const char *resp;
|
30
|
+
if (context == NULL)
|
31
|
+
rb_raise(e_WitError, "Wit context uninitialized (did you call Wit.init?)");
|
32
|
+
Check_Type(text, T_STRING);
|
33
|
+
Check_Type(access_token, T_STRING);
|
34
|
+
VALUE str = Qnil;
|
35
|
+
resp = wit_text_query(context, StringValuePtr(text), StringValuePtr(access_token));
|
36
|
+
if (resp != NULL)
|
37
|
+
str = rb_str_new2(resp);
|
38
|
+
xfree((char *)resp);
|
39
|
+
return str;
|
40
|
+
}
|
41
|
+
|
42
|
+
static VALUE libwit_voice_query_start(VALUE obj, VALUE access_token) {
|
43
|
+
if (context == NULL)
|
44
|
+
rb_raise(e_WitError, "Wit context uninitialized (did you call Wit.init?)");
|
45
|
+
Check_Type(access_token, T_STRING);
|
46
|
+
wit_voice_query_start(context, StringValuePtr(access_token));
|
47
|
+
return Qnil;
|
48
|
+
}
|
49
|
+
|
50
|
+
static VALUE libwit_voice_query_stop(VALUE obj) {
|
51
|
+
const char *resp;
|
52
|
+
if (context == NULL)
|
53
|
+
rb_raise(e_WitError, "Wit context uninitialized (did you call Wit.init?)");
|
54
|
+
VALUE str = Qnil;
|
55
|
+
resp = wit_voice_query_stop(context);
|
56
|
+
if (resp != NULL)
|
57
|
+
str = rb_str_new2(resp);
|
58
|
+
xfree((char *)resp);
|
59
|
+
return str;
|
60
|
+
}
|
61
|
+
|
62
|
+
static VALUE libwit_voice_query_auto(VALUE obj, VALUE access_token)
|
63
|
+
{
|
64
|
+
const char *resp;
|
65
|
+
if (context == NULL)
|
66
|
+
rb_raise(e_WitError, "Wit context uninitialized (did you call Wit.init?)");
|
67
|
+
Check_Type(access_token, T_STRING);
|
68
|
+
VALUE str = Qnil;
|
69
|
+
resp = wit_voice_query_auto(context, StringValuePtr(access_token));
|
70
|
+
if (resp != NULL)
|
71
|
+
str = rb_str_new2(resp);
|
72
|
+
xfree((char *)resp);
|
73
|
+
return str;
|
74
|
+
}
|
75
|
+
|
76
|
+
static VALUE thread_wrapper_proc(void *args) {
|
77
|
+
VALUE str = Qnil;
|
78
|
+
if ((char *) args != NULL)
|
79
|
+
str = rb_str_new2((char *) args);
|
80
|
+
xfree(args);
|
81
|
+
rb_funcall(rb_cb, rb_intern("call"), 1, str);
|
82
|
+
return Qnil;
|
83
|
+
}
|
84
|
+
|
85
|
+
static VALUE thread_wrapper_meth(void *args) {
|
86
|
+
VALUE str = Qnil;
|
87
|
+
if ((char *) args != NULL)
|
88
|
+
str = rb_str_new2((char *) args);
|
89
|
+
xfree(args);
|
90
|
+
rb_funcall(rb_class_of(rb_cb), rb_to_id(rb_cb), 1, str);
|
91
|
+
return Qnil;
|
92
|
+
}
|
93
|
+
|
94
|
+
void my_wit_resp_callback(char *res) {
|
95
|
+
if (rb_cb == Qnil)
|
96
|
+
rb_raise(rb_eRuntimeError, "callback is nil");
|
97
|
+
if (rb_class_of(rb_cb) == rb_cProc)
|
98
|
+
rb_thread_create(thread_wrapper_proc, (char *)res);
|
99
|
+
else if (rb_class_of(rb_cb) == rb_cSymbol)
|
100
|
+
rb_thread_create(thread_wrapper_meth, (char *)res);
|
101
|
+
else
|
102
|
+
rb_raise(rb_eTypeError, "expected Proc or Symbol callback");
|
103
|
+
}
|
104
|
+
|
105
|
+
static VALUE libwit_text_query_async(VALUE obj, VALUE text, VALUE access_token, VALUE callback)
|
106
|
+
{
|
107
|
+
if (context == NULL)
|
108
|
+
rb_raise(e_WitError, "Wit context uninitialized (did you call Wit.init?)");
|
109
|
+
Check_Type(text, T_STRING);
|
110
|
+
Check_Type(access_token, T_STRING);
|
111
|
+
if (rb_class_of(callback) != rb_cSymbol && rb_class_of(callback) != rb_cProc)
|
112
|
+
rb_raise(rb_eTypeError, "expected Proc or Symbol callback");
|
113
|
+
rb_cb = callback;
|
114
|
+
wit_text_query_async(context, StringValuePtr(text), StringValuePtr(access_token), my_wit_resp_callback);
|
115
|
+
return Qnil;
|
116
|
+
}
|
117
|
+
|
118
|
+
static VALUE libwit_voice_query_stop_async(VALUE obj, VALUE callback)
|
119
|
+
{
|
120
|
+
if (context == NULL)
|
121
|
+
rb_raise(e_WitError, "Wit context uninitialized (did you call Wit.init?)");
|
122
|
+
if (rb_class_of(callback) != rb_cSymbol && rb_class_of(callback) != rb_cProc)
|
123
|
+
rb_raise(rb_eTypeError, "expected Proc or Symbol callback");
|
124
|
+
rb_cb = callback;
|
125
|
+
wit_voice_query_stop_async(context, my_wit_resp_callback);
|
126
|
+
return Qnil;
|
127
|
+
}
|
128
|
+
|
129
|
+
static VALUE libwit_voice_query_auto_async(VALUE obj, VALUE access_token, VALUE callback)
|
130
|
+
{
|
131
|
+
if (context == NULL)
|
132
|
+
rb_raise(e_WitError, "Wit context uninitialized (did you call Wit.init?)");
|
133
|
+
Check_Type(access_token, T_STRING);
|
134
|
+
if (rb_class_of(callback) != rb_cSymbol && rb_class_of(callback) != rb_cProc)
|
135
|
+
rb_raise(rb_eTypeError, "expected Proc or Symbol callback");
|
136
|
+
rb_cb = callback;
|
137
|
+
wit_voice_query_auto_async(context, StringValuePtr(access_token), my_wit_resp_callback);
|
138
|
+
return Qnil;
|
139
|
+
}
|
140
|
+
|
141
|
+
void Init_wit(void) {
|
142
|
+
VALUE wit_module = rb_define_module("Wit");
|
143
|
+
e_WitError = rb_define_class_under(wit_module, "Wit error", rb_eStandardError);
|
144
|
+
rb_define_module_function(wit_module, "init", libwit_init, -1);
|
145
|
+
rb_define_module_function(wit_module, "close", libwit_close, 0);
|
146
|
+
rb_define_module_function(wit_module, "text_query", libwit_text_query, 2);
|
147
|
+
rb_define_module_function(wit_module, "voice_query_start", libwit_voice_query_start, 1);
|
148
|
+
rb_define_module_function(wit_module, "voice_query_stop", libwit_voice_query_stop, 0);
|
149
|
+
rb_define_module_function(wit_module, "voice_query_auto", libwit_voice_query_auto, 1);
|
150
|
+
rb_define_module_function(wit_module, "text_query_async", libwit_text_query_async, 3);
|
151
|
+
rb_define_module_function(wit_module, "voice_query_stop_async", libwit_voice_query_stop_async, 1);
|
152
|
+
rb_define_module_function(wit_module, "voice_query_auto_async", libwit_voice_query_auto_async, 2);
|
153
|
+
}
|
metadata
CHANGED
@@ -1,137 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Julien Odent
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
|
14
|
-
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ~>
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 1.8.2
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ~>
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: 1.8.2
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rest-client
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ~>
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 1.6.7
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ~>
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: 1.6.7
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: bundler
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ~>
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '1.3'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ~>
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '1.3'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rake
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - '>='
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - '>='
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: redcarpet
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - '>='
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - '>='
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: rspec
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ~>
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: 2.14.1
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ~>
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: 2.14.1
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: yard
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - '>='
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - '>='
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
111
|
-
description: A Ruby wrapper for the Wit HTTP API, a natural language processing interface.
|
112
|
-
email:
|
113
|
-
- xtagon@gmail.com
|
11
|
+
date: 2014-09-30 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Ruby SDK for Wit.AI
|
14
|
+
email: julien@wit.ai
|
114
15
|
executables: []
|
115
|
-
extensions:
|
16
|
+
extensions:
|
17
|
+
- ext/wit/extconf.rb
|
116
18
|
extra_rdoc_files: []
|
117
19
|
files:
|
118
|
-
- .
|
119
|
-
- .
|
120
|
-
|
121
|
-
- CHANGES.md
|
122
|
-
- Gemfile
|
123
|
-
- LICENSE.txt
|
124
|
-
- README.md
|
125
|
-
- Rakefile
|
126
|
-
- lib/wit.rb
|
127
|
-
- lib/wit/client.rb
|
128
|
-
- lib/wit/version.rb
|
129
|
-
- spec/spec_helper.rb
|
130
|
-
- spec/wit/version_spec.rb
|
131
|
-
- wit.gemspec
|
132
|
-
homepage:
|
20
|
+
- ext/wit/extconf.rb
|
21
|
+
- ext/wit/wit.c
|
22
|
+
homepage: http://wit.ai
|
133
23
|
licenses:
|
134
|
-
-
|
24
|
+
- EPL-1.0
|
135
25
|
metadata: {}
|
136
26
|
post_install_message:
|
137
27
|
rdoc_options: []
|
@@ -139,21 +29,18 @@ require_paths:
|
|
139
29
|
- lib
|
140
30
|
required_ruby_version: !ruby/object:Gem::Requirement
|
141
31
|
requirements:
|
142
|
-
- -
|
32
|
+
- - ">="
|
143
33
|
- !ruby/object:Gem::Version
|
144
34
|
version: '0'
|
145
35
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
36
|
requirements:
|
147
|
-
- -
|
37
|
+
- - ">="
|
148
38
|
- !ruby/object:Gem::Version
|
149
39
|
version: '0'
|
150
40
|
requirements: []
|
151
41
|
rubyforge_project:
|
152
|
-
rubygems_version: 2.
|
42
|
+
rubygems_version: 2.4.2
|
153
43
|
signing_key:
|
154
44
|
specification_version: 4
|
155
|
-
summary:
|
156
|
-
test_files:
|
157
|
-
- spec/spec_helper.rb
|
158
|
-
- spec/wit/version_spec.rb
|
159
|
-
has_rdoc:
|
45
|
+
summary: Ruby SDK for Wit
|
46
|
+
test_files: []
|
data/.gitignore
DELETED
data/.rspec
DELETED
data/.yardopts
DELETED
data/CHANGES.md
DELETED
data/Gemfile
DELETED
data/LICENSE.txt
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
Copyright (c) 2013 Justin Workman
|
2
|
-
|
3
|
-
MIT License
|
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
DELETED
@@ -1,75 +0,0 @@
|
|
1
|
-
Wit Ruby Gem
|
2
|
-
============
|
3
|
-
|
4
|
-
This is an unnoficial Ruby wrapper for the [Wit HTTP API][1]. Wit turns natural
|
5
|
-
language into structured data, this gem lets you use the Wit API from your Ruby
|
6
|
-
app, provided you have a developer's access token.
|
7
|
-
|
8
|
-
## Installation
|
9
|
-
|
10
|
-
Add this line to your application's Gemfile:
|
11
|
-
|
12
|
-
``` ruby
|
13
|
-
gem 'wit'
|
14
|
-
```
|
15
|
-
|
16
|
-
And then execute:
|
17
|
-
|
18
|
-
``` shell
|
19
|
-
$ bundle
|
20
|
-
```
|
21
|
-
|
22
|
-
Or install it yourself as:
|
23
|
-
|
24
|
-
``` shell
|
25
|
-
$ gem install wit
|
26
|
-
```
|
27
|
-
|
28
|
-
## Usage
|
29
|
-
|
30
|
-
At time of writing, the only API method is `message`.
|
31
|
-
|
32
|
-
``` ruby
|
33
|
-
require 'wit'
|
34
|
-
|
35
|
-
wit = Wit::Client.new '<Your API Key>'
|
36
|
-
puts wit.message("I need a bud right now")
|
37
|
-
```
|
38
|
-
|
39
|
-
A JSON Hash will be returned, like so:
|
40
|
-
|
41
|
-
``` json
|
42
|
-
{
|
43
|
-
"msg_id": "d953bd6c-c620-4dae-a3fc-7634b4330073",
|
44
|
-
"msg_body": "i need a bud right now!",
|
45
|
-
"outcome": {
|
46
|
-
"intent": "grab_me_something",
|
47
|
-
"entities": {
|
48
|
-
"object_to_grab": {
|
49
|
-
"value": "beer",
|
50
|
-
"start": 9,
|
51
|
-
"end": 12,
|
52
|
-
"body": "bud"
|
53
|
-
}
|
54
|
-
},
|
55
|
-
"confidence": 0.6310633902098893
|
56
|
-
}
|
57
|
-
}
|
58
|
-
```
|
59
|
-
|
60
|
-
## Contributing
|
61
|
-
|
62
|
-
1. Fork it
|
63
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
64
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
65
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
66
|
-
5. Create new Pull Request
|
67
|
-
|
68
|
-
## License
|
69
|
-
|
70
|
-
Copyright © 2013 [Justin Workman](mailto:xtagon@gmail.com)
|
71
|
-
|
72
|
-
MIT License, see LICENSE.txt
|
73
|
-
|
74
|
-
|
75
|
-
[1]: https://wit.ai/docs/api
|
data/Rakefile
DELETED
data/lib/wit.rb
DELETED
data/lib/wit/client.rb
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
module Wit
|
2
|
-
# Represents a connection to the Wit HTTP API
|
3
|
-
class Client
|
4
|
-
require 'multi_json'
|
5
|
-
require 'rest_client'
|
6
|
-
|
7
|
-
# The Wit API's base URL
|
8
|
-
API_ENDPOINT = 'https://api.wit.ai'
|
9
|
-
|
10
|
-
# @param [String] access_token Your unique Wit developer's access token
|
11
|
-
# @param [String] expected_version The Wit API version you wish to use ("YYYYMMDD").
|
12
|
-
# Not passing this version parameter will use the newest version of the API.
|
13
|
-
def initialize(access_token, expected_version = nil)
|
14
|
-
unless expected_version.nil? || expected_version =~ /\d/
|
15
|
-
raise ArgumentError "expected_version must be nil or 'YYYYMMDD' date format"
|
16
|
-
end
|
17
|
-
|
18
|
-
@access_token = access_token
|
19
|
-
@expected_version = expected_version
|
20
|
-
end
|
21
|
-
|
22
|
-
# @note See the official Wit API documentation for details on what these parameters mean.
|
23
|
-
#
|
24
|
-
# @param [String] q User's query
|
25
|
-
# @param [String] context JSON representation of the user's context
|
26
|
-
# @param [String] meta JSON representation of any information you want to
|
27
|
-
# attach to this request through its life cycle in Wit.
|
28
|
-
#
|
29
|
-
# @return [Hash] The API's JSON response as a Hash
|
30
|
-
def message(q, context = nil, meta = nil)
|
31
|
-
params = {q: q, context: context, meta: meta}
|
32
|
-
headers = default_headers.merge(params: params)
|
33
|
-
response = api['message'].get(headers)
|
34
|
-
MultiJson.load(response)
|
35
|
-
end
|
36
|
-
|
37
|
-
private
|
38
|
-
|
39
|
-
def default_headers
|
40
|
-
unless @default_headers
|
41
|
-
@default_headers = {Authorization: "Bearer #{@access_token}"}
|
42
|
-
unless @expected_version.nil?
|
43
|
-
@default_headers.merge!(Accept: "application/vnd.wit.#{@expected_version}")
|
44
|
-
end
|
45
|
-
end
|
46
|
-
@default_headers
|
47
|
-
end
|
48
|
-
|
49
|
-
def api
|
50
|
-
@api ||= RestClient::Resource.new API_ENDPOINT
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
data/lib/wit/version.rb
DELETED
data/spec/spec_helper.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'wit'
|
2
|
-
|
3
|
-
RSpec.configure do |config|
|
4
|
-
config.treat_symbols_as_metadata_keys_with_true_values = true
|
5
|
-
config.run_all_when_everything_filtered = true
|
6
|
-
config.filter_run :focus
|
7
|
-
|
8
|
-
# Run specs in random order to surface order dependencies. If you find an
|
9
|
-
# order dependency and want to debug it, you can fix the order by providing
|
10
|
-
# the seed, which is printed after each run.
|
11
|
-
# --seed 1234
|
12
|
-
config.order = 'random'
|
13
|
-
end
|
data/spec/wit/version_spec.rb
DELETED
data/wit.gemspec
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
lib = File.expand_path('../lib', __FILE__)
|
2
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
-
require 'wit/version'
|
4
|
-
|
5
|
-
Gem::Specification.new do |spec|
|
6
|
-
spec.name = 'wit'
|
7
|
-
spec.version = Wit::VERSION
|
8
|
-
spec.authors = ['Justin Workman']
|
9
|
-
spec.email = ['xtagon@gmail.com']
|
10
|
-
spec.summary = 'A Ruby wrapper for the Wit HTTP API.'
|
11
|
-
spec.description = 'A Ruby wrapper for the Wit HTTP API, a natural language processing interface.'
|
12
|
-
spec.license = 'MIT'
|
13
|
-
|
14
|
-
spec.files = `git ls-files`.split($/)
|
15
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
|
-
spec.require_paths = ["lib"]
|
18
|
-
|
19
|
-
spec.add_runtime_dependency 'multi_json', '~> 1.8.2'
|
20
|
-
spec.add_runtime_dependency 'rest-client', '~> 1.6.7'
|
21
|
-
|
22
|
-
spec.add_development_dependency 'bundler', '~> 1.3'
|
23
|
-
spec.add_development_dependency 'rake'
|
24
|
-
spec.add_development_dependency 'redcarpet'
|
25
|
-
spec.add_development_dependency 'rspec', '~> 2.14.1'
|
26
|
-
spec.add_development_dependency 'yard'
|
27
|
-
end
|