happi 0.0.5 → 0.0.10

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
- !binary "U0hBMQ==":
3
- metadata.gz: 7cbe7a33112d358c16c95b35ec410b82aaf65622
4
- data.tar.gz: 65d57b1a2230647d0246290ace7ae9a214667163
2
+ SHA1:
3
+ metadata.gz: b2bb971c27f9eb12858f5550f78a94552535bfb4
4
+ data.tar.gz: 61b0559144f1ff61208d18ee2a83e14ffdf7cf67
5
5
  SHA512:
6
- metadata.gz: 7836ce0c555cbbc9d9e49588dbb6f6b1d875256b98b60e6b2b1e75c62957bad3dde9ef7ed8ec488265c8bac084059d65578a1366e5ba8a431d31fc3b5a351c58
7
- data.tar.gz: 8be1620f866422be96752a44e657cea4ef2498a0e66862b89e718ddf1362c97bba613f37f2e5d171648592af7652419e38dc28d1227ae137705ac1f9487ca756
6
+ metadata.gz: dd301905b6ca4be9caa12f65e81059a59184e4321d8a419b5d499e12b91c59ea60efc990e95a0fe2e2315a8a070d28921f749c650547113c8d489d185f4665e8
7
+ data.tar.gz: d07674c69955338f41cc91f82ae991446bb887d7f1b190008f013985286a712f13ec5b4f9b1cdf4b5d508285c2de385d9107e9de09d5b703d2ee94a440a7d52d
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.1
4
+ - 2.0.0
5
+ gemfile:
6
+ - Gemfile.rails41
7
+ - Gemfile.rails32
8
+ - Gemfile
9
+ branches:
10
+ only:
11
+ - develop
12
+ - master
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in happi.gemspec
4
4
  gemspec
5
+
6
+ gem 'activesupport'
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'activesupport', '~> 3.2'
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'activesupport', '~> 4.1'
data/README.md CHANGED
@@ -21,7 +21,7 @@ Or install it yourself as:
21
21
  require 'happi'
22
22
 
23
23
  Happi::Client.configure do |config|
24
- config.base_url = 'http://localhost:3000'
24
+ config.host = 'http://localhost:3000'
25
25
  end
26
26
 
27
27
  client = Happi::Client.new(
@@ -55,6 +55,18 @@ Or install it yourself as:
55
55
 
56
56
  puts document[:id]
57
57
 
58
+ ## Configuration
59
+
60
+ ```ruby
61
+ Happi::Client.configure do |config|
62
+ config.host = 'http://localhost:8080'
63
+ config.port = 443
64
+ config.timeout = 60
65
+ config.version = 'v1'
66
+ config.use_json = false
67
+ end
68
+ ```
69
+
58
70
  ## Contributing
59
71
 
60
72
  1. Fork it
@@ -20,7 +20,6 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_dependency 'faraday'
22
22
  spec.add_dependency 'faraday_middleware'
23
- spec.add_dependency 'activesupport'
24
23
  spec.add_dependency 'activemodel'
25
24
  spec.add_dependency 'oauth2'
26
25
  spec.add_dependency 'mime-types'
@@ -31,4 +30,5 @@ Gem::Specification.new do |spec|
31
30
  spec.add_development_dependency 'cane'
32
31
  spec.add_development_dependency 'rake'
33
32
  spec.add_development_dependency 'rspec'
33
+ spec.add_development_dependency 'rack-test'
34
34
  end
@@ -4,8 +4,7 @@ require 'active_support/core_ext/string/inflections'
4
4
  require 'active_support/core_ext/hash'
5
5
 
6
6
  class Happi::Client
7
-
8
- delegate :config, to: :class
7
+ delegate :config, to: self
9
8
 
10
9
  def self.config
11
10
  @config ||= Happi::Configuration.new
@@ -26,6 +25,11 @@ class Happi::Client
26
25
  .body.with_indifferent_access
27
26
  end
28
27
 
28
+ def delete(resource, params = {})
29
+ call(:delete, url(resource), param_check(params))
30
+ .body.with_indifferent_access
31
+ end
32
+
29
33
  def patch(resource, params = {})
30
34
  call(:patch, url(resource), param_check(params))
31
35
  .body.with_indifferent_access
@@ -41,7 +45,12 @@ class Happi::Client
41
45
  end
42
46
 
43
47
  def call(method, url, params)
44
- logger.info("#{method}, #{url}, #{params}")
48
+ if config.log_level == :debug
49
+ logger.debug("Happi: #{method.upcase} #{config.host}#{url}, #{params}")
50
+ else
51
+ logger.info("Happi: #{method.upcase} #{config.host}#{url}")
52
+ end
53
+
45
54
  response = connection.send(method, url, params)
46
55
  raise_error(response) if errors[response.status]
47
56
  response
@@ -58,7 +67,15 @@ class Happi::Client
58
67
  end
59
68
 
60
69
  def logger
61
- @logger ||= Logger.new(STDOUT)
70
+ @logger ||= default_logger
71
+ end
72
+
73
+ def default_logger
74
+ if defined?(Rails)
75
+ Rails.try(:logger) || Logger.new(STDOUT)
76
+ else
77
+ Logger.new(STDOUT)
78
+ end
62
79
  end
63
80
 
64
81
  def param_check(params)
@@ -75,10 +92,18 @@ class Happi::Client
75
92
 
76
93
  def connection
77
94
  @connection ||= Faraday.new(config.host) do |f|
78
- f.request :multipart
79
95
  f.use FaradayMiddleware::OAuth2, config.oauth_token
80
96
  f.use FaradayMiddleware::ParseJson, content_type: 'application/json'
81
- f.request :url_encoded
97
+
98
+ if self.config.use_json
99
+ f.use FaradayMiddleware::EncodeJson
100
+ f.request :json
101
+ f.response :json
102
+ else
103
+ f.request :multipart
104
+ f.request :url_encoded
105
+ end
106
+
82
107
  f.adapter :net_http
83
108
  end
84
109
  end
@@ -4,11 +4,13 @@ class Happi::Configuration
4
4
  host: 'http://localhost:8080',
5
5
  port: 443,
6
6
  timeout: 60,
7
- version: 'v1'
7
+ version: 'v1',
8
+ use_json: false,
9
+ log_level: :info
8
10
  }
