jarvis-cli 0.1.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 892d62136bdf6f60cddb1e58048be3b585dabe12
4
- data.tar.gz: 3bf685aaa9d7212ccd401a6b2f3f6682df8d359b
3
+ metadata.gz: 7c00b9ecae0eade20f5d304fb6f9503d88f25896
4
+ data.tar.gz: 6fe81131c111fc54d8271e4fdd730b7d2cf2fcf7
5
5
  SHA512:
6
- metadata.gz: 416d63e868a5e398096b9c6e281e9e5ab38e637417e510d8ee84183fbb9925e53c5f482e97862cec4321bec6fd1df62a2b51cbb88c108983545634fc0d0f00be
7
- data.tar.gz: 3cbe3f88db1ae04ef9cc9970ff6dddc039db8ba5a372a2a46548c06f0955af7beab7b01f263e12db3dbf027890c60dc451d8626c1e5f1ffdd33c4953b00d91ad
6
+ metadata.gz: 19ee2062a4a7eb861fffd094d1d9fa0ce7ccb867d0156ffeb92e86931080664fd0a63a4311fc5a3b737fae3f690caea7c23a451e1dda8636a61a89359d777718
7
+ data.tar.gz: fa355662c6eef79d9547069e9e75430d7d7bb06cb54ea0e380ddf033bc1eef315fabe533da7381b87d0b6aa8c9d50668de17f8c935dd62a6084514639a75edd3
data/README.md CHANGED
@@ -116,12 +116,23 @@ class Joke < Jarvis::Service
116
116
  end
117
117
  end
