happi 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
- metadata.gz: 6ab6180f7bd4996bbc905f7fd2469fcc70ccfa2a
4
- data.tar.gz: a2c1f4fcab04dd623e1880c85d48a4df9bc41762
3
+ metadata.gz: af8ba21871ab04a2984602e9d6abc4a50c015f5f
4
+ data.tar.gz: 23a6a877deca390eb84cce281e3c0401d964fa74
5
5
  SHA512:
6
- metadata.gz: 8cd2b01d91ea668c1fb3111c9f3a8f01ec8cafff30fdae63a252514ff75c03d7f47cd443361682dc8dc1b97b25e715695424b4736dd4a3bbf5b8b2992ceb3674
7
- data.tar.gz: 08ddc2c0c881a989ee72283412a85dd80d3adb247eece4202e9bdea55c00c633111e90f008141ec3773d52080f627acd11a30911db05ffc7d1943d9a120fb087
6
+ metadata.gz: 508d29a0c2bfafbf3482a5ecefe8ead014d21103636fc4ccd3d6e669ce597c5cd0aa302739ee7b39253d1e4de91004277d0511ddcac45519675531bf51ebaf3c
7
+ data.tar.gz: 4c655fd218d1e52ba81c9cb489eabca25a801b81cd782bcf804608f69fe93ade21f36a69670acbcd409a22fd44bc749d03df36a004997914eab00dedeeb9f044
data/README.md CHANGED
@@ -20,8 +20,11 @@ Or install it yourself as:
20
20
 
21
21
  require 'happi'
22
22
 
23
+ Happi::Client.configure do |config|
24
+ config.base_url = 'http://localhost:3000'
25
+ end
26
+
23
27
  client = Happi::Client.new(
24
- base_url: 'http://localhost:3000',
25
28
  oauth_token: '63ba06720acf97959f5ba3e3fe1020bf69a7596e2fe3091f821a35cdfe615ceb')
26
29
 
27
30
  templates = client.get('templates')[:templates]
data/lib/happi/client.rb CHANGED
@@ -4,22 +4,18 @@ require 'active_support/core_ext/string/inflections'
4
4
  require 'active_support/core_ext/hash'
5
5
 
6
6
  class Happi::Client
7
- DEFAULTS = {
8
- host: 'http://localhost:8080',
9
- port: 443,
10
- timeout: 60,
11
- version: 'v1'
12
- }
13
7
 
14
- attr_accessor :oauth_token, :host, :port, :timeout, :version
8
+ def self.config
9
+ @config ||= Happi::Configuration.new
10
+ end
15
11
 
16
- def initialize(options = {})
17
- DEFAULTS.merge(options).each do |key, value|
18
- send("#{key}=", value)
19
- end
12
+ def self.configure
13
+ yield config
14
+ end
20
15
 
21
- if block_given?
22
- yield
16
+ def initialize(options = {})
17
+ options.each do |key, value|
18
+ self.config.send("#{key}=", value)
23
19
  end
24
20
  end
25
21
 
@@ -77,9 +73,9 @@ class Happi::Client
77
73
  end
78
74
 
79
75
  def connection
80
- @connection ||= Faraday.new(host) do |f|
76
+ @connection ||= Faraday.new(self.config.host) do |f|
81
77
  f.request :multipart
82
- f.use FaradayMiddleware::OAuth2, oauth_token
78
+ f.use FaradayMiddleware::OAuth2, self.config.oauth_token
83
79
  f.use FaradayMiddleware::ParseJson, content_type: 'application/json'
84
80
  f.request :url_encoded
85
81
  f.adapter :net_http
@@ -0,0 +1,16 @@
1
+ class Happi::Configuration
2
+ DEFAULTS = {
3
+ host: 'http://localhost:8080',
4
+ port: 443,
5
+ timeout: 60,
6
+ version: 'v1'
7
+ }
8
+
9
+ attr_accessor :oauth_token, :host, :port, :timeout, :version
10
+
11
+ def initialize(options = {})
12
+ DEFAULTS.merge(options).each do |key, value|
13
+ send("#{key}=", value)
14
+ end
15
+ end
16
+ end
data/lib/happi/error.rb CHANGED
@@ -13,4 +13,29 @@ class Happi::Error < Exception
13
13
  class TooManyRequests < ServerError; end
14
14
  class ServiceUnavailable < ServerError; end
15
15
  class GatewayTimeout < ServerError; end
16
+
17
+ module ServiceableErrors
18
+ def self.included(serviceable)
19
+ serviceable.const_set :StandardError, Class.new(::NestedError)
20
+ serviceable.const_set :UserError, Class.new(serviceable::StandardError)
21
+ serviceable.const_set :LogicError, Class.new(serviceable::StandardError)
22
+ serviceable.const_set :InternalError, Class.new(serviceable::LogicError)
23
+ serviceable.const_set :ClientError, Class.new(serviceable::LogicError)
24
+ serviceable.const_set :TransientFailure, Class.new(serviceable::StandardError)
25
+ end
26
+
27
+ class NestedError < StandardError
28
+ attr_reader :original
29
+
30
+ def initialize(msg, original = $1)
31
+ super(original ? "#{msg} - #{original.message}" : msg)
32
+ @original = original
33
+ set_backtrace(@original.backtrace) if @original.present?
34
+ end
35
+
36
+ def original?
37
+ @original.nil?
38
+ end
39
+ end
40
+ end
16
41
  end
data/lib/happi/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Happi
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
data/lib/happi.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'happi/version'
2
2
  require 'happi/error'
3
+ require 'happi/configuration'
3
4
  require 'happi/client'
4
5
  require 'happi/file'
5
6
 
data/spec/client_spec.rb CHANGED
@@ -1,12 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Happi::Client do
4
-
5
- describe 'options' do
6
- specify { expect(Happi::Client.new(host: 'http://www.google.com').host).to eql('http://www.google.com') }
7
- specify { expect(Happi::Client.new(port: 80).port).to eql(80) }
8
- end
9
-
10
4
  describe 'call' do
11
5
 
12
6
  end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe Happi::Configuration do
4
+ describe 'options' do
5
+ specify { expect(Happi::Configuration.new(host: 'http://www.google.com').host).to eql('http://www.google.com') }
6
+ specify { expect(Happi::Configuration.new(port: 80).port).to eql(80) }
7
+ end
8
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: happi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - John D'Agostino
@@ -193,10 +193,12 @@ files:
193
193
  - happi.gemspec
194
194
  - lib/happi.rb
195
195
  - lib/happi/client.rb
196
+ - lib/happi/configuration.rb
196
197
  - lib/happi/error.rb
197
198
  - lib/happi/file.rb
198
199
  - lib/happi/version.rb
199
200
  - spec/client_spec.rb
201
+ - spec/configuration_spec.rb
200
202
  - spec/file_spec.rb
201
203
  - spec/fixtures/award.docx
202
204
  - spec/spec_helper.rb
@@ -226,6 +228,7 @@ specification_version: 4
226
228
  summary: Simple faraday client wrapper preconfigured for specific usecase
227
229
  test_files:
228
230
  - spec/client_spec.rb
231
+ - spec/configuration_spec.rb
229
232
  - spec/file_spec.rb
230
233
  - spec/fixtures/award.docx
231
234
  - spec/spec_helper.rb