9
11
  end
10
12
 
11
- attr_accessor :oauth_token, :host, :port, :timeout, :version
13
+ attr_accessor :oauth_token, :host, :port, :timeout, :version, :use_json, :log_level
12
14
 
13
15
  def initialize(options = {})
14
16
  self.class.defaults.merge(options).each do |key, value|
@@ -1,13 +1,58 @@
1
1
  class Happi::Error < Exception
2
- class ClientError < self; end
3
- class BadRequest < ClientError; end
4
- class Unauthorized < ClientError; end
5
- class Forbidden < ClientError; end
6
- class NotFound < ClientError; end
7
- class NotAcceptable < ClientError; end
8
- class RequestTimeout < ClientError; end
9
- class UnprocessableEntity < ClientError; end
10
- class ServerError < self; end
2
+ class ClientError < self
3
+ def message
4
+ "A client error occurred"
5
+ end
6
+ end
7
+
8
+ class BadRequest < ClientError
9
+ def message
10
+ "The request was incorrectly performed"
11
+ end
12
+ end
13
+
14
+ class Unauthorized < ClientError
15
+ def message
16
+ "The request was not authorized"
17
+ end
18
+ end
19
+
20
+ class Forbidden < ClientError
21
+ def message
22
+ "The request was denied"
23
+ end
24
+ end
25
+
26
+ class NotFound < ClientError
27
+ def message
28
+ "The requested resource was not found"
29
+ end
30
+ end
31
+
32
+ class NotAcceptable < ClientError
33
+ def message
34
+ "The requested format was not accepted"
35
+ end
36
+ end
37
+
38
+ class RequestTimeout < ClientError
39
+ def message
40
+ "The request timed out"
41
+ end
42
+ end
43
+
44
+ class UnprocessableEntity < ClientError
45
+ def message
46
+ "The request was not able to be processed"
47
+ end
48
+ end
49
+
50
+ class ServerError < self
51
+ def message
52
+ "A server error occurred"
53
+ end
54
+ end
55
+
11
56
  class InternalServerError < ServerError; end
12
57
  class BadGateway < ServerError; end
13
58
  class TooManyRequests < ServerError; end
@@ -2,9 +2,16 @@ require 'mime/types'
2
2
 
3
3
  class Happi::File
4
4
  attr_accessor :file_name
5
+ attr_accessor :mime_type
5
6
 
6
- def initialize(file_name)
7
- @file_name = file_name
7
+ def initialize(file)
8
+ if file.is_a?(String)
9
+ @mime_type = MIME::Types.type_for(file).first.content_type
10
+ @file_name = file
11
+ else
12
+ @mime_type = file.content_type
13
+ @file_name = file.path
14
+ end
8
15
  end
9
16
 
10
17
  def exists?
@@ -15,10 +22,6 @@ class Happi::File
15
22
  Faraday::UploadIO.new(file_name, mime_type) if exists?
16
23
  end
17
24
 
18
- def mime_type
19
- MIME::Types.type_for(file_name).first.content_type
20
- end
21
-
22
25
  def encode_file
