artemis-bot 0.1.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: bb1208c38d363ca50f1c465b2c0d4832754a9a2a
4
+ data.tar.gz: ce481daf17385fb47ce30ec6727cbcba52370957
5
+ SHA512:
6
+ metadata.gz: 84f14e00bf96b6b54053ac15daa7eff29a5781096676db257a36cf988f00e17fecabd3e4a19b7cf0bdbf64d6c4097e474d3a80a3ca97437e308467bfb93dd8d0
7
+ data.tar.gz: 2a6addd28a1f5e46b19725fa71ced025f63d220e5607b37ca7704071a0ea8d564768d394c9f0353a8d0e8854f2ee865128bc867e2eb4fd930888fa5f0dd6d05e
data/.DS_Store ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.3
5
+ before_install: gem install bundler -v 1.12.5
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at wal.reyes.11@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in artemis-bot.gemspec
4
+ gemspec
5
+ gem 'pry'
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Walter Reyes
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,67 @@
1
+ <a href="https://codeclimate.com/repos/582ddb758ec2e6008000009a/feed"><img src="https://codeclimate.com/repos/582ddb758ec2e6008000009a/badges/5b338f461679b2e41308/gpa.svg" /></a>
2
+
3
+ # Artemis
4
+
5
+ Artemis is a wrapper for the [Watson Conversation Service](http://www.ibm.com/watson/developercloud/doc/conversation/)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'artemis-bot'
13
+ ```
14
+
15
+ And run `bundle install` from your shell
16
+
17
+ To install the gem manually from your shell, run:
18
+
19
+ $ gem install artemis-bot
20
+
21
+ ## Configuration
22
+
23
+ First you need to configure Artemis with your Conversation credentials
24
+
25
+ ```
26
+ Artemis::Bot.configure do |config|
27
+ config.username = "your-username-here"
28
+ config.password = "your-password-here"
29
+ end
30
+ ```
31
+
32
+ ## Usage
33
+
34
+ To send a message:
35
+
36
+ ```
37
+ workspace_id = "your-workspace_id-here"
38
+
39
+ message_request = Artemis::Bot::MessageRequest.new
40
+ message_request.input.text = "Hello there"
41
+ message_request.alternate_intents = true
42
+
43
+ response = Artemis::Bot::Conversator.message(workspace_id, message_request)
44
+ ```
45
+
46
+ To follow up a conversation:
47
+
48
+ ```
49
+ # assign the context from the previous response
50
+ message_request.context = response.context
51
+ message_request.input.text = "How you doing?"
52
+
53
+ # send the message through the Conversator
54
+ response = Artemis::Bot::Conversator.message(workspace_id, message_request)
55
+ ```
56
+
57
+ `Artemis::Bot::MessageRequest` is a wrapper of the [MessageRequest hash](http://www.ibm.com/watson/developercloud/conversation/api/v1/?curl#send_message) that the endpoint is expecting
58
+
59
+
60
+ ## Contributing
61
+
62
+ Bug reports and pull requests are welcome on GitHub at https://github.com/icalialabs/artemis. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
63
+
64
+
65
+ ## License
66
+
67
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'artemis/bot/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "artemis-bot"
8
+ spec.version = Artemis::Bot::VERSION
9
+ spec.authors = ["Walter Reyes"]
10
+ spec.email = ["wal@icalialabs.com"]
11
+
12
+ spec.summary = %q{ Watson Conversation in Ruby}
13
+ spec.description = %q{ A Ruby wrapper for the Watson Conversation Service}
14
+ spec.homepage = "https://github.com/IcaliaLabs/artemis"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "httparty", "~> 0.14.0"
23
+ spec.add_dependency "httmultiparty", "~> 0.3.16"
24
+ spec.add_dependency "activesupport", "~> 4.0"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.12"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec", "~> 3.0"
29
+ end
data/bin/console ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'artemis/bot'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ require 'pry'
11
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/.DS_Store ADDED
Binary file
@@ -0,0 +1,14 @@
1
+ require 'artemis/bot/version'
2
+ require 'artemis/bot/message_request'
3
+ require 'artemis/bot/input'
4
+ require "olimpo"
5
+ require 'active_support/dependencies'
6
+ require 'httmultiparty'
7
+ require "pry"
8
+
9
+ module Artemis
10
+ module Bot
11
+ extend Olimpo
12
+ autoload(:Conversator, 'artemis/bot/conversator')
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ module Artemis
2
+ module Bot
3
+ module Connection
4
+ def self.included(klass)
5
+ klass.class_eval do
6
+ include HTTMultiParty
7
+ base_uri 'https://gateway.watsonplatform.net/conversation/api'
8
+ headers 'Content-Type' => 'application/json'
9
+ basic_auth Artemis::Bot.username, Artemis::Bot.password
10
+ debug_output $stdout
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ require 'artemis/bot/context/system'
2
+
3
+ module Artemis
4
+ module Bot
5
+ class Context
6
+ attr_reader :conversation_id, :system, :default_counter
7
+
8
+ def initialize(attrs = {})
9
+ @conversation_id = attrs['conversation_id']
10
+ @system = Artemis::Bot::Context::System.new(attrs['system'])
11
+ @default_counter = attrs['defaultCounter']
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module Artemis
2
+ module Bot
3
+ class Context
4
+ class System
5
+ attr_reader :dialog_stack, :dialog_turn_counter, :dialog_request_counter
6
+
7
+ def initialize(attrs = {})
8
+ @dialog_stack = attrs['dialog_stack']
9
+ @dialog_turn_counter = attrs['dialog_turn_counter']
10
+ @dialog_request_counter = attrs['dialog_request_counter']
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,33 @@
1
+ require 'artemis/bot/response'
2
+ require 'artemis/bot/message_request'
3
+ require 'artemis/bot/connection'
4
+ require 'artemis/bot/errors'
5
+ require 'artemis/services/object_to_hash'
6
+
7
+ module Artemis
8
+ module Bot
9
+ class Conversator < Olimpo::Base
10
+ include Artemis::Bot::Connection
11
+
12
+ def self.message(workspace_id, message_request = Artemis::Bot::MessageRequest.new)
13
+ message_request_hash = Artemis::Services::ObjectToHash.convert(message_request, include_nils: false)
14
+
15
+ response = post("/v1/workspaces/#{workspace_id}/message?version=2016-09-20",
16
+ body: message_request_hash.to_json)
17
+
18
+ parsed_response = JSON.parse(response.body)
19
+
20
+ return Artemis::Bot::Response.new(parsed_response) if response.success?
21
+
22
+ raise_exception(response.code, response.body)
23
+ end
24
+
25
+ private
26
+
27
+ def self.raise_exception(code, body)
28
+ raise Artemis::Bot::ServerError.new(code, body) if code >= 500
29
+ raise Artemis::Bot::ClientError.new(code, body) if code < 500
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,13 @@
1
+ module Artemis
2
+ module Bot
3
+ class Entity
4
+ attr_reader :entity, :location, :value
5
+
6
+ def initialize(attrs = {})
7
+ @entity = attrs['entity']
8
+ @location = attrs['location']
9
+ @value = attrs['value']
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,18 @@
1
+ module Artemis
2
+ module Bot
3
+ class Error < StandardError
4
+ attr_accessor :http_status, :response_body
5
+
6
+ def initialize(http_status, response_body)
7
+ message = " [HTTP #{http_status}] #{response_body}"
8
+ super(message)
9
+ end
10
+ end
11
+
12
+ # Any error with a 5xx HTTP status code
13
+ class ServerError < Error; end
14
+
15
+ # Any error with a 4xx HTTP status code
16
+ class ClientError < Error; end
17
+ end
18
+ end
@@ -0,0 +1,11 @@
1
+ module Artemis
2
+ module Bot
3
+ class Input
4
+ attr_accessor :text
5
+
6
+ def initialize(attrs = {})
7
+ @text = attrs['text']
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ module Artemis
2
+ module Bot
3
+ class Intent
4
+ attr_reader :intent, :confidence
5
+
6
+ def initialize(attrs = {})
7
+ @intent = attrs['intent']
8
+ @confidence = attrs['confidence']
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,18 @@
1
+ require 'artemis/bot/input'
2
+
3
+ module Artemis
4
+ module Bot
5
+ class MessageRequest
6
+ attr_accessor :input, :alternate_intents, :context, :entities, :intents, :output
7
+
8
+ def initialize(attrs = {})
9
+ @input = attrs['input'] || Artemis::Bot::Input.new
10
+ @alternate_intents = attrs['alternate_intents']
11
+ @context = attrs['context']
12
+ @entities = attrs['entities']
13
+ @intents = attrs['intents']
14
+ @output = attrs['output']
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,12 @@
1
+ module Artemis
2
+ module Bot
3
+ class Output
4
+ attr_reader :text, :nodes_visited
5
+
6
+ def initialize(attrs = {})
7
+ @text = attrs['text']
8
+ @nodes_visited = attrs['nodes_visited']
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,21 @@
1
+ require 'artemis/bot/input'
2
+ require 'artemis/bot/entity'
3
+ require 'artemis/bot/context'
4
+ require 'artemis/bot/intent'
5
+ require 'artemis/bot/output'
6
+
7
+ module Artemis
8
+ module Bot
9
+ class Response
10
+ attr_reader :input, :context, :entities, :intents, :output
11
+
12
+ def initialize(attrs = {})
13
+ @input = Artemis::Bot::Input.new(attrs['input'])
14
+ @context = Artemis::Bot::Context.new(attrs['context'])
15
+ @entities = attrs['entities'].map { |entity| Artemis::Bot::Entity.new(entity) }
16
+ @intents = attrs['intents'].map { |intent| Artemis::Bot::Intent.new(intent) }
17
+ @output = Artemis::Bot::Output.new(attrs['output'])
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,5 @@
1
+ module Artemis
2
+ module Bot
3
+ VERSION = '0.1.1'.freeze
4
+ end
5
+ end
@@ -0,0 +1,27 @@
1
+ module Artemis
2
+ module Services
3
+ module ObjectToHash
4
+ def self.convert(object, opts = { include_nils: true })
5
+ hash = {}
6
+ object.instance_variables.each do |var|
7
+ var_value = object.instance_variable_get(var)
8
+
9
+ next if !opts['include_nils'] && var_value.nil?
10
+
11
+ hash[var.to_s.delete('@')] = if descendant?(var_value, Artemis::Bot)
12
+ convert(var_value)
13
+ else
14
+ hash[var.to_s.delete('@')] = var_value
15
+ end
16
+ end
17
+
18
+ hash
19
+ end
20
+
21
+ def self.descendant?(value, parent)
22
+ parent = parent.class unless parent.is_a?(Class) || parent.is_a?(Module)
23
+ value.class.to_s.index("#{parent}::").present?
24
+ end
25
+ end
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: artemis-bot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Walter Reyes
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-11-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.14.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.14.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: httmultiparty
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.3.16
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.3.16
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '4.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.12'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.12'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.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: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ description: " A Ruby wrapper for the Watson Conversation Service"
98
+ email:
99
+ - wal@icalialabs.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".DS_Store"
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".travis.yml"
108
+ - CODE_OF_CONDUCT.md
109
+ - Gemfile
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - artemis-bot.gemspec
114
+ - bin/console
115
+ - bin/setup
116
+ - lib/.DS_Store
117
+ - lib/artemis/bot.rb
118
+ - lib/artemis/bot/connection.rb
119
+ - lib/artemis/bot/context.rb
120
+ - lib/artemis/bot/context/system.rb
121
+ - lib/artemis/bot/conversator.rb
122
+ - lib/artemis/bot/entity.rb
123
+ - lib/artemis/bot/errors.rb
124
+ - lib/artemis/bot/input.rb
125
+ - lib/artemis/bot/intent.rb
126
+ - lib/artemis/bot/message_request.rb
127
+ - lib/artemis/bot/output.rb
128
+ - lib/artemis/bot/response.rb
129
+ - lib/artemis/bot/version.rb
130
+ - lib/artemis/services/object_to_hash.rb
131
+ homepage: https://github.com/IcaliaLabs/artemis
132
+ licenses:
133
+ - MIT
134
+ metadata: {}
135
+ post_install_message:
136
+ rdoc_options: []
137
+ require_paths:
138
+ - lib
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ requirements: []
150
+ rubyforge_project:
151
+ rubygems_version: 2.6.4
152
+ signing_key:
153
+ specification_version: 4
154
+ summary: Watson Conversation in Ruby
155
+ test_files: []