wit_ruby 0.0.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1640efe7f4c172e77b20dfd68abb9cd32aad90fc
4
- data.tar.gz: cd459ecaa05c9169b7c86287137effa7efc9381c
3
+ metadata.gz: 5534ada2f3ea5d5ebcfdb9b9b99490593d72ea3b
4
+ data.tar.gz: cf4ad6b74d4c9b4b5a4b2ba2cf993c3474f377de
5
5
  SHA512:
6
- metadata.gz: b48276ba61d3b267bf6596a46d2af8b2a3935155f12ad87898c21b7d7a08546cf0cac7a3849758d9cb54c7be7a7b0fdc39668678fd85442d59677f44b7fe2dea
7
- data.tar.gz: 2c418a23e162702fae0a3b7c73e4508760852975124cf30d2a639e7ca0dd2c3def1b252bf252ea12aa74b1ddddfa45419694be1fc9544ed5356ca265b5e13b95
6
+ metadata.gz: 3f0c8772cfd22460b81bc6434361f9b3d750472d72d45878083f78a360660611957075d6c2ffcd257f6b7948fb28fba69278edb9cbb006f34505a0e2ed66b2fb
7
+ data.tar.gz: ce28e95eb5caa6ce91017ae0e22a632a061f025aec8e8cc4575ec982b67b19458ec69749436a478b32ab128ab22c7ebccb662498c6d864733fe09dfd465c924f
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ == 1.0.0
2
+ * Yay! 1.0.0 for no reason! (Kinda.)
3
+ * Added error checking to make sure input parameters to the session are correct.
4
+ * Changed adding expression to not use the given BodyJson and instead, requires the use of just the name of the entity, value, and new expression.
5
+
1
6
  == 0.0.3
2
7
  * Implemented getting array of entities from instance (GET).
3
8
  * Implemented getting a specific entity from its name/id (GET).
data/README.md CHANGED
@@ -1,16 +1,21 @@
1
-
2
-
3
1
  # WitRuby
4
2
 