23
26
  Base64.encode64(File.read(file_name))
24
27
  end
@@ -1,3 +1,3 @@
1
1
  module Happi
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.10'
3
3
  end
@@ -4,5 +4,10 @@ describe Happi::Configuration do
4
4
  describe 'options' do
5
5
  specify { expect(Happi::Configuration.new(host: 'http://www.google.com').host).to eql('http://www.google.com') }
6
6
  specify { expect(Happi::Configuration.new(port: 80).port).to eql(80) }
7
+
8
+ specify do
9
+ Happi::Client.configure { |config| config.host = 'http://localhost:3000' }
10
+ expect(Happi::Client.config.host).to eq 'http://localhost:3000'
11
+ end
7
12
  end
8
13
  end
@@ -1,22 +1,46 @@
1
1
  require 'spec_helper'
2
+ require 'rack/test'
2
3
 
3
4
  describe Happi::File do
4
- subject { Happi::File.new(__FILE__) }
5
+ context "with a file name" do
6
+ subject { Happi::File.new(__FILE__) }
5
7
 
6
- describe '#encode_file' do
7
- encoded = Base64.encode64(File.read(__FILE__))
8
- specify { expect(subject.encode_file).to eql(encoded) }
9
- end
8
+ describe '#encode_file' do
9
+ encoded = Base64.encode64(File.read(__FILE__))
10
+ specify { expect(subject.encode_file).to eql(encoded) }
11
+ end
10
12
 
11
- describe '#mime_type' do
12
- specify { expect(subject.mime_type).to eql('application/x-ruby') }
13
- end
13
+ describe '#mime_type' do
14
+ specify { expect(subject.mime_type).to eql('application/x-ruby') }
15
+ end
14
16
 
15
- describe '#multipart' do
16
- # specify { expect(subject.multipart).to }
17
+ describe '#multipart' do
18
+ # specify { expect(subject.multipart).to }
19
+ end
20
+
21
+ describe '#exists?' do
22
+ specify { expect(subject.exists?).to eq(true) }
23
+ end
17
24
  end
18
25
 
19
- describe '#exists?' do
20
- specify { expect(subject.exists?).to be_true }
26
+ context "with an ActionDispatch::Http::UploadedFile" do
27
+ subject { Happi::File.new(Rack::Test::UploadedFile.new(__FILE__, 'application/x-ruby')) }
28
+
29
+ describe '#encode_file' do
30
+ encoded = Base64.encode64(File.read(__FILE__))
31
+ specify { expect(subject.encode_file).to eql(encoded) }
32
+ end
33
+
34
+ describe '#mime_type' do
35
+ specify { expect(subject.mime_type).to eql('application/x-ruby') }
36
+ end
37
+
38
+ describe '#multipart' do
39
+ # specify { expect(subject.multipart).to }
40
+ end
41
+
42
+ describe '#exists?' do
43
+ specify { expect(subject.exists?).to eq(true) }
44
+ end
21
45
  end
22
46
  end
metadata CHANGED
@@ -1,181 +1,181 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: happi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.10
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: 2014-06-12 00:00:00.000000000 Z
11
+ date: 2015-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: faraday_middleware
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: activesupport
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ! '>='
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ! '>='
38
+ - - ">="
53
39
  - !ruby/object:Gem::Version
54
40
  version: '0'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: activemodel
57
43
  requirement: !ruby/object:Gem::Requirement
58
44
  requirements:
59
- - - ! '>='
45
+ - - ">="
60
46
  - !ruby/object:Gem::Version
61
47
  version: '0'
62
48
  type: :runtime
63
49
  prerelease: false
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
51
  requirements:
66
- - - ! '>='
52
+ - - ">="
67
53
  - !ruby/object:Gem::Version
68
54
  version: '0'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: oauth2
71
57
  requirement: !ruby/object:Gem::Requirement
72
58
  requirements:
73
- - - ! '>='
59
+ - - ">="
74
60
  - !ruby/object:Gem::Version
75
61
  version: '0'
76
62
  type: :runtime
77
63
  prerelease: false
78
64
  version_requirements: !ruby/object:Gem::Requirement
79
65
  requirements:
80
- - - ! '>='
66
+ - - ">="
81
67
  - !ruby/object:Gem::Version
82
68
  version: '0'
83
69
  - !ruby/object:Gem::Dependency
84
70
  name: mime-types
85
71
  requirement: !ruby/object:Gem::Requirement
86
72
  requirements:
87
- - - ! '>='
73
+ - - ">="
88
74
  - !ruby/object:Gem::Version
89
75
  version: '0'
90
76
  type: :runtime
91
77
  prerelease: false
92
78
  version_requirements: !ruby/object:Gem::Requirement
93
79
  requirements:
94
- - - ! '>='
80
+ - - ">="
95
81
  - !ruby/object:Gem::Version
96
82
  version: '0'
97
83
  - !ruby/object:Gem::Dependency
98
84
  name: multi_json
99
85
  requirement: !ruby/object:Gem::Requirement
100
86
  requirements:
101
- - - ! '>='
87
+ - - ">="
102
88
  - !ruby/object:Gem::Version
103
89
  version: '0'
104
90
  type: :runtime
105
91
  prerelease: false
106
92
  version_requirements: !ruby/object:Gem::Requirement
107
93
  requirements:
108
- - - ! '>='
94
+ - - ">="
109
95
  - !ruby/object:Gem::Version
110
96
  version: '0'
111
97
  - !ruby/object:Gem::Dependency
112
98
  name: bundler
113
99
  requirement: !ruby/object:Gem::Requirement
114
100
  requirements:
115
- - - ~>
101
+ - - "~>"
116
102
  - !ruby/object:Gem::Version
117
103
  version: '1.3'
118
104
  type: :development
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
107
  requirements:
122
- - - ~>
108
+ - - "~>"
123
109
  - !ruby/object:Gem::Version
124
110
  version: '1.3'
125
111
  - !ruby/object:Gem::Dependency
126
112
  name: simplecov
127
113
  requirement: !ruby/object:Gem::Requirement
128
114
  requirements:
129
- - - ! '>='
115
+ - - ">="
130
116
  - !ruby/object:Gem::Version
131
117
  version: '0'
132
118
  type: :development
133
119
  prerelease: false
134
120
  version_requirements: !ruby/object:Gem::Requirement
135
121
  requirements:
136
- - - ! '>='
122
+ - - ">="
137
123
  - !ruby/object:Gem::Version
138
124
  version: '0'
139
125
  - !ruby/object:Gem::Dependency
140
126
  name: cane
141
127
  requirement: !ruby/object:Gem::Requirement
142
128
  requirements:
143
- - - ! '>='
129
+ - - ">="
144
130
  - !ruby/object:Gem::Version
145
131
  version: '0'
146
132
  type: :development
147
133
  prerelease: false
148
134
  version_requirements: !ruby/object:Gem::Requirement
149
135
  requirements:
150
- - - ! '>='
136
+ - - ">="
151
137
  - !ruby/object:Gem::Version
152
138
  version: '0'
153
139
  - !ruby/object:Gem::Dependency
154
140
  name: rake
155
141
  requirement: !ruby/object:Gem::Requirement
156
142
  requirements:
157
- - - ! '>='
143
+ - - ">="
158
144
  - !ruby/object:Gem::Version
159
145
  version: '0'
160
146
  type: :development
161
147
  prerelease: false
162
148
  version_requirements: !ruby/object:Gem::Requirement
163
149
  requirements:
164
- - - ! '>='
150
+ - - ">="
165
151
  - !ruby/object:Gem::Version
166
152
  version: '0'
167
153
  - !ruby/object:Gem::Dependency
168
154
  name: rspec
169
155
  requirement: !ruby/object:Gem::Requirement
170
156
  requirements:
171
- - - ! '>='
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: rack-test
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
172
  - !ruby/object:Gem::Version
173
173
  version: '0'
174
174
  type: :development
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
- - - ! '>='
178
+ - - ">="
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0'
181
181
  description: Simple faraday client preconfigured
@@ -185,8 +185,11 @@ executables: []
185
185
  extensions: []
186
186
  extra_rdoc_files: []
187
187
  files:
188
- - .gitignore
188
+ - ".gitignore"
189
+ - ".travis.yml"
189
190
  - Gemfile
191
+ - Gemfile.rails32
192
+ - Gemfile.rails41
190
193
  - LICENSE.txt
191
194
  - README.md
192
195
  - Rakefile
@@ -212,17 +215,17 @@ require_paths:
212
215
  - lib
213
216
  required_ruby_version: !ruby/object:Gem::Requirement
214
217
  requirements:
215
- - - ! '>='
218
+ - - ">="
216
219
  - !ruby/object:Gem::Version
217
220
  version: '0'
218
221
  required_rubygems_version: !ruby/object:Gem::Requirement
219
222
  requirements:
220
- - - ! '>='
223
+ - - ">="
221
224
  - !ruby/object:Gem::Version
222
225
  version: '0'
223
226
  requirements: []
224
227
  rubyforge_project:
225
- rubygems_version: 2.2.2
228
+ rubygems_version: 2.4.3
226
229
  signing_key:
227
230
  specification_version: 4
228
231
  summary: Simple faraday client wrapper preconfigured for specific usecase