hub_client 0.0.4 → 0.0.5
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 +8 -8
- data/README.md +17 -2
- data/lib/hub_client/configuration.rb +1 -1
- data/lib/hub_client/version.rb +2 -1
- data/lib/hub_client.rb +8 -2
- data/spec/hub_client_spec.rb +14 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZmQ1ODYzMzA0ZDczOThmNjgyOTE1MzdmNTM5NTBlYTg1NDg4ZGJmNw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YmU4YzdmNWIxNGU5N2MwN2E4ZmYwOTQ0NWY5MjdjYWM3ODJiNzU3Ng==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZjZhNDMyMmJkYjg5ZDZmODFhYmZhZDNkZjA0N2I3NDI5NjI0YWQ2MDZhNTY4
|
10
|
+
NTM0ZThmMmRjNzZjMjYwMzExMDFlZmQ4MGYyNTkzMzRiMWFjMjFjZDM2NDk0
|
11
|
+
NTg5MjY3NDMwNDgzMWEyYWNkMTQzMjBkYWU2ZGM1ZGUzYWY5MTk=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MjljMjUyMzU5MDMxYzFjZWZhNWZjZjgxZmM1OGIzYzFiZmRhMmRiZmYxNmVj
|
14
|
+
OGRjMjllMzg2MDY0ZjRjODE0OTliMjE2MDg5YmIzNzdjZDc0MmVkZDdhYmYx
|
15
|
+
YzQwZDNmODliNDY2Yjk1ZWExOGVjNjcwOTIwNDBlNTJlMjQ2ODM=
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# HubClient
|
2
2
|
|
3
|
-
|
3
|
+
Service hub client
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -18,7 +18,22 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
First let's create initializer file and configure the client:
|
22
|
+
```ruby
|
23
|
+
HubClient.configure do |config|
|
24
|
+
config.env = "IL" # Optional
|
25
|
+
config.endpoint_url = "http://user:pass@hub.com" # scheme://host:port
|
26
|
+
config.access_token = "token" # Optional
|
27
|
+
end
|
28
|
+
```
|
29
|
+
|
30
|
+
To publish any message to the hub:
|
31
|
+
```ruby
|
32
|
+
HubClient.publish('message', { pay: "load" })
|
33
|
+
```
|
34
|
+
|
35
|
+
### Hub API version remark
|
36
|
+
You can set the service hub api version by change the HUB_VERSION const
|
22
37
|
|
23
38
|
## Contributing
|
24
39
|
|
data/lib/hub_client/version.rb
CHANGED
data/lib/hub_client.rb
CHANGED
@@ -9,18 +9,24 @@ module HubClient
|
|
9
9
|
raise ConfigArgumentMissing, "env missing" unless HubClient.configuration.env
|
10
10
|
|
11
11
|
payload = { type: type, env: HubClient.configuration.env, content: content.to_json }
|
12
|
+
hub_url = build_hub_url(HubClient.configuration.endpoint_url)
|
12
13
|
|
13
|
-
RestClient.post(
|
14
|
+
RestClient.post(hub_url, payload, content_type: :json) do |response, request, result|
|
14
15
|
handle_response(response, request, result)
|
15
16
|
end
|
16
17
|
end
|
17
18
|
|
18
19
|
private
|
19
20
|
|
21
|
+
def self.build_hub_url(endpoint_url)
|
22
|
+
endpoint_url = endpoint_url.gsub(/\/$/, '') # remove last '/' if exists
|
23
|
+
"#{endpoint_url}/api/#{HUB_VERSION}/messages"
|
24
|
+
end
|
25
|
+
|
20
26
|
def self.handle_response(response, request, result)
|
21
27
|
# When request didn't succeed we log it
|
22
28
|
unless result.code.start_with?("2")
|
23
|
-
HubClient.logger.info("Code: #{result.code} Response: #{response} Request: #{request.args}")
|
29
|
+
HubClient.logger.info("HubClient Code: #{result.code} Response: #{response} Request: #{request.args}")
|
24
30
|
end
|
25
31
|
end
|
26
32
|
|
data/spec/hub_client_spec.rb
CHANGED
@@ -21,30 +21,39 @@ describe HubClient do
|
|
21
21
|
before(:all) do
|
22
22
|
HubClient.configure do |config|
|
23
23
|
config.env = "il-qa2"
|
24
|
-
config.endpoint_url = "service-hub.com"
|
24
|
+
config.endpoint_url = "http://service-hub.com"
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
28
|
it "publishes a message to hub" do
|
29
|
-
stub_request(:post, HubClient.configuration.endpoint_url).
|
29
|
+
stub_request(:post, HubClient.build_hub_url(HubClient.configuration.endpoint_url)).
|
30
30
|
with(body: { env: "il-qa2", type: "order_created", content: { some: "content" }.to_json }).
|
31
31
|
to_return(status: 204)
|
32
32
|
|
33
33
|
HubClient.publish(:order_created, { some: "content" })
|
34
|
-
assert_requested :post, HubClient.configuration.endpoint_url
|
34
|
+
assert_requested :post, HubClient.build_hub_url(HubClient.configuration.endpoint_url)
|
35
35
|
end
|
36
36
|
|
37
37
|
it "logs the request when hub didn't return success code" do
|
38
|
-
stub_request(:post, HubClient.configuration.endpoint_url).
|
38
|
+
stub_request(:post, HubClient.build_hub_url(HubClient.configuration.endpoint_url)).
|
39
39
|
with(body: { env: "il-qa2", type: "order_created", content: { some: "content" }.to_json }).
|
40
40
|
to_return(status: 500)
|
41
41
|
|
42
42
|
expect(HubClient.logger).to receive(:info)
|
43
43
|
HubClient.publish(:order_created, { some: "content" })
|
44
|
-
assert_requested :post, HubClient.configuration.endpoint_url
|
44
|
+
assert_requested :post, HubClient.build_hub_url(HubClient.configuration.endpoint_url)
|
45
45
|
end
|
46
46
|
|
47
47
|
after(:all) { HubClient.reset_configuration }
|
48
48
|
end
|
49
49
|
end
|
50
|
+
|
51
|
+
describe "#build_hub_url" do
|
52
|
+
it "returns url according to the version" do
|
53
|
+
stub_const("HubClient::HUB_VERSION", "v10")
|
54
|
+
|
55
|
+
expect(HubClient.send(:build_hub_url, "http://google.com")).to eq("http://google.com/api/v10/messages")
|
56
|
+
expect(HubClient.send(:build_hub_url, "http://google.com/")).to eq("http://google.com/api/v10/messages")
|
57
|
+
end
|
58
|
+
end
|
50
59
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hub_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yarin Goldman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|