converse 1.0.3 → 1.0.4

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.
data/lib/converse/api.rb CHANGED
@@ -1,7 +1,9 @@
1
- class API
2
- attr_reader :broker
1
+ module Converse
2
+ class API
3
+ attr_reader :broker
3
4
 
4
- def initialize(broker)
5
- @broker = broker
5
+ def initialize(broker)
6
+ @broker = broker
7
+ end
6
8
  end
7
- end
9
+ end
@@ -1,13 +1,15 @@
1
- class Broker
2
- attr_accessor :domain_language
1
+ module Converse
2
+ class Broker
3
+ attr_accessor :domain_language
3
4
 
4
- def open_topic(concern, action)
5
- end
5
+ def open_topic(concern, action)
6
+ end
6
7
 
7
- def broker_conversation(topic)
8
- end
8
+ def broker_conversation(topic)
9
+ end
9
10
 
10
- def discuss(concern, action)
11
- broker_conversation(open_topic(concern, action))
11
+ def discuss(concern, action)
12
+ broker_conversation(open_topic(concern, action))
13
+ end
12
14
  end
13
- end
15
+ end
@@ -1,39 +1,41 @@
1
- class Conversation
2
- attr_accessor :uri
3
- attr_accessor :body
4
- attr_accessor :headers
5
- attr_accessor :connection
6
- attr_accessor :host
7
- attr_accessor :port
8
- attr_accessor :path
9
- attr_accessor :request
10
- attr_accessor :response
11
- attr_accessor :subscribers
1
+ module Converse
2
+ class Conversation
3
+ attr_accessor :uri
4
+ attr_accessor :body
5
+ attr_accessor :headers
6
+ attr_accessor :connection
7
+ attr_accessor :host
8
+ attr_accessor :port
9
+ attr_accessor :path
10
+ attr_accessor :request
11
+ attr_accessor :response
12
+ attr_accessor :subscribers
12
13
 
13
- def initialize(uri)
14
- @uri = uri
15
- parsed = URI.parse(uri)
16
- @host = parsed.host
17
- @port = parsed.port
18
- @path = parsed.path
19
- @subscribers = []
20
- end
14
+ def initialize(uri)
15
+ @uri = uri
16
+ parsed = URI.parse(uri)
17
+ @host = parsed.host
18
+ @port = parsed.port
19
+ @path = parsed.path
20
+ @subscribers = []
21
+ end
21
22
 
22
- def ask
23
- raise NotImplementedError.new
24
- end
23
+ def ask
24
+ raise NotImplementedError.new
25
+ end
25
26
 
26
- def say
27
- raise NotImplementedError.new
28
- end
27
+ def say
28
+ raise NotImplementedError.new
29
+ end
29
30
 
30
- def subscribe(subscriber)
31
- @subscribers << subscriber
32
- end
31
+ def subscribe(subscriber)
32
+ @subscribers << subscriber
33
+ end
33
34
 
34
- def notify_subscribers(data)
35
- @subscribers.each do |subscriber|
36
- subscriber.notify(data)
35
+ def notify_subscribers(data)
36
+ @subscribers.each do |subscriber|
37
+ subscriber.notify(data)
38
+ end
37
39
  end
38
40
  end
39
- end
41
+ end
@@ -2,56 +2,58 @@ require 'net/http'
2
2
  require "comms/conversation"
3
3
  require "json"
4
4
 
5
- class HTMLConversation < Conversation
6
- attr_accessor :use_ssl
7
-
8
- def initialize(uri)
9
- super(uri)
10
- @use_ssl = false
11
- @port = @use_ssl ? 443 : 80 if @port == nil
12
- end
5
+ module Converse
6
+ class HTMLConversation < Conversation
7
+ attr_accessor :use_ssl
8
+
9
+ def initialize(uri)
10
+ super(uri)
11
+ @use_ssl = false
12
+ @port = @use_ssl ? 443 : 80 if @port == nil
13
+ end
13
14
 
14
- def notify_subscribers_of_request(path)
15
- output = "HTTP=>\n"
16
- output += "#{path}\n"
17
- output += "#{@request.body}\n"
18
- notify_subscribers(output)
19
- end
15
+ def notify_subscribers_of_request(path)
16
+ output = "HTTP=>\n"
17
+ output += "#{path}\n"
18
+ output += "#{@request.body}\n"
19
+ notify_subscribers(output)
20
+ end
20
21
 
21
- def notify_subscribers_of_response
22
- output = "<=HTTP\n"
23
- output += "#{@response.body}\n"
24
- notify_subscribers(output)
25
- end
22
+ def notify_subscribers_of_response
23
+ output = "<=HTTP\n"
24
+ output += "#{@response.body}\n"
25
+ notify_subscribers(output)
26
+ end
26
27
 
27
- def populate_request(path, data)
28
- @request.body = data if not data.nil?
29
- @request.basic_auth "hetzner_api", "secret"
30
- notify_subscribers_of_request(path)
31
- end
28
+ def populate_request(path, data)
29
+ @request.body = data if not data.nil?
30
+ @request.basic_auth "hetzner_api", "secret"
31
+ notify_subscribers_of_request(path)
32
+ end
32
33
 
33
- def converse(path, data = nil)
34
- populate_request(path, data)
35
- @response = connect.request @request
36
- notify_subscribers_of_response
37
- return @response
38
- end
34
+ def converse(path, data = nil)
35
+ populate_request(path, data)
36
+ @response = connect.request @request
37
+ notify_subscribers_of_response
38
+ return @response
39
+ end
39
40
 
