hub_client 0.0.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 ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ODFiNjgyMzhmM2UwMWE0OTNmMGYzZTRlZTM0OGMyYjZlMjhjOWZiYQ==
5
+ data.tar.gz: !binary |-
6
+ OTI3NTU0MDEwMTg5ZDg2ZTUyNTU3YTEyYjk1NDVkOGVmOTBjMjJhYQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MTc3YTg4NWQ3YmM2MjUzMTk4ZGYxMTJjMzk4YzZhYTU0NTUyZDE1NzE4NmM0
10
+ YzRkMDdiMTNmNWI5NmI0ODMwYmU5M2U2N2U2MzljMDZlMjZlNWU2M2ZhMTkx
11
+ YzI3YTRhZjJhYWU4Y2Y3YTY5NWUzNGRmNjhmODc1Nzc3YTZjZTA=
12
+ data.tar.gz: !binary |-
13
+ ZjFhNWE4YjBkNGE2ODkwMGRmNGU2NWJhOGFlMDkwMzkxZmI1ZDYxYWQ3Y2E2
14
+ MmJlNGM1MGRiNDA3NjVhZmZhMzBiZjBkODJlZGJiOTJiYmJiMTBiNGQwYjZh
15
+ MzQ4ZmE1ZGNiZGJlYmY1MGVhZjMyOGY4OTcyNmY4NzNlNTQ3NzQ=
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ .idea
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hub_client.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Yarin Goldman
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # HubClient
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'hub_client'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install hub_client
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/<my-github-username>/hub_client/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hub_client/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "hub_client"
8
+ spec.version = HubClient::VERSION
9
+ spec.authors = ["Yarin Goldman"]
10
+ spec.email = ["yarin@gettaxi.com"]
11
+ spec.summary = %q{Ruby SDK for service hub}
12
+ spec.description = %q{Ruby SDK for service hub}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "rest-client"
22
+ spec.add_development_dependency "bundler", "~> 1.5"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "rspec"
25
+ spec.add_development_dependency "webmock"
26
+ spec.add_development_dependency "pry"
27
+ end
@@ -0,0 +1,21 @@
1
+ module HubClient
2
+ class Configuration
3
+ attr_accessor :env, :access_token, :endpoint_url
4
+ end
5
+
6
+ def self.configuration
7
+ @configuration ||= Configuration.new
8
+ end
9
+
10
+ def self.configuration=(config)
11
+ @configuration = config
12
+ end
13
+
14
+ def self.reset_configuration
15
+ @configuration = Configuration.new
16
+ end
17
+
18
+ def self.configure
19
+ yield(configuration) if block_given?
20
+ end
21
+ end
@@ -0,0 +1,13 @@
1
+ module HubClient
2
+ class Logger
3
+ def method_missing(method_sym, *args, &block)
4
+ if defined?(Rails)
5
+ Rails.logger.send(method_sym, args)
6
+ end
7
+ end
8
+ end
9
+
10
+ def self.logger
11
+ @logger ||= Logger.new
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module HubClient
2
+ VERSION = "0.0.1"
3
+ end
data/lib/hub_client.rb ADDED
@@ -0,0 +1,28 @@
1
+ require "hub_client/configuration"
2
+ require "hub_client/logger"
3
+ require "hub_client/version"
4
+ require "rest-client"
5
+
6
+ module HubClient
7
+ def self.publish(type, content)
8
+ raise ConfigArgumentMissing, "endpoint_url missing" unless HubClient.configuration.endpoint_url
9
+ raise ConfigArgumentMissing, "env missing" unless HubClient.configuration.env
10
+
11
+ payload = { type: type, env: HubClient.configuration.env, content: content }
12
+
13
+ RestClient.post(HubClient.configuration.endpoint_url, payload) do |response, request, result|
14
+ handle_response(result, request)
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def self.handle_response(result, request)
21
+ # When request didn't succeed we log it
22
+ unless result.code.start_with?("2")
23
+ HubClient.logger.info(request.args)
24
+ end
25
+ end
26
+
27
+ class ConfigArgumentMissing < StandardError; end
28
+ end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+ require 'hub_client'
3
+
4
+ describe HubClient do
5
+ describe "#publish" do
6
+ context "not configured" do
7
+ after(:each) { HubClient.reset_configuration }
8
+
9
+ it "raises an error when endpoint_url is not configured" do
10
+ HubClient.configure { |config| config.env = "il-qa2" }
11
+ expect { HubClient.publish("order_created", {}) }.to raise_error(HubClient::ConfigArgumentMissing)
12
+ end
13
+
14
+ it "raises an error when env is not configured" do
15
+ HubClient.configure { |config| config.endpoint_url = "service-hub.com" }
16
+ expect { HubClient.publish("order_created", {}) }.to raise_error(HubClient::ConfigArgumentMissing)
17
+ end
18
+ end
19
+
20
+ context "configured" do
21
+ before(:all) do
22
+ HubClient.configure do |config|
23
+ config.env = "il-qa2"
24
+ config.endpoint_url = "service-hub.com"
25
+ end
26
+ end
27
+
28
+ it "publishes a message to hub" do
29
+ stub_request(:post, HubClient.configuration.endpoint_url).
30
+ with(body: { env: "il-qa2", type: "order_created", content: { some: "content" } }).
31
+ to_return(status: 204)
32
+
33
+ HubClient.publish(:order_created, { some: "content" })
34
+ assert_requested :post, HubClient.configuration.endpoint_url
35
+ end
36
+
37
+ it "logs the request when hub didn't return success code" do
38
+ stub_request(:post, HubClient.configuration.endpoint_url).
39
+ with(body: { env: "il-qa2", type: "order_created", content: { some: "content" } }).
40
+ to_return(status: 500)
41
+
42
+ expect(HubClient.logger).to receive(:info)
43
+ HubClient.publish(:order_created, { some: "content" })
44
+ assert_requested :post, HubClient.configuration.endpoint_url
45
+ end
46
+
47
+ after(:all) { HubClient.reset_configuration }
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,14 @@
1
+ require 'webmock/rspec'
2
+ require 'pry'
3
+
4
+ RSpec.configure do |config|
5
+ config.treat_symbols_as_metadata_keys_with_true_values = true
6
+ config.run_all_when_everything_filtered = true
7
+ config.filter_run :focus
8
+
9
+ # Run specs in random order to surface order dependencies. If you find an
10
+ # order dependency and want to debug it, you can fix the order by providing
11
+ # the seed, which is printed after each run.
12
+ # --seed 1234
13
+ config.order = 'random'
14
+ end
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hub_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Yarin Goldman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Ruby SDK for service hub
98
+ email:
99
+ - yarin@gettaxi.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - .rspec
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - hub_client.gemspec
111
+ - lib/hub_client.rb
112
+ - lib/hub_client/configuration.rb
113
+ - lib/hub_client/logger.rb
114
+ - lib/hub_client/version.rb
115
+ - spec/hub_client_spec.rb
116
+ - spec/spec_helper.rb
117
+ homepage: ''
118
+ licenses:
119
+ - MIT
120
+ metadata: {}
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ! '>='
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ! '>='
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 2.3.0
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: Ruby SDK for service hub
141
+ test_files:
142
+ - spec/hub_client_spec.rb
143
+ - spec/spec_helper.rb