Class: GeekierFactory::API
- Inherits:
-
Object
- Object
- GeekierFactory::API
- Defined in:
- lib/geekier_factory/api.rb
Instance Method Summary collapse
- #api_connection ⇒ Object
- #available_actions ⇒ Object
- #base_url ⇒ Object
- #error_responses ⇒ Object
-
#initialize(structure) ⇒ API
constructor
A new instance of API.
- #log_body? ⇒ Boolean
Constructor Details
#initialize(structure) ⇒ API
Returns a new instance of API.
7 8 9 10 |
# File 'lib/geekier_factory/api.rb', line 7 def initialize(structure) @structure = structure @actions = Hash[@structure['apis'].map{ |api| [api['description'], api['operations'].map{ |op| Action.new(self, op.merge('path' => api['path'])) }] }] end |
Instance Method Details
#api_connection ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/geekier_factory/api.rb', line 16 def api_connection @connection ||= begin Faraday.new(base_url, ssl: {verify: false}) do |builder| builder.request :json # builder.request :oauth, credentials_hash.merge(oauth_consumer_credentials) if oauth? and oauth_consumer_credentials.present? builder.response :body_logger if log_body? builder.adapter Faraday.default_adapter end end end |
#available_actions ⇒ Object
30 31 32 |
# File 'lib/geekier_factory/api.rb', line 30 def available_actions @actions end |
#base_url ⇒ Object
34 35 36 |
# File 'lib/geekier_factory/api.rb', line 34 def base_url @structure['basePath'].end_with?('/') ? @structure['basePath'] : (@structure['basePath'] + '/') end |
#error_responses ⇒ Object
38 39 40 |
# File 'lib/geekier_factory/api.rb', line 38 def error_responses @structure['errorResponses'] || [] end |
#log_body? ⇒ Boolean
12 13 14 |
# File 'lib/geekier_factory/api.rb', line 12 def log_body? true end |