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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OWRlZmRiZDgzOGU1NDM4MGQ0ZDM4NjBkYzhkNWMzMWVhMTFhNzI3Ng==
4
+ ZmQ1ODYzMzA0ZDczOThmNjgyOTE1MzdmNTM5NTBlYTg1NDg4ZGJmNw==
5
5
  data.tar.gz: !binary |-
6
- MzQzNzU4NTZjNDZjNTc2ZjQ1YTJiNGQzYzAwZjQ3MDZhZjFjOWFhMg==
6
+ YmU4YzdmNWIxNGU5N2MwN2E4ZmYwOTQ0NWY5MjdjYWM3ODJiNzU3Ng==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MzM4NTU1ODhlOTFkOWU2NTQ0OGU4ZDA3MTUzMDdhYzk3ZWM4ZjhlMjJiOTFm
10
- NTU1Y2Q0NzVmN2VlM2UwMzc4NTQ4MzI4ODc2ODQ2ZDJhNmFhZWY4ZDcwZWFk
11
- NGRjNWU1NjM0Yjg0YTJlMjFmMDBhYTU2MTZmOWI4MTRmNTVjNjc=
9
+ ZjZhNDMyMmJkYjg5ZDZmODFhYmZhZDNkZjA0N2I3NDI5NjI0YWQ2MDZhNTY4
10
+ NTM0ZThmMmRjNzZjMjYwMzExMDFlZmQ4MGYyNTkzMzRiMWFjMjFjZDM2NDk0
11
+ NTg5MjY3NDMwNDgzMWEyYWNkMTQzMjBkYWU2ZGM1ZGUzYWY5MTk=
12
12
  data.tar.gz: !binary |-
13
- MGI3NzNiNGU2OWJkYWQ1MzQ5NjMwZTE4N2NlYjI1NWVmOGRkNzUxZWUzY2Mx
14
- NzhmOTM4N2VlNGY0ZjBlMDNkMDAyZTM4NTM4NGEzY2EwNjlkY2Q1YWI3N2I0
15
- NGU4NzVlODIwNDJmNDNhZDMxZTZiMTBiN2M2NWExMzNhM2RiZWE=
13
+ MjljMjUyMzU5MDMxYzFjZWZhNWZjZjgxZmM1OGIzYzFiZmRhMmRiZmYxNmVj
14
+ OGRjMjllMzg2MDY0ZjRjODE0OTliMjE2MDg5YmIzNzdjZDc0MmVkZDdhYmYx
15
+ YzQwZDNmODliNDY2Yjk1ZWExOGVjNjcwOTIwNDBlNTJlMjQ2ODM=
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # HubClient
2
2
 
3
- TODO: Write a gem description
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
- TODO: Write usage instructions here
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
 
@@ -1,6 +1,6 @@
1
1
  module HubClient
2
2
  class Configuration
3
- attr_accessor :env, :access_token, :endpoint_url, :http_auth
3
+ attr_accessor :env, :access_token, :endpoint_url
4
4
  end
5
5
 
6
6
  def self.configuration
@@ -1,3 +1,4 @@
1
1
  module HubClient
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
+ HUB_VERSION = "v1"
3
4
  end
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(HubClient.configuration.endpoint_url, payload, content_type: :json) do |response, request, result|
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
 
@@ -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
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-06 00:00:00.000000000 Z
11
+ date: 2014-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client