Skip to content

Commit

Permalink
Initial setup
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdavis178 committed Dec 30, 2023
1 parent 6ac3362 commit d61dbba
Show file tree
Hide file tree
Showing 19 changed files with 308 additions and 1 deletion.
8 changes: 8 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# This is a comment.
# Each line is a file pattern followed by one or more owners.

# These owners will be the default owners for everything in
# the repo. Unless a later match takes precedence,
# @global-owner1 and @global-owner2 will be requested for
# review when someone opens a pull request.
* @chrisdavis180
8 changes: 8 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## What
Describe the change(s).

## Why
Describe the reason for the change(s).

## Testing
Describe how to test your change(s).
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/.bundle/
/.yardoc
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
/tmp/
Gemfile.lock
.rspec
.DS_store
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## [Unreleased]

## [0.1.0] - 2022-11-24

- Initial release
8 changes: 8 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

source 'https://rubygems.org'

# Specify your gem's dependencies in beeceptor_ruby.gemspec
gemspec

gem 'rake', '~> 13.0'
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2022 Chris Davis

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
52 changes: 51 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,51 @@
# beeceptor_ruby
# BeeceptorRuby

## Installation

Install the gem and add to the application's Gemfile by executing:

$ bundle add beeceptor_ruby

If bundler is not being used to manage dependencies, install the gem by executing:

$ gem install beeceptor_ruby

## Usage

This gem provides access to the Beeceptor REST API.

```ruby
require 'beeceptor_ruby'

options = {
:api_key => 'YOUR_API_KEY',
:endpoint => 'YOUR_ENDPOINT'
}

client = BeeceptorRuby::Client.new(options)

puts client.list_rules
```

## Beeceptor REST API Documentation
- [Overview](https://docs.beeceptor.com/docs/api-overview/)
- [Rules](https://docs.beeceptor.com/docs/features-mocking-rules/)
- [History](https://docs.beeceptor.com/docs/api-request-history/)

## Development

After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/beeceptor_ruby.

## License

The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).

## Need this for your python project?

If you're on a python stack this gem also comes in a python flavor! Check it out here: https://github.com/chdavis180/beeceptorpy
4 changes: 4 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

require 'bundler/gem_tasks'
task default: %i[]
33 changes: 33 additions & 0 deletions beeceptor_ruby.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

require_relative 'lib/beeceptor_ruby/version'

Gem::Specification.new do |spec|
spec.name = 'beeceptor_ruby'
spec.version = BeeceptorRuby::VERSION
spec.authors = ['Chris Davis']

spec.summary = 'Beeceptor REST API Client for Ruby'
spec.description = "Allows users to use Beeceptor's REST API."
spec.homepage = 'https://github.com/chrisdavis179/beeceptor_ruby'
spec.license = 'MIT'
spec.required_ruby_version = '>= 2.6.0'

# Specify which files should be added to the gem when it is released.
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
spec.files = Dir.chdir(__dir__) do
`git ls-files -z`.split("\x0").reject do |f|
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
end
end
spec.bindir = 'exe'
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']

spec.add_dependency 'faraday'
spec.add_dependency 'json'
spec.add_dependency 'rspec', '~> 3.7'

# For more information and examples about making a new gem, check out our
# guide at: https://bundler.io/guides/creating_gem.html
end
15 changes: 15 additions & 0 deletions bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'bundler/setup'
require 'beeceptor_ruby'

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.

# (If you use this, don't forget to add pry to your Gemfile!)
# require "pry"
# Pry.start

require 'irb'
IRB.start(__FILE__)
8 changes: 8 additions & 0 deletions bin/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
set -vx

bundle install

# Do any other automated setup that you need to do here
8 changes: 8 additions & 0 deletions lib/beeceptor_ruby.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

require_relative 'beeceptor_ruby/version'
require_relative 'beeceptor_ruby/client'

module BeeceptorRuby
class Error < StandardError; end
end
37 changes: 37 additions & 0 deletions lib/beeceptor_ruby/client.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# frozen_string_literal: true

require_relative 'resource/history'
require_relative 'resource/rules'
require 'faraday'
require 'json'

module BeeceptorRuby
# Client provides methods for interacting with all beeceptor
# features i.e. mocking rules and api request
class Client
include BeeceptorRuby::Client::Resource::History
include BeeceptorRuby::Client::Resource::Rules

def initialize(options)
@base_url = "https://api.beeceptor.com/api/v1/endpoints/#{options[:endpoint]}"
@api_key = options[:api_key]
@client = Faraday.new(@base_url, builder: build_middleware) do |http|
http.headers[:content_type] = 'application/json'
http.headers[:authorization] = @api_key
end
end

attr_reader :base_url

def request(method, path, params = {}, headers = {})
path = URI.parse("#{@base_url}#{path}").normalize.to_s
@client.send(method, path, params, headers)
end

def build_middleware
Faraday::RackBuilder.new do |builder|
builder.response :json
end
end
end
end
26 changes: 26 additions & 0 deletions lib/beeceptor_ruby/resource/history.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

module BeeceptorRuby
class Client
module Resource
# The History API can be used to retrieve and manage request history
module History
def get_request(request_id)
request :get, "/requests/#{request_id}"
end

def list_requests
request :get, '/requests'
end

def purge_request(request_id)
request :delete, "/requests/#{request_id}"
end

def purge_requests
request :delete, '/requests'
end
end
end
end
end
30 changes: 30 additions & 0 deletions lib/beeceptor_ruby/resource/rules.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true

module BeeceptorRuby
class Client
module Resource
# The Rules API can be used to create, retrieve, update and delete mocking rules
module Rules
def create_rule(body)
request :post, '/rules', body
end

def get_rule(rule_id)
request :get, "/rules/#{rule_id}"
end

def list_rules
request :get, '/rules'
end

def update_rule(rule_id, body)
request :put, "/rules/#{rule_id}", body
end

def delete_rule(rule_id)
request :delete, "/rules/#{rule_id}"
end
end
end
end
end
5 changes: 5 additions & 0 deletions lib/beeceptor_ruby/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

module BeeceptorRuby
VERSION = '0.1.0'
end
4 changes: 4 additions & 0 deletions sig/beeceptor_ruby.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module BeeceptorRuby
VERSION: String
# See the writing guide of rbs: https://github.com/ruby/rbs#guides
end
11 changes: 11 additions & 0 deletions spec/beeceptor_ruby_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

RSpec.describe BeeceptorRuby do
it 'has a version number' do
expect(BeeceptorRuby::VERSION).not_to be nil
end

it 'does something useful' do
expect(false).to eq(true)
end
end
15 changes: 15 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

require 'beeceptor_ruby'

RSpec.configure do |config|
# Enable flags like --only-failures --next-failure
config.example_status_persistence_file_path = '.rspec_status'

# Disable RSpec exposing methods globally on `Module` and `main`
config.disable_monkey_patching!

config.expect_with :rspec do |c|
c.syntax = :expect
end
end

0 comments on commit d61dbba

Please sign in to comment.