converse 1.0.7 → 1.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +57 -57
- data/lib/converse/version.rb +1 -1
- metadata +3 -3
data/README.md
CHANGED
@@ -18,7 +18,7 @@ that allow the creation of an application-specified API for interacting with pro
|
|
18
18
|
dependency on providers. The application only depends on the API it specifies, i.e. the language it wants to talk.
|
19
19
|
|
20
20
|
Brokers become plug-in adapters to providers and can be swapped out at will, provided they can speak the application's
|
21
|
-
language as well as the provider's language
|
21
|
+
language as well as the provider's language. The set of interactions a broker is aware of specifies the API towards
|
22
22
|
the provider. The application specifies its API through a set of methods that ask brokers to act on its behalf.
|
23
23
|
|
24
24
|
Brokers can be chained for multiple translation / technology bridging.
|
@@ -46,74 +46,74 @@ want to swap the RESTful provider out for a SQL provider, or some other provider
|
|
46
46
|
|
47
47
|
The application specifies the API it wants to talk, and teaches a broker how to discuss transactions:
|
48
48
|
|
49
|
-
class ApplicationApi < API
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
end
|
49
|
+
class ApplicationApi < API
|
50
|
+
def get_transactions(client_id)
|
51
|
+
substance = { 'client_id' => client_id }
|
52
|
+
o = GetTransactions.new(@broker, substance)
|
53
|
+
o.discuss
|
54
|
+
end
|
55
|
+
end
|
56
56
|
|
57
57
|
The GetTransactions interaction faces towards the provider, and uses a TransactionTranslator to turn JSON responses
|
58
58
|
into a list of transactions that the application understands.
|
59
59
|
|
60
|
-
class GetTransactions < ProviderInteraction
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
60
|
+
class GetTransactions < ProviderInteraction
|
61
|
+
def initialize(broker, substance)
|
62
|
+
discuss_with_broker_concerning(broker, "transactions")
|
63
|
+
about("<client_id>/transactions.json")
|
64
|
+
detailed_by(substance)
|
65
|
+
by_asking
|
66
|
+
end
|
67
67
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
end
|
68
|
+
def interpret_conversation(response)
|
69
|
+
return [] if response.code == '404'
|
70
|
+
TransactionTranslator::build_financial_entries_from(response)
|
71
|
+
end
|
72
|
+
end
|
73
73
|
|
74
74
|
Generically, the provider interaction knows how to say and ask the provider for information:
|
75
75
|
|
76
|
-
class ProviderInteraction < Interaction
|
77
|
-
|
78
|
-
|
79
|
-
|
76
|
+
class ProviderInteraction < Interaction
|
77
|
+
def ask
|
78
|
+
@conversation.ask(broker.prepare_content(@concern, @action), broker.generate_parameters(@substance))
|
79
|
+
end
|
80
80
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
end
|
81
|
+
def say
|
82
|
+
@conversation.say(broker.prepare_content(@concern, @action), broker.generate_parameters(@substance))
|
83
|
+
end
|
84
|
+
end
|
85
85
|
|
86
86
|
The ProviderBroker is taught how to talk the provider's language by using an HTMLConversation:
|
87
87
|
|
88
|
-
class ProviderBroker < Broker
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
end
|
88
|
+
class ProviderBroker < Broker
|
89
|
+
attr_accessor :host
|
90
|
+
attr_accessor :port
|
91
|
+
attr_accessor :username
|
92
|
+
attr_accessor :password
|
93
|
+
|
94
|
+
def initialize(host, port , username, password)
|
95
|
+
@version = "v1"
|
96
|
+
@host = host
|
97
|
+
@port = port
|
98
|
+
@username = username
|
99
|
+
@password = password
|
100
|
+
end
|
101
|
+
|
102
|
+
def broker_conversation(topic)
|
103
|
+
conversation = HTMLConversation.new(topic)
|
104
|
+
conversation.username = @username
|
105
|
+
conversation.password = @password
|
106
|
+
conversation
|
107
|
+
end
|
108
|
+
|
109
|
+
def open_topic(concern, action)
|
110
|
+
"https://#{@host}:#{@port}/" + concern + "/" + action
|
111
|
+
end
|
112
|
+
|
113
|
+
def prepare_content(concern, action)
|
114
|
+
"/" + concern + "/" + action;
|
115
|
+
end
|
116
|
+
end
|
117
117
|
|
118
118
|
The application, a dependency injector or a factory at some point decides to use the ProviderBroker to facilitate
|
119
119
|
interaction with the provider:
|
data/lib/converse/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: converse
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 8
|
10
|
+
version: 1.0.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ernst van Graan
|