Module: ThreeScale::Core::APIClient::Support::ClassMethods
- Defined in:
- lib/3scale/core/api_client/support.rb
Instance Method Summary collapse
- #default_http_error_exception(exception = nil) ⇒ Object
- #default_prefix(prefix = nil) ⇒ Object
- #default_uri(uri = nil) ⇒ Object
- #parse_json(body) ⇒ Object
- #status_ok?(method, uri, response) ⇒ Boolean
- #url_encode(str) ⇒ Object
Instance Method Details
#default_http_error_exception(exception = nil) ⇒ Object
33 34 35 36 |
# File 'lib/3scale/core/api_client/support.rb', line 33 def default_http_error_exception(exception = nil) return @default_http_error_exception ||= APIError unless exception @default_http_error_exception = exception end |
#default_prefix(prefix = nil) ⇒ Object
38 39 40 41 |
# File 'lib/3scale/core/api_client/support.rb', line 38 def default_prefix(prefix = nil) return @default_prefix ||= self.to_s.split(':').last.downcase.to_sym unless prefix @default_prefix = prefix end |
#default_uri(uri = nil) ⇒ Object
28 29 30 31 |
# File 'lib/3scale/core/api_client/support.rb', line 28 def default_uri(uri = nil) return @default_uri ||= "/internal/#{self.to_s.split(':').last.downcase!}s/" unless uri @default_uri = uri end |
#parse_json(body) ⇒ Object
24 25 26 |
# File 'lib/3scale/core/api_client/support.rb', line 24 def parse_json(body) JSON.parse(body, symbolize_names: true) end |
#status_ok?(method, uri, response) ⇒ Boolean
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/3scale/core/api_client/support.rb', line 12 def status_ok?(method, uri, response) status = response.status # handle server errors here, since we will not be expecting JSON raise internal_api_error(status).new(method, uri, response) if status >= 500 case method when :post then [200, 201] when :put then [200, 204, 202] when :delete then [200, 204, 202] else [200] end.include? status end |
#url_encode(str) ⇒ Object
43 44 45 |
# File 'lib/3scale/core/api_client/support.rb', line 43 def url_encode(str) ERB::Util.url_encode(str) end |