Class: ECSBundler::RestClient
- Inherits:
-
Object
- Object
- ECSBundler::RestClient
- Defined in:
- lib/ecs_bundler/rest_client.rb
Overview
Wrapper under rest-client with authorization headers
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #headers ⇒ Object
-
#initialize(options = {}) ⇒ RestClient
constructor
A new instance of RestClient.
-
#method_missing(name, *args) ⇒ Object
get delete head options post patch put methods.
- #respond_to?(name) ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ RestClient
Returns a new instance of RestClient.
11 12 13 |
# File 'lib/ecs_bundler/rest_client.rb', line 11 def initialize( = {}) @options = end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
get delete head options post patch put methods
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ecs_bundler/rest_client.rb', line 31 def method_missing(name, *args) if %i[get delete head options post patch put].include?(name) if %i[get delete head options].include?(name) path, headers = args payload = nil else path, payload, headers = args end return ::RestClient::Request.execute( method: name, url: "#{[:url]}#{path}", payload: payload ? payload.to_json : payload, headers: self.headers.merge(headers || {}) ) do |response| parsed_response = JSON.parse(response.body) rescue {} = [ "#{response.code} #{::RestClient::STATUSES[response.code]}", parsed_response['info'], (parsed_response['messages'] || []).map { || ['message'] } ].compact.join(', ') yield(response, parsed_response, ) if block_given? response end end super(name, *args) end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
9 10 11 |
# File 'lib/ecs_bundler/rest_client.rb', line 9 def @options end |
Instance Method Details
#headers ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/ecs_bundler/rest_client.rb', line 15 def headers { content_type: :json, accept: :json, 'User-Agent' => [:userAgent], 'X-ApiKey' => [:apiKey], 'X-User' => [:userName] } end |
#respond_to?(name) ⇒ Boolean
25 26 27 28 |
# File 'lib/ecs_bundler/rest_client.rb', line 25 def respond_to?(name) return true if %i[get delete head options post patch put].include?(name) super(name) end |