Skip to content

Commit

Permalink
Merge branch 'jwir3/#25-bubblez-rename'
Browse files Browse the repository at this point in the history
  • Loading branch information
jwir3 committed Mar 1, 2022
2 parents f4df545 + 1fa76b9 commit 78274a5
Show file tree
Hide file tree
Showing 14 changed files with 242 additions and 238 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source 'https://rubygems.org'

# Specify your gem's dependencies in bubbles.gemspec
# Specify your gem's dependencies in bubblez.gemspec
gemspec
27 changes: 16 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# bubbles
# bubblez
[![Build Status](https://travis-ci.org/FoamFactory/bubbles.svg?branch=master)](https://travis-ci.org/FoamFactory/bubbles)

A gem for easily defining client REST interfaces in ruby

## Project Goals
When working in an Android environment, [Retrofit](https://square.github.io/retrofit/) provides a simple and effective way of annotating methods so that you can define your REST interface:
When working in an Android environment, [Retrofit](https://square.github.io/retrofit/) provides a simple and effective
way of annotating methods so that you can define your REST interface:
```java
public interface GitHubService {
@GET("users/{user}/repos")
Expand All @@ -21,19 +22,22 @@ Retrofit retrofit = new Retrofit.Builder()
GitHubService service = retrofit.create(GitHubService.class);
```

What this does is allow you to focus on your _handling_ of the REST responses, rather than worrying about the boilerplate code required to set up the client side of the REST API.
What this does is allow you to focus on your _handling_ of the REST responses, rather than worrying about the
boilerplate code required to set up the client side of the REST API.

_bubbles_ is a Gem that seeks to provide this same behavior.
_bubblez_ is a Gem that seeks to provide this same behavior.

## Usage
If you're using Rails, it's suggested to have a `config/initializers/bubbles.rb` configuration file where you can easily configure your endpoints and environments. If you're not using Rails, then you can put this configuration just about anywhere, provided it's executed before where you want to use it.
If you're using Rails, it's suggested to have a `config/initializers/bubblez.rb` configuration file where you can
easily configure your endpoints and environments. If you're not using Rails, then you can put this configuration just
about anywhere, provided it's executed before where you want to use it.

## Quickstart
In `config/initializers/bubbles.rb`, add the following:
In `config/initializers/bubblez.rb`, add the following:
```ruby
require 'bubbles'
require 'bubblez'

Bubbles.configure do |config|
Bubblez.configure do |config|
config.endpoints = [
{
:method => :get,
Expand All @@ -51,11 +55,12 @@ Bubbles.configure do |config|
end
```

The `config.endpoints` section is where you configure which endpoints you want to support. The `config.environments` defines the environments, or remote configurations, for accessing the endpoint on specific remote destinations.
The `config.endpoints` section is where you configure which endpoints you want to support. The `config.environments`
defines the environments, or remote configurations, for accessing the endpoint on specific remote destinations.

Now, you can use this endpoint with:
```ruby
require 'bubbles'
require 'bubblez'
...

def version
Expand All @@ -70,4 +75,4 @@ end
```

## Detailed Documentation
For more examples and detailed documentation, please see [the Bubbles GitHub page](http://foamfactory.github.io/bubbles).
For more examples and detailed documentation, please see [the Bubbles GitHub page](http://foamfactory.github.io/bubblez).
18 changes: 9 additions & 9 deletions bubbles.gemspec → bubblez.gemspec
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'bubbles/version'
require 'bubblez/version'

Gem::Specification.new do |spec|
spec.name = Bubbles::VersionInformation.package_name
spec.version = Bubbles::VersionInformation.version_name
spec.name = Bubblez::VersionInformation.package_name
spec.version = Bubblez::VersionInformation.version_name
spec.date = Date.today.strftime("%Y-%m-%d")
spec.summary = 'Bubbles REST Client'
spec.homepage = 'https://github.com/FoamFactory/bubbles'
spec.summary = 'Bubblez REST Client'
spec.homepage = 'https://github.com/FoamFactory/bubblez'
spec.authors = ['Scott Johnson']
spec.email = 'jaywir3@gmail.com'
spec.files = %w(lib/bubbles.rb lib/bubbles/rest_environment.rb lib/bubbles/version.rb)
spec.files = %w(lib/bubblez.rb lib/bubblez/rest_environment.rb lib/bubblez/version.rb)
spec.license = 'MPL-2.0'
spec.summary = %q{A gem for easily defining client REST interfaces in Ruby}
spec.description = %q{Retrofit, by Square, allows you to easily define annoations that will generate the necessary boilerplate code for your REST interfaces. Bubbles is a Gem that seeks to bring a similar style of boilerplate generation to Ruby.}
spec.description = %q{Retrofit, by Square, allows you to easily define annoations that will generate the necessary boilerplate code for your REST interfaces. Bubblez is a Gem that seeks to bring a similar style of boilerplate generation to Ruby.}

# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
# to allow pushing to a single host or delete this section to allow pushing to any host.
Expand All @@ -33,14 +33,14 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"]

spec.add_development_dependency "bundler", "~> 2.2.26"
spec.add_development_dependency "rake", ">= 12.3.3"
spec.add_development_dependency 'rake', '~> 12.3', '>= 12.3.3'
spec.add_development_dependency "minitest", "~> 5.0"
spec.add_development_dependency "minitest-reporters", "~> 1.1"
spec.add_development_dependency "simplecov", "~> 0.16"
spec.add_development_dependency "webmock", "~> 3.5"
spec.add_development_dependency "vcr", "~> 3.0"
spec.add_development_dependency "rspec", "~> 3.8"
spec.add_development_dependency "os"
spec.add_development_dependency "os", "~> 1.1.4"
spec.add_dependency "addressable", "~> 2.5"
spec.add_dependency "rest-client", "~> 2.0"
end
29 changes: 0 additions & 29 deletions lib/bubbles.rb

This file was deleted.

28 changes: 28 additions & 0 deletions lib/bubblez.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require "bubblez/version"
require 'bubblez/config'
require 'base64'
require 'bubblez/rest_client_resources'
require 'bubblez/rest_environment'
require 'bubblez/version'
require 'rest-client'
require 'json'

module Bubblez
class Resources < RestClientResources
def initialize(api_key='')
super

@package_name = Bubblez::VersionInformation.package_name
@version_name = Bubblez::VersionInformation.version_name
@version_code = Bubblez::VersionInformation.version_code
end

def get_version_info
{
:name => @package_name,
:version_name => @version_name,
:version_code => @version_code
}
end
end
end
48 changes: 24 additions & 24 deletions lib/bubbles/config.rb → lib/bubblez/config.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
require 'bubbles/rest_environment'
require 'bubbles/endpoint'
require 'bubblez/rest_environment'
require 'bubblez/endpoint'
require 'base64'

module Bubbles
module Bubblez
class << self
attr_writer :configuration
end

##
# Configure the Bubbles instance.
# Configure the Bubblez instance.
#
# Use this method if you want to configure the Bubbles instance, typically during initialization of your Gem or
# Use this method if you want to configure the Bubblez instance, typically during initialization of your Gem or
# application.
#
# @example In app/config/initializers/bubbles.rb
# Bubbles.configure do |config|
# @example In app/config/initializers/bubblez.rb
# Bubblez.configure do |config|
# config.endpoints = [
# {
# :type => :get,
Expand All @@ -33,7 +33,7 @@ def self.configuration
end

##
# The configuration of the Bubbles rest client.
# The configuration of the Bubblez rest client.
#
# Use this class if you want to retrieve configuration values set during initialization.
#
Expand Down Expand Up @@ -86,7 +86,7 @@ def environment(environment_name = nil)
# environment have a +:environment_name:+ parameter to differentiate it from other environments.
#
# @example In app/config/environments/staging.rb:
# Bubbles.configure do |config|
# Bubblez.configure do |config|
# config.environments = [{
# :scheme => 'https',
# :host => 'stage.api.somehost.com',
Expand Down Expand Up @@ -161,15 +161,15 @@ def endpoints=(endpoints)
endpoint_name_as_sym = endpoint.get_location_string.to_sym
end

if Bubbles::RestEnvironment.instance_methods(false).include?(endpoint_name_as_sym)
Bubbles::RestEnvironment.class_exec do
if Bubblez::RestEnvironment.instance_methods(false).include?(endpoint_name_as_sym)
Bubblez::RestEnvironment.class_exec do
remove_method endpoint_name_as_sym
end
end

if endpoint.method == :get
if endpoint.authenticated?
Bubbles::RestEnvironment.class_exec do
Bubblez::RestEnvironment.class_exec do
if endpoint.has_uri_params?
if endpoint.encode_authorization_header?
define_method(endpoint_name_as_sym) do |username, password, uri_params|
Expand Down Expand Up @@ -204,7 +204,7 @@ def endpoints=(endpoints)
end
end
else
Bubbles::RestEnvironment.class_exec do
Bubblez::RestEnvironment.class_exec do
if endpoint.has_uri_params?
define_method(endpoint_name_as_sym) do |uri_params|
RestClientResources.execute_get_unauthenticated self, endpoint, uri_params, endpoint.additional_headers, self.get_api_key_if_needed(endpoint), self.api_key_name
Expand All @@ -218,13 +218,13 @@ def endpoints=(endpoints)
end
elsif endpoint.method == :post
if endpoint.authenticated? and !endpoint.encode_authorization_header?
Bubbles::RestEnvironment.class_exec do
Bubblez::RestEnvironment.class_exec do
define_method(endpoint_name_as_sym) do |auth_token, data|
RestClientResources.execute_post_authenticated self, endpoint, :bearer, auth_token, data, endpoint.additional_headers, self.get_api_key_if_needed(endpoint), self.api_key_name
end
end
elsif endpoint.encode_authorization_header?
Bubbles::RestEnvironment.class_exec do
Bubblez::RestEnvironment.class_exec do
define_method(endpoint_name_as_sym) do |username, password, data = {}|
login_data = {
:username => username,
Expand All @@ -239,7 +239,7 @@ def endpoints=(endpoints)
end
end
else
Bubbles::RestEnvironment.class_exec do
Bubblez::RestEnvironment.class_exec do
define_method(endpoint_name_as_sym) do |data|
composite_headers = endpoint.additional_headers
RestClientResources.execute_post_unauthenticated self, endpoint, data, composite_headers, self.get_api_key_if_needed(endpoint), self.api_key_name
Expand All @@ -249,13 +249,13 @@ def endpoints=(endpoints)
elsif endpoint.method == :delete
if endpoint.has_uri_params?
if endpoint.authenticated?
Bubbles::RestEnvironment.class_exec do
Bubblez::RestEnvironment.class_exec do
define_method(endpoint_name_as_sym) do |auth_token, uri_params|
RestClientResources.execute_delete_authenticated self, endpoint, auth_token, uri_params, endpoint.additional_headers, self.get_api_key_if_needed(endpoint), self.api_key_name
end
end
else
Bubbles::RestEnvironment.class_exec do
Bubblez::RestEnvironment.class_exec do
define_method(endpoint_name_as_sym) do |uri_params|
RestClientResources.execute_delete_unauthenticated self, endpoint, uri_params, endpoint.additional_headers, self.get_api_key_if_needed(endpoint), self.api_key_name
end
Expand All @@ -270,7 +270,7 @@ def endpoints=(endpoints)
end
elsif endpoint.method == :patch
if endpoint.authenticated?
Bubbles::RestEnvironment.class_exec do
Bubblez::RestEnvironment.class_exec do
if endpoint.has_uri_params?
define_method(endpoint_name_as_sym) do |auth_token, uri_params, data|
RestClientResources.execute_patch_authenticated self, endpoint, auth_token, uri_params, data, endpoint.additional_headers, self.get_api_key_if_needed(endpoint), self.api_key_name
Expand All @@ -282,7 +282,7 @@ def endpoints=(endpoints)
end
end
else
Bubbles::RestEnvironment.class_exec do
Bubblez::RestEnvironment.class_exec do
if endpoint.has_uri_params?
define_method(endpoint_name_as_sym) do |uri_params, data|
RestClientResources.execute_patch_unauthenticated self, endpoint, uri_params, data, endpoint.additional_headers, self.get_api_key_if_needed(endpoint), self.api_key_name
Expand All @@ -296,7 +296,7 @@ def endpoints=(endpoints)
end
elsif endpoint.method == :put
if endpoint.authenticated?
Bubbles::RestEnvironment.class_exec do
Bubblez::RestEnvironment.class_exec do
if endpoint.has_uri_params?
define_method(endpoint_name_as_sym) do |auth_token, uri_params, data|
RestClientResources.execute_put_authenticated self, endpoint, auth_token, uri_params, data, endpoint.additional_headers, self.get_api_key_if_needed(endpoint), self.api_key_name
Expand All @@ -308,7 +308,7 @@ def endpoints=(endpoints)
end
end
else
Bubbles::RestEnvironment.class_exec do
Bubblez::RestEnvironment.class_exec do
if endpoint.has_uri_params?
define_method(endpoint_name_as_sym) do |uri_params, data|
RestClientResources.execute_put_unauthenticated self, endpoint, uri_params, data, endpoint.additional_headers, self.get_api_key_if_needed(endpoint), self.api_key_name
Expand All @@ -322,7 +322,7 @@ def endpoints=(endpoints)
end
elsif endpoint.method == :head
if endpoint.authenticated?
Bubbles::RestEnvironment.class_exec do
Bubblez::RestEnvironment.class_exec do
if endpoint.has_uri_params?
define_method(endpoint_name_as_sym) do |auth_token, uri_params|
RestClientResources.execute_head_authenticated self, endpoint, auth_token, uri_params, endpoint.additional_headers, self.get_api_key_if_needed(endpoint), self.api_key_name
Expand All @@ -334,7 +334,7 @@ def endpoints=(endpoints)
end
end
else
Bubbles::RestEnvironment.class_exec do
Bubblez::RestEnvironment.class_exec do
if endpoint.has_uri_params?
define_method(endpoint_name_as_sym) do |uri_params|
RestClientResources.execute_head_unauthenticated self, endpoint, uri_params, endpoint.additional_headers, self.get_api_key_if_needed(endpoint), self.api_key_name
Expand Down
6 changes: 3 additions & 3 deletions lib/bubbles/endpoint.rb → lib/bubblez/endpoint.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require 'addressable/template'

module Bubbles
module Bubblez
##
# Representation of a single API endpoint within the Bubbles infrastructure.
# Representation of a single API endpoint within the Bubblez infrastructure.
#
# In order to access an API Endpoint, an {RestEnvironment} must also be provided. This class is an abstract
# representation of an +Endpoint+, without any information provided as part of the Environment. In other words, an
Expand Down Expand Up @@ -53,7 +53,7 @@ class Endpoint
## A template for specifying the complete URL for endpoints, with a port attached to the host.
API_URL_WITH_PORT = ::Addressable::Template.new("{scheme}://{host}:{port}/{endpoint}")

## The HTTP methods supported by a rest client utilizing Bubbles.
## The HTTP methods supported by a rest client utilizing Bubblez.
METHODS = %w[get post patch put delete head].freeze

## The possible return types for successful REST calls. Defaults to :body_as_string.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
require 'bubbles/config'
require 'bubbles/rest_environment'
require 'bubblez/config'
require 'bubblez/rest_environment'

module Bubbles
module Bubblez
class RestClientResources
def environment(env_name = nil)
Bubbles.configuration.environment(env_name)
Bubblez.configuration.environment(env_name)
end

##
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Bubbles
module Bubblez
class RestEnvironment
attr_accessor :host, :port, :api_key, :api_key_name

Expand Down
Loading

0 comments on commit 78274a5

Please sign in to comment.