happi 0.1.0 → 0.2.0

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
  SHA1:
3
- metadata.gz: c253d43249392dcece9180d9df4016fb24fb9703
4
- data.tar.gz: 8ecf4749f3d5e4f5a835405daee249ed431326c4
3
+ metadata.gz: 9dbbe19b69447b59fcdffc793300f8058b61d87e
4
+ data.tar.gz: 1551a9532ba36b03ead3746239880e90eee83ccb
5
5
  SHA512:
6
- metadata.gz: 7edea26416999669e165e569290b1d171c2194d81acf5b3ae0247115218259cc37a0182da22fc30879385e45f6f5a593feb195e3bb49afe5d71f9e8b84ecafd6
7
- data.tar.gz: 6be9fbded9eb24829e0f310c7cee85553667e27e31ed7b666f23b8082b21b34a709282911418130093199d5c66839816f3f1114678184533f9e58514006940ef
6
+ metadata.gz: 7812c0d9fc728a44e021a95914be86d03dce8e65136748258e3620c4e916d2916796a068e1f7eb947a49b897daac60cd2fc58cb9eb1ba68f866a31bad0c9e40e
7
+ data.tar.gz: b34a4009a5fed72e54209ae705ef770ada24d74cd07c83aff7074252b45953ab37a7501a472e6cd9501470d5bdd6def8f0965918471422318e4fae2272b5d701
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Happi
2
2
 
3
- Happi - preconfigured faraday client
3
+ Happi is a pre-configured Faraday client designed for easy access to RESTful
4
+ HTTP APIs. It assumes URLS of the form `https://hostname.com/api/v1/something`.
4
5
 
5
6
  ## Installation
6
7
 
@@ -12,61 +13,80 @@ And then execute:
12
13
 
13
14
  $ bundle
14
15
 
15
- Or install it yourself as:
16
+ ## Usage
16
17
 
17
- $ gem install happi
18
+ Happi stores its configuration as class-level state, so it's important to
19
+ derive your own client from `Happi::Client` rather than using it directly,
20
+ which can cause requests to be sent to the wrong endpoint.
18
21
 
19
- ## Usage
22
+ ```ruby
23
+ require 'happi'
20
24
 
21
- require 'happi'
25
+ class MyClient < Happi::Client
26
+ end
22
27
 
23
- Happi::Client.configure do |config|
24
- config.host = 'http://localhost:3000'
25
- end
28
+ MyClient.configure do |config|
29
+ config.host = 'http://localhost:3000'
30
+ end
26
31
 
27
- client = Happi::Client.new(
28
- oauth_token: '63ba06720acf97959f5ba3e3fe1020bf69a7596e2fe3091f821a35cdfe615ceb')
32
+ client = Myclient.new(
33
+ oauth_token: '63ba06720acf97959f5ba3e3fe1020bf69a7596e2fe3091f821a35cdfe615ceb')
29
34
 
30
- templates = client.get('templates')[:templates]
31
- templates.each do |template|
32
- puts template[:name]
33
- end
35
+ templates = client.get('templates')[:templates]
36
+ templates.each do |template|
37
+ puts template[:name]
38
+ end
34
39
 
35
- response = client.post('templates', template: {name: 'test',
36
- file: Happi::File.new(File.join(File.dirname(__FILE__), 'spec/fixtures/award.docx')) } )
37
- template = response[:template]
40
+ response = client.post('templates', template: {name: 'test',
41
+ file: Happi::File.new(File.join(File.dirname(__FILE__), 'spec/fixtures/award.docx')) } )
42
+ template = response[:template]
38
43
 
39
- templates = client.get('templates')[:templates]
40
- template = client.get('templates/1')[:template]
44
+ templates = client.get('templates')[:templates]
45
+ template = client.get('templates/1')[:template]
41
46
 
42
- template = client.patch("templates/#{template[:id]}",
43
- template: {id: template[:id],
44
- name: 'test' }
45
- )[:template]
47
+ template = client.patch("templates/#{template[:id]}",
48
+ template: {id: template[:id],
49
+ name: 'test' }
50
+ )[:template]
46
51
 
47
- client.get('documents')[:documents].each do |document|
48
- puts document[:name]
49
- end
52
+ client.get('documents')[:documents].each do |document|
53
+ puts document[:name]
54
+ end
50
55
 
51
- document = client.post('documents',
52
- document: {template_id: template[:id],
53
- name: 'Test Document',
54
- params: JSON.dump({name: 'Test'}) } )[:document]
56
+ document = client.post('documents',
57
+ document: {template_id: template[:id],
58
+ name: 'Test Document',
59
+ params: JSON.dump({name: 'Test'}) } )[:document]
55
60
 
56
- puts document[:id]
61
+ puts document[:id]
62
+ ```
57
63
 
