Class: BeeceptorRuby::Client
- Inherits:
-
Object
- Object
- BeeceptorRuby::Client
- Includes:
- Resource::History, Resource::Rules
- Defined in:
- lib/beeceptor_ruby/client.rb,
lib/beeceptor_ruby/resource/rules.rb,
lib/beeceptor_ruby/resource/history.rb
Overview
Client provides methods for interacting with all beeceptor features i.e. mocking rules and api request
Defined Under Namespace
Modules: Resource
Instance Attribute Summary collapse
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
Instance Method Summary collapse
- #build_middleware ⇒ Object
-
#initialize(options) ⇒ Client
constructor
A new instance of Client.
- #request(method, path, params = {}, headers = {}) ⇒ Object
Methods included from Resource::Rules
#create_rule, #delete_rule, #get_rule, #list_rules, #update_rule
Methods included from Resource::History
#get_request, #list_requests, #purge_request, #purge_requests
Constructor Details
#initialize(options) ⇒ Client
Returns a new instance of Client.
15 16 17 18 19 20 21 22 |
# File 'lib/beeceptor_ruby/client.rb', line 15 def initialize() @base_url = "https://api.beeceptor.com/api/v1/endpoints/#{options[:endpoint]}" @api_key = [: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 |
Instance Attribute Details
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
24 25 26 |
# File 'lib/beeceptor_ruby/client.rb', line 24 def base_url @base_url end |
Instance Method Details
#build_middleware ⇒ Object
31 32 33 34 35 |
# File 'lib/beeceptor_ruby/client.rb', line 31 def build_middleware Faraday::RackBuilder.new do |builder| builder.response :json end end |
#request(method, path, params = {}, headers = {}) ⇒ Object
26 27 28 29 |
# File 'lib/beeceptor_ruby/client.rb', line 26 def request(method, path, params = {}, headers = {}) path = URI.parse("#{@base_url}#{path}").normalize.to_s @client.send(method, path, params, headers) end |