watsbot 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b41f8b57d87729bb11ef95cab49fd8017441754d
4
+ data.tar.gz: 741021ef543d67646490bc89ebf6defcb1c85cda
5
+ SHA512:
6
+ metadata.gz: b4949ae9e6ea73319cf501cb16e140b0cf5091d86d58fd759006edeb1997507c5713ed357edef595f0e949504400cb8c00037a44b21461c9a2d3f23b1c357a50
7
+ data.tar.gz: 9a192c6a5be0cc2c755aa738f8cf9047d94ade2971ca8ad85c7b1a6170463cd7664ea38f47b8fda34f60750764bab94a2712014aab072c639c631e82ca1a5423
@@ -0,0 +1,71 @@
1
+ c
2
+ n
3
+ ex
4
+ n
5
+ ex
6
+ n
7
+ uid
8
+ c
9
+ response.context["system"]
10
+ response.context["system"]["branch_exited_reason"]
11
+ response.context["system"]["branch_exited_reason"
12
+ n
13
+ response
14
+ n
15
+ c
16
+ response
17
+ n
18
+ c
19
+ response
20
+ n
21
+ c
22
+ State.instancec
23
+ State.instance
24
+ response
25
+ response = message.call(uid, "Hi", {})
26
+ Watsbot.configuration.version
27
+ c
28
+ response
29
+ n
30
+ c
31
+ State.instance
32
+ State.instance.redis.keys
33
+ State.instance.keys
34
+ State.instance.fetch(uid)
35
+ c
36
+ data.to_json
37
+ data
38
+ d2 = state.fetch(uid)
39
+ c
40
+ e
41
+ n
42
+ c
43
+ e
44
+ n
45
+ c
46
+ options
47
+ n
48
+ c
49
+ e
50
+ n
51
+ Watsbot.configuration.version
52
+ options
53
+ body
54
+ n
55
+ c
56
+ e.backtrace.first
57
+ e
58
+ n
59
+ context
60
+ state
61
+ n
62
+ uid
63
+ s
64
+ n
65
+ ENV["WATSON_WORKSPACE_VERSION"]
66
+ c
67
+ Dotenv.load
68
+ ENV["WATSON_WORKSPACE_VERSION"]
69
+ ENV["WATSON_WORKSPACE"]
70
+ ENV["WATSON_PASSWORD"]
71
+ ENV["WATSON_USERNAME"]
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /log/
11
+ # rspec failure tracking
12
+ .rspec_status
13
+ coverage
14
+ .env
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ SimpleCov.start do
2
+ add_group "lib", "lib"
3
+ add_filter "/spec/"
4
+ end
@@ -0,0 +1,14 @@
1
+ sudo: false
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.3.3
6
+ before_install: gem install bundler -v 1.15.0
7
+ script: 'bundle exec rake'
8
+
9
+ notifications:
10
+ email:
11
+ recipients:
12
+ - payam@roundtableapps.com
13
+ on_failure: change
14
+ on_success: never
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at payam@roundtableapps.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in watsbot.gemspec
4
+ gemspec
@@ -0,0 +1,26 @@
1
+ guard 'rspec', cmd: "rspec" do
2
+ require "guard/rspec/dsl"
3
+ dsl = Guard::RSpec::Dsl.new(self)
4
+
5
+ # RSpec files
6
+ rspec = dsl.rspec
7
+ watch(rspec.spec_helper) { rspec.spec_dir }
8
+ watch(rspec.spec_support) { rspec.spec_dir }
9
+ watch(rspec.spec_files)
10
+
11
+ # Ruby files
12
+ ruby = dsl.ruby
13
+ dsl.watch_spec_files_for(ruby.lib_files)
14
+
15
+ # watch /lib/ files
16
+ watch(%r{^lib\/watsbot\/(.+)\.rb$}) do |m|
17
+ "spec/#{m[1]}_spec.rb"
18
+ end
19
+
20
+ # watch /spec/ files
21
+ watch(%r{^spec\/(.+)\.rb$}) do |m|
22
+ "spec/#{m[1]}.rb"
23
+ end
24
+
25
+ watch('spec/spec_helper.rb') { "spec" }
26
+ end
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Payam Mousavi
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.
@@ -0,0 +1,63 @@
1
+ # Watsbot
2
+
3
+ Talk to [IBM Watson Conversation service](https://www.ibm.com/watson/developercloud/doc/conversation/getting-started.html)!
4
+
5
+ This gem provides a simple client to communicate with IBM Watson Conversation service using REST API. It utilizes [Redis](https://redis.io/) to store state of the conversation.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'watsbot'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install watsbot
22
+
23
+ ## Requirements
24
+
25
+ * Redis server ([https://redis.io/topics/quickstart](https://redis.io/topics/quickstart))
26
+
27
+ ## Examples
28
+
29
+
30
+ ```ruby
31
+ require 'watsbot/watsbot'
32
+
33
+ # config/initializers/watsbot.rb
34
+ Watsbot::Configuration.new(
35
+ username: ENV["WATSON_USERNAME"],
36
+ password: ENV["WATSON_PASSWORD"],
37
+ workspace: ENV["WATSON_WORKSPACE"],
38
+ version: ENV["WATSON_WORKSPACE_VERSION"],
39
+ redis_url: ENV["REDIS_URL"] # redis://127.0.0.1:6379/2
40
+ )
41
+
42
+ watsbot = Watsbot::Message.new
43
+
44
+ # To start a conversation/send a message without context
45
+ watsbot.send("A UNIQUE IDENTIFIER, e.g. uuid", "Hi")
46
+
47
+ # To send a message with context
48
+ watsbot.send("A UNIQUE IDENTIFIER, e.g. uuid", "Hi", { conversation_id: "...", ... })
49
+ ```
50
+
51
+ ## Development
52
+
53
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
54
+
55
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
56
+
57
+ ## Contributing
58
+
59
+ Bug reports and pull requests are welcome on GitHub at https://github.com/pamit/watsbot.
60
+
61
+ ## License
62
+
63
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+ require "dotenv"
4
+
5
+ Dotenv.load
6
+
7
+ RSpec::Core::RakeTask.new(:spec) do |task|
8
+ task.rspec_opts = ['--color', '--format', 'documentation']
9
+ end
10
+
11
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "watsbot"
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
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -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
@@ -0,0 +1,33 @@
1
+ require "watsbot/base_resource"
2
+ require "watsbot/configuration"
3
+ require "watsbot/logger"
4
+ require "watsbot/message"
5
+ require "watsbot/state"
6
+ require "watsbot/version"
7
+ require "watsbot/response/error"
8
+ require "watsbot/response/success"
9
+ require "watsbot/response/parser"
10
+
11
+ module Watsbot
12
+ BASE_URI = "https://gateway.watsonplatform.net/conversation/api/v1"
13
+
14
+ def self.root
15
+ File.dirname __dir__
16
+ end
17
+
18
+ class << self
19
+ attr_writer :configuration
20
+
21
+ def configure(&block)
22
+ yield(configuration)
23
+ end
24
+
25
+ def configuration
26
+ @configuration ||= Configuration.new
27
+ end
28
+
29
+ def reset
30
+ @configuration = Configuration.new
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,19 @@
1
+ module Watsbot
2
+ class BaseResource
3
+ attr_accessor :config, :logger
4
+
5
+ def initialize(config = Watsbot.configuration)
6
+ @config = config
7
+ self.class.base_uri @config.base_uri
8
+ @logger = Logger.instance
9
+ end
10
+
11
+ def headers
12
+ { 'Content-Type' => 'application/json' }
13
+ end
14
+
15
+ def basic_auth
16
+ { username: @config.username, password: @config.password }
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,16 @@
1
+ module Watsbot
2
+ class Configuration
3
+ attr_accessor :username, :password, :workspace, :version, :base_uri, :redis_url
4
+
5
+ def initialize(*args, &block)
6
+ arg = args.pop || {}
7
+ @username = arg[:username] || ENV["WATSON_USERNAME"]
8
+ @password = arg[:password] || ENV["WATSON_PASSWORD"]
9
+ @workspace = arg[:workspace] || ENV["WATSON_WORKSPACE"]
10
+ @version = arg[:version] || ENV["WATSON_WORKSPACE_VERSION"]
11
+ @base_uri = BASE_URI
12
+ @redis_url = arg[:redis_url] || ENV["REDIS_URL"]
13
+ yield self if block_given?
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,50 @@
1
+ require "logger"
2
+ require "singleton"
3
+
4
+ module Watsbot
5
+ class Logger
6
+ include Singleton
7
+
8
+ def debug(path, message)
9
+ ::Logger.new(make_log_file(path), "daily").debug(message)
10
+ end
11
+
12
+ def error(path, message)
13
+ ::Logger.new(make_log_file(path), "daily").error(message)
14
+ end
15
+
16
+ def info(path, message)
17
+ ::Logger.new(make_log_file(path), "daily").info(message)
18
+ end
19
+
20
+ def warn(path, message)
21
+ ::Logger.new(make_log_file(path), "daily").warn(message)
22
+ end
23
+
24
+ def raw_log(path, message)
25
+ full_path = make_log_file(path)
26
+ File.open(full_path, "a+") { |f| f.puts("R, [#{DateTime.now.as_json}] RAW -- : " + message) }
27
+ end
28
+
29
+ private
30
+
31
+ def make_log_file(path)
32
+ log_address = "#{Watsbot.root}#{path}"
33
+ make_dir(File.dirname(log_address))
34
+ make_file(log_address)
35
+ log_address
36
+ end
37
+
38
+ def make_dir(path)
39
+ if (!File.directory? path)
40
+ FileUtils.mkpath path
41
+ end
42
+ end
43
+
44
+ def make_file(path_to_file)
45
+ if (!File.exists? path_to_file)
46
+ FileUtils.touch path_to_file
47
+ end
48
+ end
49
+ end
50
+ end