58
64
  ## Configuration
59
65
 
60
66
  ```ruby
61
- Happi::Client.configure do |config|
67
+ MyClient.configure do |config|
62
68
  config.host = 'http://localhost:8080'
63
69
  config.port = 443
64
70
  config.timeout = 60
65
71
  config.version = 'v1'
66
72
  config.use_json = false
73
+ config.log_level = :debug
67
74
  end
68
75
  ```
69
76
 
77
+ A class deriving from `Happi::Client` can be configured with the following
78
+ paramters:
79
+
80
+ - **config.host** - the hostname of the server
81
+ - **config.port** - the TCP port to which requests will be sent.
82
+ - **config.timeout** - the maximum time to allow requests to take.
83
+ - **config.version** - the API version to interpolate in the URL
84
+ - **config.use_json** - when `true`, encode requests as JSON, and intepret
85
+ responses as JSON.
86
+ - **config.log_level** - when set to `:debug`, will log full request bodies and
87
+ paramaters, but will only log URL otherwise. Be aware: setting this to `:debug`
88
+ in data-heavy applications can lead to very large log files.
89
+
70
90
  ## Contributing
71
91
 
72
92
  1. Fork it
@@ -1,12 +1,12 @@
1
1
  class Happi::Error < StandardError
2
- class ClientError < self
3
- attr_reader :response
2
+ attr_reader :response
4
3
 
5
- def initialize(msg = nil, response = nil)
6
- super(msg)
7
- @response = response
8
- end
4
+ def initialize(msg = nil, response = nil)
5
+ super(msg)
6
+ @response = response
7
+ end
9
8
 
9
+ class ClientError < self
10
10
  def message
11
11
  "A client error occurred"
12
12
  end
@@ -1,3 +1,3 @@
1
1
  module Happi
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -0,0 +1,19 @@
1
+ #!/bin/bash
2
+ set -e
3
+
4
+ REVISION=https://github.com/$BUILDBOX_PROJECT_SLUG/commit/$BUILDBOX_COMMIT
5
+
6
+ echo '--- setting ruby version'
7
+ rbenv local 2.1.5
8
+
9
+ echo '--- bundling'
10
+ bundle install -j $(nproc) --without development production --quiet
11
+
12
+ echo '--- running specs'
13
+ if bundle exec rspec; then
14
+ echo "[Successful] $BUILDBOX_PROJECT_SLUG - Build - $BUILDBOX_BUILD_URL - Commit - $REVISION" | hipchat_room_message -t $HIPCHAT_TOKEN -r $HIPCHAT_ROOM -f "Buildbox" -c "green"
15
+ else
16
+ echo "[Failed] Build $BUILDBOX_PROJECT_SLUG - Build - $BUILDBOX_BUILD_URL - Commit - $REVISION" | hipchat_room_message -t $HIPCHAT_TOKEN -r $HIPCHAT_ROOM -f "Buildbox" -c "red"
17
+ exit 1;
18
+ fi
19
+
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe Happi::Error do
4
+ describe '.new' do
5
+ context 'with 1 argument' do
6
+ let(:error) { Happi::Error.new('message') }
7
+ specify { expect(error.message).to eq('message') }
8
+ specify { expect(error.response).to be nil }
9
+ end
10
+
11
+ context 'with 2 arguments' do
12
+ let(:error) { Happi::Error.new('message', 'response') }
13
+ specify { expect(error.message).to eq('message') }
14
+ specify { expect(error.response).to eq('response') }
15
+ end
16
+ end
17
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: happi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John D'Agostino
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-03 00:00:00.000000000 Z
11
+ date: 2015-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -200,8 +200,10 @@ files:
200
200
  - lib/happi/error.rb
201
201
  - lib/happi/file.rb
202
202
  - lib/happi/version.rb
203
+ - script/buildkite.sh
203
204
  - spec/client_spec.rb
204
205
  - spec/configuration_spec.rb
206
+ - spec/error_spec.rb
205
207
  - spec/file_spec.rb
206
208
  - spec/fixtures/award.docx
207
209
  - spec/spec_helper.rb
@@ -232,6 +234,7 @@ summary: Simple faraday client wrapper preconfigured for specific usecase
232
234
  test_files:
233
235
  - spec/client_spec.rb
234
236
  - spec/configuration_spec.rb
237
+ - spec/error_spec.rb
235
238
  - spec/file_spec.rb
236
239
  - spec/fixtures/award.docx
237
240
  - spec/spec_helper.rb