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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aa7191e00b0fa6396be519250117e31e924c258f368cf7d1c9e02697234bcab0
4
- data.tar.gz: e989353ef2ef2fc4cb07014fb3b2a9a0dfce0bf778b820582c98c13502c1de1d
3
+ metadata.gz: 57f1034be17b96ea4181b77b4ff472b1e10c8b435d3569180a2c2e008286c573
4
+ data.tar.gz: 1206b4f733335dfc41d4fa02cb6c171840187c105f2967afcb10d62939015f2c
5
5
  SHA512:
6
- metadata.gz: 046af961bf1da02e71a2193cfad8cd048084dc021e6786bfc1df753d54730284b4d3bd309f383b8b9456e4628a5c21a24beccbbddc25977c6b93c40485b1bfe8
7
- data.tar.gz: 579c841ef7eb221a3d86e3e0ef13e77e77fb08a9ecacf70847f4a5c38509b7de2541507b9d45d05b26eb98c3e93dfcc61b229cbd8b8efba70c8b44336a361530
6
+ metadata.gz: 050ecf0c162ceec1bbbfac219db53b2e33ec509545e6574f67b6a9f685cf10706f9ea314c9b188d96a23c0109ef4538246d5fc7fb4cc5fafb1ccf200ffdcd3cb
7
+ data.tar.gz: 152a955fc1788a341c2de601b5d8d6eff7a4263e1d9965f64d7f3943fb2d7f218f092716cd13117a873a2422d0f0efac84be72e90aff9c2147bf02b87f44b8fd
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.6.1
4
+ script: bundle exec rake spec
5
+ branches:
6
+ only:
7
+ - master
@@ -0,0 +1,77 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers of Bubbles pledge to making participation in our
7
+ project and our community a harassment-free experience for everyone,
8
+ regardless of age, body size, disability, ethnicity, sex characteristics,
9
+ gender identity and expression, level of experience, education,
10
+ socio-economic status, nationality, personal appearance, race, religion,
11
+ or sexual identity and orientation.
12
+
13
+ ## Our Standards
14
+
15
+ Examples of behavior that contributes to creating a positive environment
16
+ include:
17
+
18
+ * Using welcoming and inclusive language
19
+ * Being respectful of differing viewpoints and experiences
20
+ * Gracefully accepting constructive criticism
21
+ * Focusing on what is best for the community and users
22
+ * Showing empathy towards other community members
23
+
24
+ Examples of unacceptable behavior by participants include:
25
+
26
+ * The use of sexualized language or imagery and unwelcome sexual attention or
27
+ advances
28
+ * Trolling, insulting/derogatory comments, and personal or political attacks
29
+ * Public or private harassment
30
+ * Publishing others' private information, such as a physical or electronic
31
+ address, without explicit permission
32
+ * Other conduct which could reasonably be considered inappropriate in a
33
+ professional setting
34
+
35
+ ## Our Responsibilities
36
+
37
+ Project maintainers are responsible for clarifying the standards of acceptable
38
+ behavior and are expected to take appropriate and fair corrective action in
39
+ response to any instances of unacceptable behavior.
40
+
41
+ Project maintainers have the right and responsibility to remove, edit, or
42
+ reject comments, commits, code, wiki edits, issues, and other contributions
43
+ that are not aligned to this Code of Conduct, or to ban temporarily or
44
+ permanently any contributor for other behaviors that they deem inappropriate,
45
+ threatening, offensive, or harmful.
46
+
47
+ ## Scope
48
+
49
+ This Code of Conduct applies both within project spaces and in public spaces
50
+ when an individual is representing the project or its community. Examples of
51
+ representing a project or community include using an official project e-mail
52
+ address, posting via an official social media account, or acting as an appointed
53
+ representative at an online or offline event. Representation of a project may be
54
+ further defined and clarified by project maintainers.
55
+
56
+ ## Enforcement
57
+
58
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
59
+ reported by contacting Scott Johnson, our project lead, at jaywir3@gmail.com. All
60
+ complaints will be reviewed and investigated and will result in a response that
61
+ is deemed necessary and appropriate to the circumstances. The project leadership
62
+ team is obligated to maintain confidentiality with regard to the reporter of an
63
+ incident. Further details of specific enforcement policies may be posted separately.
64
+
65
+ Project maintainers who do not follow or enforce the Code of Conduct in good
66
+ faith may face temporary or permanent repercussions as determined by other
67
+ members of the project's leadership.
68
+
69
+ ## Attribution
70
+
71
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
72
+ available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
73
+
74
+ [homepage]: https://www.contributor-covenant.org
75
+
76
+ For answers to common questions about this code of conduct, see
77
+ https://www.contributor-covenant.org/faq
@@ -0,0 +1,31 @@
1
+ # Contributing to Bubbles
2
+
3
+ ## Introduction
4
+ First off, thanks for looking to contribute to Bubbles! We need people like you
5
+ to help us make the best quality product we possibly can. Regardless of whether
6
+ you're a developer, a designer, a technical writer, a student, or even someone
7
+ just interested in learning more about open source and how to contribute, you're
8
+ welcome here.
9
+
10
+ ## Code of Conduct
11
+ Please take a look at our contributor [Code of Conduct](CODE_OF_CONDUCT.md). We
12
+ take harassment and non-inclusive behavior very seriously and will not tolerate
13
+ bullying in any form.
14
+
15
+ ## Development Process
16
+ Our development process works as follows:
17
+
18
+ 1. Fork this repository to your own local Github account.
19
+ 2. Clone your local version of the repository: `git clone git@github.com:<username>/bubbles`.
20
+ 3. Create a branch on your local repository: `git checkout -b <username>/#<issue>-<short-description>`.
21
+ 4. Make any changes you see fit to fix the issue or add your work.
22
+ 5. Verify that tests pass: `bundle install && rake spec`.
23
+ 6. If you're adding a new feature, make sure to add tests for the feature.
24
+ 7. Commit your changes and push to your fork of the repository.
25
+ 8. Submit a pull request to the `master` branch of the original repository.
26
+ 9. You will receive a review within 7 days, at which time, you may need to make
27
+ modifications to your code, or your contribution might be accepted as-is.
28
+
29
+ ## Good First Issues
30
+ You can take a look at our [good first issues](https://github.com/FoamFactory/bubbles/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22)
31
+ to check out some issues that might be a good starting point for you.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bubbles-rest-client (0.4.0)
4
+ bubbles-rest-client (0.5.0)
5
5
  addressable (~> 2.5)
6
6
  rest-client (~> 2.0)
7
7
 
@@ -33,6 +33,7 @@ GEM
33
33
  minitest (>= 5.0)
34
34
  ruby-progressbar
35
35
  netrc (0.11.0)
36
+ os (1.0.1)
36
37
  public_suffix (3.0.3)
37
38
  rake (10.5.0)
38
39
  rest-client (2.1.0)
@@ -77,6 +78,7 @@ DEPENDENCIES
77
78
  bundler (~> 2.0.0)
78
79
  minitest (~> 5.0)
79
80
  minitest-reporters (~> 1.1)
81
+ os
80
82
  rake (~> 10.0)
81
83
  rspec (~> 3.8)
82
84
  simplecov (~> 0.16)
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
1
  # bubbles
2
+ [![Build Status](https://travis-ci.org/FoamFactory/bubbles.svg?branch=master)](https://travis-ci.org/FoamFactory/bubbles)
3
+
2
4
  A gem for easily defining client REST interfaces in ruby
3
5
 
4
6
  ## Project Goals
@@ -28,9 +30,7 @@ _bubbles_ is a Gem that seeks to provide this same behavior.
28
30
 
29
31
  Currently, bubbles has a number of limitations that make it likely not suitable for use in a production environment. Each of these is tracked by an issue on our [issues page](https://github.com/FoamFactory/bubbles/issues).
30
32
 
31
- - Passing an API key with a request is restricted to using `X-Api-Key` as a header key (#10).
32
- - Some request methods (specifically `DELETE`) do not currently allow unauthenticated access. In other words, it is not possible to perform a `DELETE` request on your API without passing an authorization token. (#16)
33
- - Not all possible combinations of `has_uri_params`, `authenticated`, and `api_key_required` are tested. In some cases, such as with `GET` requests, there aren't any tests for possible configuration cases that might cause issues when combined. (#12)
33
+ - Some request methods (specifically `DELETE`) do not currently allow unauthenticated access. In other words, it is not possible to perform a `DELETE` request on your API without passing an authorization token. (FoamFactory/bubbles#16)
34
34
 
35
35
  If you're interested in working on any of the issues above, please feel free to submit a pull request and a member of our team will review that pull request within a couple of days.
36
36
 
@@ -52,7 +52,7 @@ Bubbles.configure do |config|
52
52
  }
53
53
  ]
54
54
 
55
- config.local_environment = {
55
+ config.environment = {
56
56
  :scheme => 'http',
57
57
  :host => '0.0.0.0',
58
58
  :port => '1234'
@@ -60,12 +60,11 @@ Bubbles.configure do |config|
60
60
  end
61
61
  ```
62
62
 
63
- The `config.endpoints` section is where you configure which endpoints you want to support. The `config.local_environment` defines an environment, or remote configuration, for accessing the endpoint on a specific remote destination.
63
+ The `config.endpoints` section is where you configure which endpoints you want to support. The `config.environment` defines an environment, or remote configuration, for accessing the endpoint on a specific remote destination.
64
64
 
65
65
  Now, you can use this endpoint with:
66
66
  ```ruby
67
67
  require 'bubbles'
68
-
69
68
  ...
70
69
 
71
70
  def version
@@ -73,7 +72,7 @@ def version
73
72
 
74
73
  # The following will make a GET request to
75
74
  # http://0.0.0.0:1234/version and return the result.
76
- result = resources.local_environment.version
75
+ result = resources.environment.version
77
76
 
78
77
  puts(result)
79
78
  end
@@ -83,13 +82,15 @@ end
83
82
  There are currently two parts to a bubbles configuration: the _environments_ and the _endpoints_. Bubbles is configured in a _bubbles configuration block_:
84
83
  ```ruby
85
84
  Bubbles.configure do |config|
86
- ...
85
+ # You can add configuration for Bubbles here using config.endpoints and config.environment
87
86
  end
88
87
  ```
89
88
 
90
89
  This configuration block can be run at any time, but is typically set up in the initializer section of an app's startup. If desired, configuration can happen separately. That is, you can initialize environments within your initializer file and then initialize endpoints within another section of the application. Just note that when endpoints are defined, it overwrites _all_ endpoints of a configuration, not just the ones you choose to change.
91
90
 
92
91
  ### Environments
92
+ > :construction: Environment names used to be hardcoded into Bubbles. You can now access the current environment using `Bubbles::Resources.new.environment`. This section is left in the documentation for future reference, as we will eventually be adding back named environments (see FoamFactory/bubbles#23 for tracking information).
93
+
93
94
  Three environments are currently available to be set up within bubbles. These are:
94
95
  - `local_environment` : Designed to be used for a local API for development testing.
95
96
  - `staging_environment` : Designed to be used for a remote API for second-stage testing or production-like deployment.
@@ -104,27 +105,30 @@ Environments are configured as part of the _bubbles configuration block_ and can
104
105
  - `host`: A domain name or IP address for the remote host to access for the environment. Defaults to `127.0.0.1`.
105
106
  - `port`: The port to use to access the remote host. Defaults to `1234`.
106
107
  - `api_key`: The API key to send along with requests for a given environment, if an API key is required. This is optional, and defaults to `nil`.
108
+ - `headers`: A `Hash` of key-value pairs that contain additional headers to pass to every call to this endpoint. Defaults to `{}`.
107
109
 
108
110
  You can configure all three environments at once in the _bubbles configuration block_:
109
111
  ```ruby
110
112
  Bubbles.configure do |config|
111
- config.local_environment = {
113
+ config.environment = {
112
114
  :scheme => 'http',
113
115
  :host => '0.0.0.0',
114
116
  :port => '1234'
115
117
  }
116
118
 
117
- config.staging_environment = {
118
- :scheme => 'http',
119
- :host => 'stage.api.foamfactory.com',
120
- :port => '80'
121
- }
122
-
123
- config.production_environment = {
124
- :scheme => 'https',
125
- :host => 'api.foamfactory.com',
126
- :port => '443'
127
- }
119
+ # Note: This is deprecated for the time being. See (FoamFactory/bubbles/#23).
120
+ # config.staging_environment = {
121
+ # :scheme => 'http',
122
+ # :host => 'stage.api.foamfactory.com',
123
+ # :port => '80'
124
+ # }
125
+
126
+ # Note: This is deprecated for the time being. See (FoamFactory/bubbles/#23).
127
+ # config.production_environment = {
128
+ # :scheme => 'https',
129
+ # :host => 'api.foamfactory.com',
130
+ # :port => '443'
131
+ # }
128
132
  end
129
133
  ```
130
134
 
@@ -164,14 +168,178 @@ Each _endpoint_ object can have the following attributes:
164
168
  | `api_key_required` | Whether or not an API key is required. If `true`, a parameter will be added to the method created to execute the REST API call named `api_key`. The value of this parameter will be set as the value of the `X-Api-Key` header when making the REST API call. | No | `false` |
165
169
  | `return_type` | Must be one of: `[full_response, body_as_object, body_as_string]`. This specifies what type of response is expected from the `Endpoint`. A value of `full_response` will return the full `RestClient::Response` object to the client. A value of `body_as_string` will return the `RestClient::Response.body` value as a `String`. A value of `body_as_object` will take the `RestClient::Response.body` parameter and parse it as an `OpenStruct` object, and return the result of this parsing operation. | No | `body_as_string` |
166
170
  | `encode_authorization` | Whether the `data` passed as part of the request should be re-encoded as an `Authorization: Basic` header (and Base64 encoded). Typically, this is only used for initial username/password authentication. | No | `false` |
171
+ | `headers` | A `Hash` of key-value pairs specifying additional headers (the `key` specifies the name of the header, and the `value` specifies the value) that should be passed with each call to this `Endpoint`. Defaults to `{}`.
167
172
 
168
173
  ### Examples
174
+ These examples are taken almost directly from our [test suite](https://github.com/FoamFactory/bubbles/blob/master/spec/bubbles/resources_spec.rb). For more detailed examples, please refer to our specifications located in the `/spec` directory.
175
+
169
176
  #### GET the version of the software (unauthenticated, no API key required)
177
+ **Configuration**:
178
+
179
+ ```ruby
180
+ require 'bubbles'
181
+
182
+ Bubbles.configure do |config|
183
+ config.endpoints = [
184
+ {
185
+ :method => :get,
186
+ :location => :version,
187
+ :authenticated => false,
188
+ :api_key_required => false,
189
+ :return_type => :body_as_object
190
+ }
191
+ ]
192
+
193
+ config.environment = {
194
+ :scheme => 'http',
195
+ :host => '0.0.0.0',
196
+ :port => '1234'
197
+ }
198
+ end
199
+ ```
200
+
201
+ **Usage**:
202
+ ```ruby
203
+ it 'should return an object containing the version information from the API' do
204
+ resources = Bubbles::Resources.new
205
+ environment = resources.environment
206
+
207
+ response = environment.version
208
+ expect(response).to_not be_nil
209
+ expect(response.name).to eq('My Sweet API')
210
+ expect(response.versionName).to eq('0.0.1')
211
+ end
212
+ ```
170
213
 
171
214
  #### GET a specific user by id (authentication required)
215
+ **Configuration**:
216
+ ```ruby
217
+ Bubbles.configure do |config|
218
+ config.endpoints = [
219
+ {
220
+ :method => :get,
221
+ :location => 'users/{id}',
222
+ :authenticated => true,
223
+ :name => :get_user,
224
+ :return_type => :body_as_object
225
+ }
226
+ ]
227
+
228
+ config.environment = {
229
+ :scheme => 'http',
230
+ :host => '127.0.0.1',
231
+ :port => '9002'
232
+ }
233
+ end
234
+ ```
235
+
236
+ **Usage**:
237
+ ```ruby
238
+ it 'should return an object containing a user with id = 4' do
239
+ environment = Bubbles::Resources.new.environment
240
+ user = environment.get_user(@auth_token, {:id => 4})
241
+ expect(user).to_not be_nil
242
+
243
+ expect(user.id).to eq(4)
244
+ end
245
+ ```
172
246
 
173
247
  #### POST a login (i.e. retrieve an authorization token)
248
+ **Configuration**:
249
+ ```ruby
250
+ Bubbles.configure do |config|
251
+ config.endpoints = [
252
+ {
253
+ :method => :post,
254
+ :location => :login,
255
+ :authenticated => false,
256
+ :api_key_required => true,
257
+ :encode_authorization => [:username, :password],
258
+ :return_type => :body_as_object
259
+ }
260
+ ]
261
+
262
+ config.environment = {
263
+ :scheme => 'http',
264
+ :host => '127.0.0.1',
265
+ :port => '9002',
266
+ :api_key => 'someapikey'
267
+ }
268
+ end
269
+ ```
270
+
271
+ **Usage**:
272
+ ```ruby
273
+ it 'should return a user data structure with a valid authorization token' do
274
+ environment = Bubbles::Resources.new.environment
275
+
276
+ data = { :username => 'myusername', :password => 'mypassword' }
277
+ login_object = environment.login data
278
+
279
+ auth_token = login_object.auth_token
280
+
281
+ expect(auth_token).to_not be_nil
282
+ end
283
+ ```
174
284
 
175
285
  #### DELETE a user by id
286
+ **Configuration**:
287
+ ```ruby
288
+ Bubbles.configure do |config|
289
+ config.endpoints = [
290
+ {
291
+ :method => :delete,
292
+ :location => 'users/{id}',
293
+ :authenticated => true,
294
+ :name => 'delete_user_by_id',
295
+ :return_type => :body_as_object
296
+ }
297
+ ]
298
+
299
+ config.environment = {
300
+ :scheme => 'http',
301
+ :host => '127.0.0.1',
302
+ :port => '9002'
303
+ }
304
+ ```
305
+
306
+ **Usage**:
307
+ ```ruby
308
+ it 'should successfully delete the given user' do
309
+ environment = Bubbles::Resources.new.environment
310
+ response = environment.delete_user_by_id @auth_token, {:id => 2}
311
+ expect(response.success).to eq(true)
312
+ end
313
+ ```
176
314
 
177
315
  #### PATCH a user's information by providing a body containing information to update
316
+ **Configuration**:
317
+ ```ruby
318
+ Bubbles.configure do |config|
319
+ config.endpoints = [
320
+ {
321
+ :method => :patch,
322
+ :location => 'users/{id}',
323
+ :authenticated => true,
324
+ :name => 'update_user',
325
+ :return_type => :body_as_object
326
+ }
327
+ ]
328
+
329
+ config.environment = {
330
+ :scheme => 'http',
331
+ :host => '127.0.0.1',
332
+ :port => '9002'
333
+ }
334
+ ```
335
+
336
+ **Usage**:
337
+ ```ruby
338
+ it 'should update information for the specified user' do
339
+ environment = Bubbles::Resources.new.environment
340
+ response = environment.update_user @auth_token, {:id => 4}, {:user => {:email => 'kleinhammer@somewhere.com' } }
341
+
342
+ expect(response.id).to eq(4)
343
+ expect(response.email).to eq('kleinhammer@somewhere.com')
344
+ end
345
+ ```
data/Rakefile CHANGED
@@ -1,10 +1,5 @@
1
1
  require "bundler/gem_tasks"
2
- require "rake/testtask"
3
2
 
4
- Rake::TestTask.new(:test) do |t|
5
- t.libs << "test"
6
- t.libs << "lib"
7
- t.test_files = FileList['test/**/*_test.rb']
8
- end
3
+ Dir.glob('lib/tasks/*.rake').each { |r| load r}
9
4
 
10
- task :default => :test
5
+ task :default => :build