Module: Safettp::Client
- Defined in:
- lib/safettp/client.rb
Defined Under Namespace
Modules: ClassMethods Classes: Configuration
Instance Attribute Summary collapse
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#options_hash ⇒ Object
readonly
Returns the value of attribute options_hash.
Class Method Summary collapse
Instance Method Summary collapse
- #initialize(base_url = self.class.config.base_url, options_hash = self.class.config.default_options) ⇒ Object
- #perform(*args) {|guard| ... } ⇒ Object
- #perform_without_guard(method, uri_suffix = '/', options = {}) ⇒ Object
Instance Attribute Details
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
2 3 4 |
# File 'lib/safettp/client.rb', line 2 def base_url @base_url end |
#options_hash ⇒ Object (readonly)
Returns the value of attribute options_hash.
2 3 4 |
# File 'lib/safettp/client.rb', line 2 def end |
Class Method Details
.included(base) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/safettp/client.rb', line 45 def self.included(base) base.extend(ClassMethods) i[get delete].each do |method| define_method(method) do |uri_suffix, query = {}, = { query: query }, &block| perform(method, uri_suffix, , &block) end end i[post put patch].each do |method| define_method(method) do |uri_suffix, body = {}, = { body: body }, &block| perform(method, uri_suffix, , &block) end end end |
Instance Method Details
#initialize(base_url = self.class.config.base_url, options_hash = self.class.config.default_options) ⇒ Object
4 5 6 7 8 |
# File 'lib/safettp/client.rb', line 4 def initialize(base_url = self.class.config.base_url, = self.class.config.) @base_url = base_url = end |
#perform(*args) {|guard| ... } ⇒ Object
10 11 12 13 14 15 |
# File 'lib/safettp/client.rb', line 10 def perform(*args, &block) response = perform_without_guard(*args) guard = Safettp::Guard.new(response) yield(guard) guard.evaluate! end |
#perform_without_guard(method, uri_suffix = '/', options = {}) ⇒ Object
17 18 19 20 21 |
# File 'lib/safettp/client.rb', line 17 def perform_without_guard(method, uri_suffix = '/', = {}) url = "#{base_url}#{uri_suffix}" Safettp::Request.new(url, .merge()) .perform(method) end |