wit 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a6ac091647ac82d9f4f086d6daaed555c0af3686
4
+ data.tar.gz: c74219501fe69d424acbea861836c73bab6b960c
5
+ SHA512:
6
+ metadata.gz: 6cf30a3a98cae7ab9b2c0f3ca281b2dc057eb95d8e9eb386fcd08b5d345b9002222b733cb69241a09e105fa3640a8f22796436453e3e75ec965145aa54f47c66
7
+ data.tar.gz: 52eb5fd930b44c1e51d8883af5107299938a8091c6e7ed539fff0e2a310b3d49dc5902c476a16debe4fd19888807d4d0c5589e14aa8dd49a5506263de2e1167f
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.yardopts ADDED
@@ -0,0 +1,4 @@
1
+ -
2
+ CHANGES.md
3
+ LICENSE.txt
4
+ README.md
data/CHANGES.md ADDED
@@ -0,0 +1,6 @@
1
+ Wit Gem Changes
2
+ ===============
3
+
4
+ ## v0.0.1 - *2013-10-14*
5
+
6
+ - First version, implementing the one API method: `message`.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
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 ADDED
@@ -0,0 +1,75 @@
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 ADDED
@@ -0,0 +1,8 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'yard'
4
+
5
+ RSpec::Core::RakeTask.new :spec
6
+ YARD::Rake::YardocTask.new :doc
7
+
8
+ task default: :spec
data/lib/wit/client.rb ADDED
@@ -0,0 +1,53 @@
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
@@ -0,0 +1,4 @@
1
+ module Wit
2
+ # The version of the currently loaded Wit gem
3
+ VERSION = '0.0.1'
4
+ end
data/lib/wit.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'wit/version'
2
+ require 'wit/client'
@@ -0,0 +1,13 @@
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
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe Wit::VERSION do
4
+ it('is a valid version string') { should =~ /\A\d+\.\d+\.\d+(-\w+)?\Z/ }
5
+ end
data/wit.gemspec ADDED
@@ -0,0 +1,27 @@
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
metadata ADDED
@@ -0,0 +1,159 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Justin Workman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: multi_json
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
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .gitignore
119
+ - .rspec
120
+ - .yardopts
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:
133
+ licenses:
134
+ - MIT
135
+ metadata: {}
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - '>='
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubyforge_project:
152
+ rubygems_version: 2.0.3
153
+ signing_key:
154
+ specification_version: 4
155
+ summary: A Ruby wrapper for the Wit HTTP API.
156
+ test_files:
157
+ - spec/spec_helper.rb
158
+ - spec/wit/version_spec.rb
159
+ has_rdoc: