bubbles-rest-client 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  module Bubbles
2
2
  class RestEnvironment
3
- attr_accessor :scheme, :host, :port, :api_key
3
+ attr_accessor :host, :port, :api_key, :api_key_name
4
4
 
5
5
  ##
6
6
  # Construct a new instance of +RestEnvironment+.
@@ -9,17 +9,59 @@ module Bubbles
9
9
  # @param [String] host The host to communicate with.
10
10
  # @param [Integer] port The port on which the communication channel should operate.
11
11
  # @param [String] api_key (Optional) The API key to use to identify your client with the API. Defaults to +nil+.
12
+ # @param [String] api_key_name (Optional) The name of the header that will specify the API key. Defaults to +"X-API-Key"+.
12
13
  #
13
- def initialize(scheme='https', host='api.foamfactory.com', port=443, api_key=nil)
14
+ def initialize(scheme='https', host='api.foamfactory.com', port=443, api_key=nil, api_key_name='X-API-Key')
14
15
  @scheme = scheme
15
16
  @port = port
16
17
 
17
- if @scheme == 'http' && @port == 443
18
+ if @scheme == 'http' && @port == nil
18
19
  @port = 80
20
+ elsif @scheme == 'https' && @port == nil
21
+ @port = 443
19
22
  end
20
23
 
21
24
  @host = host
22
25
  @api_key = api_key
26
+ @api_key_name = api_key_name
27
+ end
28
+
29
+ ##
30
+ # Retrieve the name of the API key to be used.
31
+ #
32
+ # This will be the "key" portion of the key-value of the API key header.
33
+ #
34
+ # @return [String] The API key name, if set; "X-API-Key", otherwise.
35
+ #
36
+ def api_key_name
37
+ @api_key_name
38
+ end
39
+
40
+ ##
41
+ # Retrieve an API key from this +RestEnvironment+, but only if a specific +Endpoint+ requires it.
42
+ #
43
+ # If an +Endpoint+ has +api_key_required+ set to +true+, this method will return the API for the current
44
+ # +RestEnvironment+. If not, then it will return +nil+, rather than just blindly returning the API key for every
45
+ # possible retrieval, even if the +Endpoint+ doesn't require it.
46
+ #
47
+ # @return [String] The API key for this +RestEnvironment+, if the specified +Endpoint+ requires it; +nil+,
48
+ # otherwise.
49
+ #
50
+ def get_api_key_if_needed(endpoint)
51
+ if endpoint.api_key_required?
52
+ @api_key
53
+ else
54
+ nil
55
+ end
56
+ end
57
+
58
+ ##
59
+ # Retrieve the scheme of the current +RestEnvironment+, as a +Symbol+.
60
+ #
61
+ # @return [Symbol] The scheme of the current +RestEnvironment+, as a +Symbol+.
62
+ #
63
+ def scheme
64
+ @scheme.to_s
23
65
  end
24
66
  end
25
67
  end
@@ -7,7 +7,7 @@ module Bubbles
7
7
  end
8
8
 
9
9
  def self.version_name
10
- '0.4.1'
10
+ '0.5.0'
11
11
  end
12
12
 
13
13
  def self.version_code
@@ -0,0 +1,22 @@
1
+ require 'rspec/core/rake_task'
2
+ require 'simplecov'
3
+ require 'os'
4
+
5
+ namespace :spec do
6
+ desc "Create rspec coverage"
7
+ task :coverage do
8
+ ENV['COVERAGE'] = 'true'
9
+ Rake::Task["spec"].execute
10
+ end
11
+
12
+ namespace :coverage do
13
+ desc 'View coverage information'
14
+ task :view => [:coverage] do
15
+ if OS.mac?
16
+ `open coverage/index.html`
17
+ elsif OS.posix?
18
+ `sensible-browser coverage/index.html`
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,5 @@
1
+ begin
2
+ require 'rspec/core/rake_task'
3
+ RSpec::Core::RakeTask.new(:spec)
4
+ rescue LoadError
5
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bubbles-rest-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Johnson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-14 00:00:00.000000000 Z
11
+ date: 2019-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: '3.8'
125
+ - !ruby/object:Gem::Dependency
126
+ name: os
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: addressable
127
141
  requirement: !ruby/object:Gem::Requirement
@@ -159,6 +173,9 @@ extensions: []
159
173
  extra_rdoc_files: []
160
174
  files:
161
175
  - ".gitignore"
176
+ - ".travis.yml"
177
+ - CODE_OF_CONDUCT.md
178
+ - CONTRIBUTING.md
162
179
  - Gemfile
163
180
  - Gemfile.lock
164
181
  - LICENSE
@@ -171,6 +188,8 @@ files:
171
188
  - lib/bubbles/rest_client_resources.rb
172
189
  - lib/bubbles/rest_environment.rb
173
190
  - lib/bubbles/version.rb
191
+ - lib/tasks/coverage.rake
192
+ - lib/tasks/spec.rake
174
193
  homepage: https://github.com/FoamFactory/bubbles
175
194
  licenses:
176
195
  - MPL-2.0