Class: GeekierFactory::API

Inherits:
Object
  • Object
show all
Defined in:
lib/geekier_factory/api.rb

Instance Method Summary collapse

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_connectionObject



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_actionsObject



30
31
32
# File 'lib/geekier_factory/api.rb', line 30

def available_actions
  @actions
end

#base_urlObject



34
35
36
# File 'lib/geekier_factory/api.rb', line 34

def base_url
  @structure['basePath'].end_with?('/') ? @structure['basePath'] : (@structure['basePath'] + '/')
end

#error_responsesObject



38
39
40
# File 'lib/geekier_factory/api.rb', line 38

def error_responses
  @structure['errorResponses'] || []
end

#log_body?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/geekier_factory/api.rb', line 12

def log_body?
  true
end