5
- Provides a unofficial and (seemingly) pleasant Ruby API Wrapper for the Wit.ai API. As of 0.0.3, most functionalities have been implemented. Go over to https://rubygems.org/gems/wit_ruby for more information.
3
+ [![Build Status](https://travis-ci.org/gching/wit_ruby.svg?branch=master)](https://travis-ci.org/gching/wit_ruby)
4
+ [![Gem Version](https://badge.fury.io/rb/wit_ruby.png)](http://badge.fury.io/rb/wit_ruby)
5
+ [![Coverage Status](https://coveralls.io/repos/gching/wit_ruby/badge.png?branch=master)](https://coveralls.io/r/gching/wit_ruby?branch=master)
6
+
7
+ Provides a unofficial and (seemingly) pleasant Ruby API Wrapper for the Wit.ai API. As of 1.0.0, most functionalities have been implemented. Go over to https://rubygems.org/gems/wit_ruby for more information.
6
8
 
7
9
  Documentation that you will definitely need : http://rubydoc.info/gems/wit_ruby/
8
10
 
9
11
  Do also reference the Wit.ai API documentation : https://wit.ai/docs/api
10
12
 
11
- [![Build Status](https://travis-ci.org/gching/wit_ruby.svg?branch=master)](https://travis-ci.org/gching/wit_ruby)
12
- [![Gem Version](https://badge.fury.io/rb/wit_ruby.png)](http://badge.fury.io/rb/wit_ruby)
13
- [![Coverage Status](https://coveralls.io/repos/gching/wit_ruby/badge.png?branch=master)](https://coveralls.io/r/gching/wit_ruby?branch=master)
13
+ There are other gems that are also Ruby wrappers for Wit.ai, but this was more of learning experience for me! If you don't find this pleasing, do check the others out!
14
+
15
+ https://github.com/modeset/wit-ruby
16
+
17
+ https://github.com/xtagon/wit-gem
18
+
14
19
 
15
20
  ## Installation
16
21
 
@@ -34,12 +39,12 @@ Remember to put this up to access it!
34
39
 
35
40
  To start using the wrapper, create a client with an authorization token given from Wit.ai. Set this either in ENV["WIT_AI_TOKEN"] or pass it on it the parameters as a hash. Default settings can be overridden by this hash as well.
36
41
 
37
- ## Default to ENV["WIT_AI_TOKEN"]
42
+ Default to ENV["WIT_AI_TOKEN"]
38
43
  $ client = Wit::REST::Client.new()
39
- ## Override token when created
44
+ Override token when created
40
45
  $ client = Wit::REST::Client.new(token: "Insert Token Here")
41
46
 
42
- The client provides also a session for you to mainly do API calls. I suggest you save the session somewhere for easy access.
47
+ The client provides a session for you to mainly do API calls. I suggest you save the session somewhere for easy access.
43
48
 
44
49
  $ session = client.session
45
50
 
@@ -47,15 +52,24 @@ Please again, do look over documentation to see the full scope of usage and conf
47
52
 
48
53
  ### Result
49
54
 
50
- Every method returns a class wrapper corresponding specifically to the results pertaining to it. The superclass that is inherited (Wit::REST::Result) allows for you to easily access the results of the API call. The results is converted to a hash and is saved in this result class.
55
+ Every method returns a class wrapper corresponding specifically to the results pertaining to it. Each object returned has its own unique defined methods to make your lives easier in getting the specific information from the results. Do look over the documentation to see what you can specifically call.
56
+
57
+ The superclass that is inherited (Wit::REST::Result) allows for you to easily access the results of the API call. The results is converted to a hash and is saved in this result class.
51
58
  You can call methods on it and if it matches the result's hash, it will return it's value. For example,
52
59
 
53
- ## results.hash = {"a" => "b"}
60
+ results.hash = {"a" => "b"}
54
61
  $ results.a
55
- ## = "b"
62
+ = "b"
56
63
 
57
64
  Every direct result returned from each method call defined from the session will be refreshable.
58
65
 
66
+ Some unique methods are provided:
67
+
68
+ ```ruby
69
+ results.raw_data # The raw data from the response of the request.
70
+ results.refreshable? # Check to see current object is refreshable.
71
+ ```
72
+
59
73
  ### JSON Specific Calls
60
74
 
61
75
  Methods that require JSON for the API calls will be generated through use of the class Wit::REST::BodyJson.
@@ -63,12 +77,12 @@ BodyJson inherits from OpenStruct and will assist in providing properly formatte
63
77
 
64
78
  Depending on the data needed, certain methods are provided. For example:
65
79
 
66
- ## First instantiate.
80
+ First instantiate.
67
81
  $ new_body = Wit::REST::BodyJson.new
68
- ## Adding an ID and doc parameter
82
+ Adding an ID and doc parameter
69
83
  $ new_body.id = "Some ID"
70
84
  $ new_body.doc = "Some doc"
71
- ## Adding value and expression.
85
+ Adding value and expression.
72
86
  $ new_body.add_value("Some value", "possible expressions that--", "--that can be added to this value")
73
87
  $ new_body.add_expression("Some existing value", "possible expressions that--", "--that can be added to this value")
74
88
 
@@ -83,6 +97,15 @@ To get a specific messages information from the wit.ai, pass in the message's ID
83
97
 
84
98
  $ session.get_message("Message ID")
85
99
 
100
+ ##### Message Result Unique Methods
101
+
102
+ ```ruby
103
+ message_results = session.send_message("Your Message")
104
+ message_results.confidence # Returns the confidence of the message results.
105
+ message_results.entity_names # Generates array of names of each entity in this message.
106
+ message_results.intent # Returns the intent that this message corresponded to.
107
+ ```
108
+
86
109
  ### Intent
87
110
 
88
111
  To get a list of intents in the specific instance over at wit.ai.
@@ -93,6 +116,26 @@ To get a specific intent information, pass in it's ID or name.
93
116
 
94
117
  $ session.get_intents("Intent ID or Name")
95
118
 
119
+ ##### Intent Result Unique Methods
120
+
121
+ If it is a list of intents:
122
+
123
+ ```ruby
124
+ multi_intent = session.get_intents
125
+ multi_intent[0] # Returns each specific index of intent
126
+ multi_intent.each {} # Provides access to each individual intent
127
+ ```
128
+
129
+ If it is only one specific intent:
130
+
131
+ ```ruby
132
+ intent = session.get_intents("Intent ID or Name")
133
+ intent.entities_used # Return entities used with there id as an array of strings.
134
+ intent.entities # Returns array of entities.
135
+ intent.expression_bodies # Return the expression bodies as an array of strings.
136
+ intent.expressions # Return the list of expressions as array of expression objects.
137
+ ```
138
+
96
139
  ### Entities
97
140
 
98
141
  To get a list of entities for this instance.
@@ -105,16 +148,27 @@ To get a specific entity, pass it in's ID
105
148
 
106
149
  To create and update entities, methods require a Wit::REST::BodyJson object with an id defined and optional doc, values and expressions defined.
107
150
 
108
- ## New entity
151
+ New entity
109
152
  $ new_entity = Wit::REST::BodyJson.new(id: "some id")
110
153
  $ session.create_entity(new_entity)
111
- ## Update it with a new doc parameter
154
+ Update it with a new doc parameter
112
155
  $ new_entity.doc = "some doc"
113
156
 
114
157
  Deleting the entity requires the passing of it's ID
115
158
 
116
159
  $ session.delete_entity("some entity id")
117
160
 
161
+ ##### Entities Result Unique Methods
162
+
163
+ For a list of entities:
164
+
165
+ ```ruby
166
+ entities = session.get_entities
167
+ entities[0] # Index to access each string for the entity name.
168
+ entities.each {} # Go through each entity string.
169
+ ```
170
+
171
+ For a specific entity, no unique methods are given.
118
172
 
119
173
  ### Values
120
174
 
@@ -138,6 +192,8 @@ Same goes for the deletion of an expression.
138
192
 
139
193
  $ session.delete_expression("some entity id", "some value name", "to be deleted expression")
140
194
 
195
+
196
+
141
197
  ## Contributing
142
198
 
143
199
  I am a beginner developer so do contribute or help as much as possible! I definitely need to learn a lot :). Whoever helps will also have there name put here below this line. Amazing!
@@ -12,3 +12,8 @@ require "wit_ruby/rest/intent"
12
12
  require "wit_ruby/rest/entity"
13
13
  require "wit_ruby/rest/expression"
14
14
  require "wit_ruby/rest/bodyjson"
15
+
16
+
17
+ ## Module that contains everything necessary for this amazing wrapper!
18
+ module Wit
19
+ end
@@ -1,6 +1,6 @@
1
1
  ## bodyjson.rb
2
2
  ## Wrapper for JSON data that will be sent over to API
3
- ## TODO - better seraching for specific hash
3
+ ## @todo better seraching for specific hash
4
4
 
5
5
  module Wit
6
6
  module REST
@@ -27,17 +27,18 @@ module Wit
27
27
  super(new_hash_to_os)
28
28
  end
29
29
 
30
- ## TODO - include metadata
30
+
31
31
  ## Used to add value for an entity
32
32
  ##
33
33
  ## @param value [String] a possible value
34
34
  ## @param args [Array] posible expressions for the given value
35
35
  ## @return [Wit::REST::BodyJson] the current BodyJson with new value.
36
+ ## @todo include metadata
36
37
  def add_value(value, *args)
37
38
  ## Check to see if the value already exists
38
39
  @values.each do |value_hash|
39
40
  if value_hash["value"] == value
40
- raise ValueAlreadyExists.new(%(The current value being inserted, "#{value}", already exists.))
41
+ raise ValueAlreadyExists.new("The current value being inserted, \"#{value}\", already exists.")
41
42
  end
42
43
  end
43
44
  ## Adds it if it isn't there with the given expressions
@@ -60,7 +61,7 @@ module Wit
60
61
  ## Set union for arrays, removes duplicates
61
62
  value_hash["expressions"] = value_hash["expressions"] | args
62
63
  else ## Not found and raise error
63
- raise NotFound.new(%(The value, "#{value}", cannot be found.))
64
+ raise NotFound.new("The value, \"#{value}\", cannot be found.")
64
65
  end
65
66
  end
66
67
 
@@ -32,7 +32,7 @@ module Wit
32
32
 
33
33
  # Allows for the reading of the last request, last response, and the
34
34
  # current session.
35
- attr_reader :last_req, :last_response, :session, :last_result
35
+ attr_reader :last_request, :last_response, :session, :last_result
36
36
 
37
37
  ## Initialize the new instance with either the default parameters or given parameters.
38
38
  ## Token can either be given in options or defaults to ENV["WIT_AI_TOKEN"]
@@ -133,7 +133,7 @@ module Wit
133
133
  ## @return [Wit::REST::Result] result from request.
134
134
  def connect_send(request)
135
135
  ## Set the last request parameter
136
- @last_req = request
136
+ @last_request = request
137
137
  ## Set the retries if necessary to send again.
138
138
  left_retries = @params[:retry_limit]
139
139
  ## Start sending request
@@ -10,11 +10,11 @@ module Wit
10
10
  end
11
11
 
12
12
  ## Internal wrapper for multiple entities for a given result.
13
- class MultiEntity
13
+ class EntityArray
14
14
  ## Creates an instance that holds array of intents.
15
15
  ##
16
- ## @param resultData [Array] array of hashes of intents.
17
- ## @return [Wit::REST::MultiEntity] with instance variable of Array of intents.
16
+ ## @param resultData [Array] array of hashes of entity values.
17
+ ## @return [Wit::REST::MultiEntity] with instance variable of Array of each entity value.
18
18
  def initialize(resultData)
19
19
 
20
20
  entity_arr = Array.new
@@ -35,8 +35,8 @@ module Wit
35
35
 
36
36
  ## Wrapper for array of entities as strings. Inherits from Results so it can
37
37
  ## be refreshed.
38
- ## TODO - Propagate these methods into Result
39
- class EntityArray < Result
38
+ ## @todo Propagate these methods into Result
39
+ class MultiEntity < Result
40
40
 
41
41
  ## Generates instance variable that holds list of entities as strings in array.
42
42
  ##
@@ -42,7 +42,7 @@ module Wit
42
42
  def method_missing(possible_key, *args, &block)
43
43
  if @rawdata["outcome"]["entities"].has_key?(possible_key.to_s)
44
44
  entity_value = @rawdata["outcome"]["entities"][possible_key.to_s]
45
- entity_value.class == Hash ? Entity.new(entity_value) : MultiEntity.new(entity_value)
45
+ entity_value.class == Hash ? Entity.new(entity_value) : EntityArray.new(entity_value)
46
46
  else
47
47
  super
48
48
  end
@@ -88,6 +88,13 @@ module Wit
88
88
  !@requestRest.nil?
89
89
  end
90
90
 
91
+ ## Checks to see if the data in the Result object is empty (empty array or hash).
92
+ ##
93
+ ## @return [Boolean] indicating if the current object is empty.
94
+ def empty?
95
+ @rawdata.empty?
96
+ end
97
+
91
98
 
92
99
 
93
100
  private
@@ -5,6 +5,9 @@
5
5
  module Wit
6
6
  module REST
7
7
  class Session
8
+ ## Able to read cached result from last request.
9
+
10
+ attr_reader :last_result
8
11
  ## Initialize with the given client.
9
12
  ##
10
13
  ## @param client [Wit::REST::Client] client of the connection
@@ -15,6 +18,7 @@ module Wit
15
18
  ##
16
19
  ## @param message [String] sentence being examined from API.
17
20
  ## @return [Wit::REST::Message] message results from API.
21
+ ## @todo allow for JSON pass in.
18
22
  def send_message(message)
19
23
  ## Recieve unwrapped results
20
24
  results = @client.get("/message?q=#{message}")
@@ -30,11 +34,11 @@ module Wit
30
34
  end
31
35
 
32
36
  ## GET - returns stored message for specific id.
33
- ## TODO - possibly renaming as it is ambigious compared to send_message.
34
- ## TODO - Notify Wit.ai as there documentation does not include the stats parameter
35
37
  ##
36
38
  ## @param message_id [String] message id of message in API servers.
37
39
  ## @return [Wit::REST::Message] message results from the given id.
40
+ ## @todo possibly renaming as it is ambigious compared to send_message.
41
+ ## @todo Notify Wit.ai as there documentation does not include the stats parameter
38
42
  def get_message(message_id)
39
43
  results = @client.get("/messages/#{message_id}")
40
44
 
@@ -47,9 +51,7 @@ module Wit
47
51
  ## @param intent_indicator [String] the id or name of the intent
48
52
  ## @return [Wit:REST::Intent] [Wit::REST::MultiIntent] results of intent call to API.
49
53
  def get_intents(intent_indicator = nil)
50
- ## TODO - Raise error if no intents
51
-
52
- ## No spefic id, so get list of intents or specific id, return it as Intent object
54
+ ## No specific id, so get list of intents or specific id, return it as Intent object
53
55
  results = intent_indicator.nil? ? @client.get("/intents") : @client.get("/intents/#{intent_indicator}")
54
56
 
55
57
  ## Same concept but wrap it around proper object
@@ -63,16 +65,14 @@ module Wit
63
65
  ## GET - returns a list of available entities given this instance with the
64
66
  ## given token if no id is given.
65
67
  ## - returns the specific entity and its parameters with a given id.
66
- ## TODO - notify Wit.ai to fix their documentations as there is a wrong
67
- ## - description.
68
68
  ## @param entity_id [String] entity id for specific retrieval
69
- ## @return [Wit::REST::EntityArray] [Wit::REST::Entity] results and returned in either wrapper
69
+ ## @return [Wit::REST::MultiEntity] [Wit::REST::Entity] results and returned in either wrapper
70
+ ## @todo notify Wit.ai to fix their documentations as there is a wrong description.
70
71
  def get_entities(entity_id = nil)
71
72
  ## No specific id, so get list of entities
72
73
  results = entity_id.nil? ? @client.get("/entities") : @client.get("/entities/#{entity_id}")
73
-
74
74
  ## Same concept but wrap it properly if neccessary.
75
- returnObject = entity_id.nil? ? EntityArray : Entity
75
+ returnObject = entity_id.nil? ? MultiEntity : Entity
76
76
 
77
77
  return return_with_class(returnObject, results)
78
78
 
@@ -83,18 +83,21 @@ module Wit
83
83
  ## @param new_entity [Wit::REST::BodyJson] object with data to be sent over to API.
84
84
  ## @return [Wit::REST::Result] results of the posting of the new entity.
85
85
  def create_entity(new_entity)
86
+
87
+ ## Checks to make sure it has an id, if not, raise error.
86
88
  if new_entity.id.nil?
87
89
  raise NotCorrectSchema.new("The current BodyJson object passed in does not have an \"id\" defined.")
88
90
  end
89
91
  return @client.post("/entities", new_entity.json)
90
92
  end
91
93
 
92
- ## TODO - notify Wit.ai to return back the updated entity results.
94
+
93
95
  ## PUT - updates a given entity with the specific entity id and BodyJson data.
94
96
  ##
95
97
  ## @param entity_id [String] entity id that will be updated.
96
98
  ## @param update_entity_data [Wit::REST::BodyJson] new data that will update the entity.
97
99
  ## @return [Wit::REST::Result] results of updating the entity
100
+ ## @todo notify Wit.ai to return back the updated entity results.
98
101
  def update_entity(entity_id, update_entity_data)
99
102
  return @client.put("/entities/#{entity_id}", update_entity_data.json)
100
103
  end
@@ -109,12 +112,15 @@ module Wit
109
112
 
110
113
  ## POST - adds the possible value into the list of values for the given
111
114
  ## - entity with the id.
112
- ## TODO - restrict to only one value in BodyJson
113
- ## TODO - notify wit.ai that documentation is off.
114
115
  ##
115
116
  ## @param new_value_with_entity [Wit::REST::BodyJson] includes the new value and entity name as ID.
116
117
  ## @return [Wit::REST::Result] the results of the addition of the value
118
+ ## @todo notify wit.ai that documentation is off.
117
119
  def add_value(new_value_with_entity)
120
+ ## Makes sure values exist and has a value and id as well.
121
+ if new_value_with_entity.id.nil? || new_value_with_entity.one_value_to_json == "null"
122
+ raise NotCorrectSchema.new("The current BodyJson object passed in does not have either an \"id\" or a \"value\" defined.")
123
+ end
118
124
  return @client.post("/entities/#{new_value_with_entity.id}/values", new_value_with_entity.one_value_to_json)
119
125
  end
120
126
 
@@ -131,12 +137,8 @@ module Wit
131
137
  ##
132
138
  ## @param new_expression_with_id_and_value [Wit::REST::BodyJson] includes new expression for said ID and value.
133
139
  ## @return [Wit::REST::Result] results of the addition of the expression
134
- def add_expression(new_expression_with_id_and_value)
135
- ## Rename it for better reading
136
- new_express = new_expression_with_id_and_value
137
- ## Get the value that will had the expression inserted
138
- value = new_express.values[0]["value"]
139
- return @client.post("/entities/#{new_express.id}/values/#{value}/expressions", new_express.one_expression_to_json(value))
140
+ def add_expression(entity_id, value, expression)
141
+ return @client.post("/entities/#{entity_id}/values/#{value}/expressions", "{\"expression\":\"#{expression}\"}")
140
142
  end
141
143
 
142
144
  ## DELETE - deletes the expression in the value of the entity.
@@ -167,22 +169,23 @@ module Wit
167
169
  return return_with_class(result_class, refreshed_result)
168
170
  end
169
171
 
170
- ## Used to refresh the last response given from the last request.
171
- ## TODO - fix wrapper
172
+ ## Used to refresh the last result given from the last request.
172
173
  ##
173
174
  ## @return [Wit::REST::Result] refreshed result from last result
174
175
  def refresh_last
175
- last_result = @client.last_result
176
- return @client.request_from_result(last_result.restCode, last_result.restPath, last_result.restBody)
176
+ refreshed_last_result = @client.request_from_result(@last_result.restCode, @last_result.restPath, @last_result.restBody)
177
+ return_with_class(@last_result.class, refreshed_last_result)
177
178
  end
178
179
 
179
180
  private
180
- ## Used to return using the given return class and results.
181
+ ## Used to return using the given return class and results. Also saves the last result.
181
182
  ##
182
183
  ## @param return_class return class for the specific method.
183
184
  ## @param results [Wit::REST::Result] holding the specific results from client.
184
185
  def return_with_class(return_class, results)
185
- return return_class.new(results.raw_data, results.restCode, results.restPath, results.restBody)
186
+ ## Save it in instance parameter @last_result for easy access.
187
+ @last_result = return_class.new(results.raw_data, results.restCode, results.restPath, results.restBody)
188
+ return @last_result
186
189
  end
187
190
 
188
191
  end
@@ -190,9 +193,13 @@ module Wit
190
193
  ## Raised when the given result object cannot be refreshed.
191
194
  ##
192
195
  class NotRefreshable < Exception; end
193
-
196
+
194
197
  ## Raised when the given result object does not have required parameters.
195
198
  ##
196
199
  class NotCorrectSchema < Exception; end
200
+
201
+ ## Raised when the returned result object is empty.
202
+ class IsEmpty < Exception; end
203
+
197
204
  end
198
205
  end
@@ -1,3 +1,3 @@
1
1
  module Wit
2
- VERSION = "0.0.3"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -21,7 +21,7 @@ describe Wit::REST::Entity do
21
21
 
22
22
  end
23
23
 
24
- describe Wit::REST::MultiEntity do
24
+ describe Wit::REST::EntityArray do
25
25
  let(:json_two) {%([
26
26
  {
27
27
  "value": {
@@ -38,7 +38,7 @@ describe Wit::REST::MultiEntity do
38
38
  "body": "Friday"
39
39
  }
40
40
  ])}
41
- let(:entity_coll) {Wit::REST::MultiEntity.new(MultiJson.load(json_two))}
41
+ let(:entity_coll) {Wit::REST::EntityArray.new(MultiJson.load(json_two))}
42
42
 
43
43
 
44
44
  it "should be an array with entities" do
@@ -48,7 +48,7 @@ describe Wit::REST::MultiEntity do
48
48
 
49
49
  end
50
50
 
51
- describe Wit::REST::EntityArray do
51
+ describe Wit::REST::MultiEntity do
52
52
  let(:json_three) {%([
53
53
  "wit$amount_of_money",
54
54
  "wit$contact",
@@ -57,7 +57,7 @@ describe Wit::REST::EntityArray do
57
57
  "wit$phrase_to_translate",
58
58
  "wit$temperature"
59
59
  ])}
60
- let(:entity_array) {Wit::REST::EntityArray.new(MultiJson.load(json_three))}
60
+ let(:entity_array) {Wit::REST::MultiEntity.new(MultiJson.load(json_three))}
61
61
 
62
62
 
63
63
  it "should be each transversable and be strings" do
@@ -46,7 +46,7 @@ describe Wit::REST::Message do
46
46
  expect(message_results.confidence).to eql(0.979)
47
47
  expect(message_results.intent).to eql("query_metrics")
48
48
  expect(message_results.metric.class).to eql(Wit::REST::Entity)
49
- expect(message_results.datetime.class).to eql(Wit::REST::MultiEntity)
49
+ expect(message_results.datetime.class).to eql(Wit::REST::EntityArray)
50
50
  end
51
51
 
52
52
  it "should have the right values in the entities" do
@@ -9,6 +9,8 @@ describe Wit::REST::Result do
9
9
  let(:rest_code) {"post"}
10
10
  let(:result) {Wit::REST::Result.new(randHash, rest_code, rand_path, rand_body)}
11
11
  let(:not_refresh_result) {Wit::REST::Result.new(randHash)}
12
+ let(:empty_hash) {Wit::REST::Result.new({})}
13
+ let(:empty_array) {Wit::REST::Result.new([])}
12
14
 
13
15
  it "should have an instance of the original hash" do
14
16
  expect(result.raw_data).to eql(randHash)
@@ -40,4 +42,10 @@ describe Wit::REST::Result do
40
42
  expect(not_refresh_result.refreshable?).to be_false
41
43
  end
42
44
 
45
+ it "should have an empty method to check if the data is empty and return true if it is" do
46
+ expect(result.empty?).to be_false
47
+ expect(empty_hash.empty?).to be_true
48
+ expect(empty_array.empty?).to be_true
49
+ end
50
+
43
51
  end
@@ -199,7 +199,7 @@ describe Wit::REST::Session do
199
199
  describe "get list of entities" do
200
200
 
201
201
  it "should return an array of used entities as strings" do
202
- expect(get_entities.class).to eql(Wit::REST::EntityArray)
202
+ expect(get_entities.class).to eql(Wit::REST::MultiEntity)
203
203
  expect(get_entities[0].class).to eql(String)
204
204
  end
205
205
 
@@ -210,7 +210,7 @@ describe Wit::REST::Session do
210
210
 
211
211
  it "should return an entity class with same id" do
212
212
  expect(get_entity.class).to eql(Wit::REST::Entity)
213
- ## TODO - tell WIT.AI there documentation is wrong as they have name and id switched.
213
+ ## @todo tell WIT.AI there documentation is wrong as they have name and id switched.
214
214
  expect(get_entity.name).to eql(get_entities[0].split("$")[1])
215
215
  end
216
216
 
@@ -308,6 +308,8 @@ describe Wit::REST::Session do
308
308
  @body_with_id_and_value = @body_for_value_insert.add_value(@resulting_value_name)
309
309
  @resulting_add_value = session.add_value(@body_with_id_and_value)
310
310
  @resulting_delete_value = session.delete_value(@resulting_entity_name, @resulting_value_name)
311
+ @no_id = Wit::REST::BodyJson.new.add_value(@resulting_value_name)
312
+ @no_value = Wit::REST::BodyJson.new(id: @resulting_entity_name)
311
313
  end
312
314
  after :each do
313
315
  session.delete_entity(@resulting_entity_name)
@@ -321,6 +323,11 @@ describe Wit::REST::Session do
321
323
  it "should have the new value inserted" do
322
324
  expect(@resulting_add_value.values[0]["value"]).to eql(@resulting_value_name)
323
325
  end
326
+
327
+ it "should raise an error for an incorrect BodyJson with no id or value " do
328
+ expect{session.add_value(@no_id)}.to raise_error(Wit::REST::NotCorrectSchema)
329
+ expect{session.add_value(@no_value)}.to raise_error(Wit::REST::NotCorrectSchema)
330
+ end
324
331
  end
325
332
 
326
333
  describe "deletion" do
@@ -340,9 +347,9 @@ describe Wit::REST::Session do
340
347
  VCR.insert_cassette 'add_delete_expression', record: :new_episodes
341
348
  entity_creation = session.create_entity(entity_body)
342
349
  @entity_value_expression_name = entity_creation.name
343
- session.add_value(Wit::REST::BodyJson.new(id: @entity_value_expression_name).add_value(@entity_value_expression_name))
344
- @expression_creation = session.add_expression(Wit::REST::BodyJson.new(id: @entity_value_expression_name).add_value(@entity_value_expression_name).add_expression(@entity_value_expression_name, @entity_value_expression_name))
350
+ @expression_creation = session.add_expression(@entity_value_expression_name, @entity_value_expression_name, @entity_value_expression_name)
345
351
  @expression_deletion = session.delete_expression(@entity_value_expression_name, @entity_value_expression_name, @entity_value_expression_name)
352
+
346
353
  end
347
354
  after :each do
348
355
  session.delete_value(@entity_value_expression_name, @entity_value_expression_name)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wit_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin Ching
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-22 00:00:00.000000000 Z
11
+ date: 2014-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json