40
- def connect
41
- if (@use_ssl)
42
- Net::HTTP.start(@host, @port, :use_ssl => @use_ssl ? "yes" : "no")
43
- else
44
- Net::HTTP.start(@host, @port)
41
+ def connect
42
+ if (@use_ssl)
43
+ Net::HTTP.start(@host, @port, :use_ssl => @use_ssl ? "yes" : "no")
44
+ else
45
+ Net::HTTP.start(@host, @port)
46
+ end
45
47
  end
46
- end
47
48
 
48
- def ask(path, data = nil)
49
- @request = Net::HTTP::Get.new(path)
50
- converse(path, data)
51
- end
49
+ def ask(path, data = nil)
50
+ @request = Net::HTTP::Get.new(path)
51
+ converse(path, data)
52
+ end
52
53
 
53
- def say(path, data = nil)
54
- @request = Net::HTTP::Post.new(path)
55
- converse(path, data)
54
+ def say(path, data = nil)
55
+ @request = Net::HTTP::Post.new(path)
56
+ converse(path, data)
57
+ end
56
58
  end
57
59
  end
@@ -1,39 +1,41 @@
1
1
  require "comms/conversation"
2
2
  require "mysql2"
3
3
 
4
- class MysqlConversation < Conversation
5
- attr_writer :username
6
- attr_writer :password
7
- attr_writer :database
8
- attr_accessor :query
4
+ module Converse
5
+ class MysqlConversation < Conversation
6
+ attr_writer :username
7
+ attr_writer :password
8
+ attr_writer :database
9
+ attr_accessor :query
9
10
 
10
- def initialize(uri)
11
- super(uri)
12
- parsed = URI.parse(uri)
13
- @username = parsed.user
14
- @password = parsed.password
15
- @database = parsed.path.gsub(/\//, "")
16
- end
11
+ def initialize(uri)
12
+ super(uri)
13
+ parsed = URI.parse(uri)
14
+ @username = parsed.user
15
+ @password = parsed.password
16
+ @database = parsed.path.gsub(/\//, "")
17
+ end
17
18
 
18
- def connect()
19
- @client = Mysql2::Client.new(:host => @host,
20
- :port => @port.to_f,
21
- :username => @username,
22
- :password => @password,
23
- :database => @database)
24
- end
19
+ def connect()
20
+ @client = Mysql2::Client.new(:host => @host,
21
+ :port => @port.to_f,
22
+ :username => @username,
23
+ :password => @password,
24
+ :database => @database)
25
+ end
25
26
 
26
- def converse
27
- connect()
28
- @client.query(@query)
29
- end
27
+ def converse
28
+ connect()
29
+ @client.query(@query)
30
+ end
30
31
 
31
- def ask
32
- converse
33
- end
32
+ def ask
33
+ converse
34
+ end
34
35
 
35
- def say
36
- converse
37
- end
36
+ def say
37
+ converse
38
+ end
38
39
 
40
+ end
39
41
  end
@@ -1,58 +1,61 @@
1
1
  require "comms/simple_logger"
2
2
 
3
- class Interaction
4
- attr_accessor :broker
5
- attr_accessor :concern
6
- attr_accessor :action
7
- attr_accessor :substance
8
- attr_accessor :conversation
9
- attr_accessor :should_i_ask
10
-
11
- def discuss_with_broker_concerning(broker, concern)
12
- discuss_with(broker)
13
- concerning(concern)
14
- end
15
-
16
- def discuss_with(broker)
17
- @broker = broker
18
- end
19
-
20
- def concerning(concern)
21
- @concern = concern.dup
22
- end
23
-
24
- def about(action)
25
- @action = action.dup
26
- end
27
-
28
- def detailed_by(substance)
29
- @substance = substance
30
- end
31
-
32
- def by_asking
33
- @should_i_ask = true
34
- end
35
-
36
- def by_saying
37
- @should_i_ask = false
38
- end
39
-
40
- def ask
41
- @conversation.ask
42
- end
43
-
44
- def say
45
- @conversation.say
46
- end
47
-
48
- def discuss
49
- @conversation = broker.broker_conversation(@broker.open_topic(@concern, @action))
50
- @conversation.subscribe(SimpleLogger.new)
51
- @should_i_ask ? response = ask : response = say
52
- interpret_conversation(response)
53
- end
54
-
55
- def interpret_conversation(response)
56
- response
57
- end
58
- end
3
+ module Converse
4
+
5
+ class Interaction
6
+ attr_accessor :broker
7
+ attr_accessor :concern
8
+ attr_accessor :action
9
+ attr_accessor :substance
10
+ attr_accessor :conversation
11
+ attr_accessor :should_i_ask
12
+
13
+ def discuss_with_broker_concerning(broker, concern)
14
+ discuss_with(broker)
15
+ concerning(concern)
16
+ end
17
+
18
+ def discuss_with(broker)
19
+ @broker = broker
20
+ end
21
+
22
+ def concerning(concern)
23
+ @concern = concern.dup
24
+ end
25
+
26
+ def about(action)
27
+ @action = action.dup
28
+ end
29
+
30
+ def detailed_by(substance)
31
+ @substance = substance
32
+ end
33
+
34
+ def by_asking
35
+ @should_i_ask = true
36
+ end
37
+
38
+ def by_saying
39
+ @should_i_ask = false
40
+ end
41
+
42
+ def ask
43
+ @conversation.ask
44
+ end
45
+
46
+ def say
47
+ @conversation.say
48
+ end
49
+
50
+ def discuss
51
+ @conversation = broker.broker_conversation(@broker.open_topic(@concern, @action))
52
+ @conversation.subscribe(SimpleLogger.new)
53
+ @should_i_ask ? response = ask : response = say
54
+ interpret_conversation(response)
55
+ end
56
+
57
+ def interpret_conversation(response)
58
+ response
59
+ end
60
+ end
61
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: converse
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: