wit_bot 0.1.0 → 0.1.1

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: 860c744638b8b4e301e8c388d038d32f8e7cd8fc
4
- data.tar.gz: 4d6c170e3506b97235a9184e7e70a420aae94926
3
+ metadata.gz: 931f58cf60b1216e89ca8cbc037a8d7d1f9bacc6
4
+ data.tar.gz: 50f63f7128bb94520d7482ebebe0115641af1712
5
5
  SHA512:
6
- metadata.gz: 3edd3cd3d85269c77a4035fe9c095435b7ace28508231379207868aadc218ca4b69d9a0f2a18415afb788aef6ec062e30f844230b515a54f18f5a80de6a5c41c
7
- data.tar.gz: be861fdb6a7761e56fc20cd5ae71fc037807d5b305c6f21732c375fc420dcab6a1a6691022bac3fe5888d29aa8d471f371b9d3c0d013d619ce6ed29455f056d5
6
+ metadata.gz: 000a54affd75c669637c93f5e75b00c3729ddeda2162108003ac7893877e64556964cdfde0432ee2dada908436fa0559aa454afdcbd5131a34fbbb217b6c781d
7
+ data.tar.gz: 5f95529a175d8f27c0c2281c703ece179a21f0231da6efe1033a7700e92e13da38b3e548e488752a0d7ddd9f9f03fccf1207ad8b413966729bfc1aa13e40a2f4
@@ -2,12 +2,15 @@
2
2
 
3
3
  require_relative '../lib/wit_bot'
4
4
 
5
+ include WitBot
6
+
5
7
  WitBot.configure do |c|
6
8
  c.token = ENV['WIT_ACCESS_TOKEN'] # Create a wit bot and set the token here
7
9
  end
8
10
 
9
11
  def reload!
10
12
  WitBot.load
13
+ include WitBot
11
14
  end
12
15
 
13
16
  require "irb"
@@ -7,11 +7,14 @@ module WitBot
7
7
 
8
8
  def initialize(state)
9
9
  @state = state
10
- @@states[state] = self
11
10
  end
12
11
 
13
12
  def self.find(state)
14
- @@states[state] || State.new(state)
13
+ @@states[state] ||= State.new(state)
14
+ end
15
+
16
+ def self.all
17
+ @@states.values
15
18
  end
16
19
 
17
20
  alias :to_s :state
@@ -18,7 +18,11 @@ module WitBot
18
18
 
19
19
  class << self
20
20
  def all
21
- @all ||= REQUEST.new.get.map{|data| from_response_data data}
21
+ @all ||= request.get(all: true).map do |data|
22
+ model = self.new data[:id]
23
+ model.from_response_data data
24
+ model
25
+ end
22
26
  end
23
27
 
24
28
  def get(model: nil)
@@ -35,6 +35,10 @@ module WitBot
35
35
  def request
36
36
  EntitiesRequest.new(model: self)
37
37
  end
38
+
39
+ def self.request
40
+ EntitiesRequest.new
41
+ end
38
42
  end
39
43
  end
40
44
  end
@@ -43,6 +43,10 @@ module WitBot
43
43
  def request
44
44
  IntentsRequest.new(model: self)
45
45
  end
46
+
47
+ def self.request
48
+ IntentsRequest.new
49
+ end
46
50
  end
47
51
  end
48
52
  end
@@ -12,7 +12,7 @@ module WitBot
12
12
  @model = model
13
13
  end
14
14
 
15
- def get(all: true)
15
+ def get(all: false)
16
16
  path = all ? model_path : individual_model_path
17
17
  request http.get path
18
18
  end
@@ -6,11 +6,22 @@ module WitBot
6
6
 
7
7
  def request(request=http)
8
8
  if request.code.between? 200, 299
9
- request.parse.with_indifferent_access
9
+ process_response request.parse
10
10
  else
11
11
  response = request.parse.with_indifferent_access
12
12
  raise WitError.new(response[:status]), (response[:error] || response[:body])
13
13
  end
14
14
  end
15
+
16
+ private
17
+ def process_response(response)
18
+ if response.respond_to? :with_indifferent_access
19
+ response.with_indifferent_access
20
+ elsif response.respond_to? :map
21
+ response.map {|r| process_response r}
22
+ else
23
+ response
24
+ end
25
+ end
15
26
  end
16
27
  end
@@ -1,3 +1,3 @@
1
1
  module WitBot
2
- VERSION = "0.1.0"
2
+ VERSION = '0.1.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wit_bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben (@penne12_)