118
118
  ```
119
- ## TODO
119
+ ## Ship List
120
120
 
121
- * Finish Porting The Services from the original bot to the framework
122
- * Add Test Framework to the Project Generator
123
- * Service Generator
124
- * Configure all the things
121
+ When these things are done, we'll be ready for 1.0
122
+
123
+ Finish Porting The Services from the original bot to the framework
124
+
125
+ ☐ Ability for Jarvis to Post Back into the Slack Chatroom
126
+
127
+ ☐ Jarvis::Schedule
128
+
129
+ ☐ Add Test Framework to the Project Generator
130
+
131
+ ✓ Service Generator
132
+
133
+ ✓ Configure All The Things
134
+
135
+ ✓ Boot Process for the Generated App
125
136
 
126
137
  ## Contributing
127
138
 
@@ -0,0 +1,14 @@
1
+ module Jarvis
2
+ class Application
3
+ def self.initialize!
4
+ require File.join Jarvis.root, "bot/server"
5
+ require_initializers
6
+ end
7
+
8
+ def self.require_initializers
9
+ Dir[Jarvis.root + '/config/initializers/*.rb'].each do |file|
10
+ require file
11
+ end
12
+ end
13
+ end
14
+ end
data/lib/jarvis/cli.rb CHANGED
@@ -3,23 +3,35 @@ module Jarvis
3
3
  class CLI < Thor
4
4
  include Thor::Actions
5
5
 
6
+ attr_reader :name
7
+
6
8
  desc "new BOT_NAME", "Sets up a new Jarvis project"
7
9
  def new(name)
8
10
  @name = Thor::Util.snake_case(name)
9
11
  directory(:project, @name)
10
12
  end
11
13
 
12
- desc "boot", "Bootup the Jarvis Application"
13
- def boot(*args)
14
+ desc "start", "Bootup the Jarvis Application"
15
+ def start(*args)
14
16
  port_option = args.include?('-p') ? '' : ' -p 3030'
15
17
  command = "rackup #{port_option}"
16
18
  run_command(command)
17
19
  end
18
20
 
21
+ desc "generate", "Generate service NAME"
22
+ def generate(type, name)
23
+ @name = Thor::Util.snake_case(name)
24
+ generate_service(@name)
25
+ end
26
+
19
27
  private
20
28
 
21
29
  def run_command(command)
22
30
  system(command)
23
31
  end
32
+
33
+ def generate_service(name)
34
+ template("services/%name%.rb.tt", "bot/services/#{name}.rb")
35
+ end
24
36
  end
25
37
  end
@@ -0,0 +1,17 @@
1
+ module Jarvis
2
+ module Configuration
3
+ require 'active_support'
4
+ require 'active_support/configurable'
5
+ require 'active_support/dependencies'
6
+ def self.included(base)
7
+ base.include ActiveSupport::Configurable
8
+ base.configure do |config|
9
+ config.default_response = "What is this, I don't even"
10
+ config.unfit_environment_response = "I'm really sorry, but that service needs to be configured"
11
+ config.third_party_api_failure_respone = "Most unfortunately, that service is not working right now."
12
+ config.standard_error_response = "I'm sorry, Something went wrong."
13
+ config.autoload_paths = ["#{Jarvis.root}/app/services"]
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,40 @@
1
+ module Jarvis
2
+ module HTTPUtilities
3
+ require 'httparty'
4
+ require 'uri'
5
+ module ClassMethods
6
+ # HTTP Requests
7
+ def get(path, options={}, &block)
8
+ Jarvis::API::Response.new HTTParty.get(path, options, &block)
9
+ end
10
+
11
+ def post(path, options={}, &block)
12
+ Jarvis::API::Response.new HTTParty.post(path, options, &block)
13
+ end
14
+
15
+ def patch(path, options={}, &block)
16
+ Jarvis::API::Response.new HTTParty.patch(path, options, &block)
17
+ end
18
+
19
+ def put(path, options={}, &block)
20
+ Jarvis::API::Response.new HTTParty.put(path, options, &block)
21
+ end
22
+
23
+ def delete(path, options={}, &block)
24
+ Jarvis::API::Response.new HTTParty.delete(path, options, &block)
25
+ end
26
+
27
+ def encode_uri(str)
28
+ URI.encode(str)
29
+ end
30
+
31
+ def decode_uri(str)
32
+ URI.decode(str)
33
+ end
34
+ end
35
+ def self.included(base)
36
+ base.send(:include, HTTParty)
37
+ base.send(:extend, ClassMethods)
38
+ end
39
+ end
40
+ end
data/lib/jarvis/server.rb CHANGED
@@ -17,11 +17,11 @@ module Jarvis
17
17
  begin
18
18
  json text: run_service(service)
19
19
  rescue Jarvis::UnfitEnvironmentException => e
20
- json text: "I'm really sorry, but that service needs to be configured"
20
+ json text: Jarvis::ArrayResponder.new(Jarvis.config.unfit_environment_response).respond
21
21
  rescue Jarvis::ThirdPartyAPIFailure
22
- json text: "Most unfortunately, #{params["user_name"]}, that service is not working right now."
22
+ json text: Jarvis::ArrayResponder.new(Jarvis.config.third_party_api_failure_respone).respond
23
23
  rescue => e
24
- json text: "I'm sorry, Something went wrong: #{e}"
24
+ json text: Jarvis::ArrayResponder.new(Jarvis.config.standard_error_response).respond
25
25
  end
26
26
  end
27
27
 
@@ -1,2 +1,5 @@
1
1
  class NullService < Jarvis::Service
2
+ def run
3
+ Jarvis::ArrayResponder.new(Jarvis.config.default_response).respond
4
+ end
2
5
  end
@@ -0,0 +1,16 @@
1
+ module Jarvis
2
+ class ArrayResponder
3
+ attr_accessor :response
4
+
5
+ def initialize(response)
6
+ @response = response
7
+ end
8
+
9
+ def respond
10
+ case response
11
+ when String then [response]
12
+ when Array then response
13
+ end.sample
14
+ end
15
+ end
16
+ end
@@ -1,3 +1,3 @@
1
1
  module Jarvis
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/jarvis.rb CHANGED
@@ -9,19 +9,12 @@ require 'jarvis/refinements'
9
9
  require 'jarvis/services'
10
10
  require 'jarvis/slack'
11
11
  require 'jarvis/api/response'
12
- require 'httparty'
13
- require 'uri'
14
- require 'active_support/configurable'
15
-
12
+ require 'jarvis/configuration'
13
+ require 'jarvis/http_utilities'
14
+ require 'jarvis/application'
15
+ require 'jarvis/utilities/array_responder'
16
16
  module Jarvis
17
- include HTTParty
18
- include ActiveSupport::Configurable
19
-
20
- self.configure do |config|
21
- end
22
-
23
17
  class << self
24
-
25
18
  attr_accessor :services
26
19
  def services
27
20
  @services ||= []
@@ -36,33 +29,15 @@ module Jarvis
36
29
  @services = []
37
30
  end
38
31
 
39
- # HTTP Requests
40
- def get(path, options={}, &block)
41
- Jarvis::API::Response.new HTTParty.get(path, options, &block)
42
- end
43
-
44
- def post(path, options={}, &block)
45
- Jarvis::API::Response.new HTTParty.post(path, options, &block)
46
- end
47
-
48
- def patch(path, options={}, &block)
49
- Jarvis::API::Response.new HTTParty.patch(path, options, &block)
50
- end
51
-
52
- def put(path, options={}, &block)
53
- Jarvis::API::Response.new HTTParty.put(path, options, &block)
54
- end
55
-
56
- def delete(path, options={}, &block)
57
- Jarvis::API::Response.new HTTParty.delete(path, options, &block)
58
- end
59
-
60
- def encode_uri(str)
61
- URI.encode(str)
32
+ def bootstrap
33
+ require File.join Jarvis.root, "config", "environment"
34
+ Jarvis::Application.initialize!
62
35
  end
63
36
 
64
- def decode_uri(str)
65
- URI.decode(str)
37
+ def root
38
+ self.config.root
66
39
  end
67
40
  end
41
+ include Jarvis::HTTPUtilities
42
+ include Jarvis::Configuration
68
43
  end
@@ -1,3 +1,7 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem 'jarvis-cli', require: 'jarvis', path: "~/code/jarvis-cli"
3
+ gem 'jarvis-cli', require: 'jarvis', path: "../../"
4
+ gem 'unicorn'
5
+ group :development, :test do
6
+ gem 'byebug'
7
+ end
@@ -0,0 +1,12 @@
1
+ require 'bundler/setup'
2
+ Bundler.require(:default, ENV["RACK_ENV"].to_sym)
3
+ Jarvis.configure do |config|
4
+ config.root = File.expand_path "./"
5
+ # Default response is what Jarvis will say in response to a message that doesn't have a registered service.
6
+ # If you configure this to be an array of strings, a random one will be selected.
7
+ # config.default_response = "What is this, I don't even"
8
+
9
+ # Add additional autoload directories to autoload_paths
10
+ # config.autoload_paths << "#{Jarvis.root}/bot/models"
11
+ end
12
+ Jarvis.bootstrap
File without changes
@@ -1,4 +1,2 @@
1
- $: << File.expand_path('../', __FILE__)
2
- require 'jarvis'
3
- require './bot/server.rb'
1
+ require File.join File.dirname(__FILE__), "config/environment"
4
2
  run Server
@@ -0,0 +1,5 @@
1
+ class <%= Thor::Util.camel_case(name) %> < Jarvis::Service
2
+ # See https://github.com/DVG/jarvis-cli for information on creating services
3
+ def run
4
+ end
5
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jarvis-cli
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
  - DVG
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-23 00:00:00.000000000 Z
11
+ date: 2015-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -323,10 +323,13 @@ files:
323
323
  - jarvis-cli.gemspec
324
324
  - lib/jarvis.rb
325
325
  - lib/jarvis/api/response.rb
326
+ - lib/jarvis/application.rb
326
327
  - lib/jarvis/cli.rb
328
+ - lib/jarvis/configuration.rb
327
329
  - lib/jarvis/core_ext.rb
328
330
  - lib/jarvis/core_ext/symbol.rb
329
331
  - lib/jarvis/exceptions.rb
332
+ - lib/jarvis/http_utilities.rb
330
333
  - lib/jarvis/interpreter.rb
331
334
  - lib/jarvis/refinements.rb
332
335
  - lib/jarvis/refinements/zip_refinement.rb
@@ -361,6 +364,7 @@ files:
361
364
  - lib/jarvis/slack/message.rb
362
365
  - lib/jarvis/test_support/cucumber.rb
363
366
  - lib/jarvis/test_support/test_support.rb
367
+ - lib/jarvis/utilities/array_responder.rb
364
368
  - lib/jarvis/version.rb
365
369
  - spec/jarvis/interpreter_spec.rb
366
370
  - spec/jarvis/jarvis_spec.rb
@@ -402,6 +406,9 @@ files:
402
406
  - templates/project/bot/services/.gitkeep
403
407
  - templates/project/config.ru
404
408
  - templates/project/config/.gitkeep
409
+ - templates/project/config/environment.rb
410
+ - templates/project/config/initializers/.gitkeep
411
+ - templates/services/%name%.rb.tt
405
412
  homepage: https://github.com/DVG/jarvis-cli.git
406
413
  licenses:
407
414
  - MIT