Class: Her::API
- Inherits:
-
Object
- Object
- Her::API
- Defined in:
- lib/castle-her/api.rb
Overview
This class is where all HTTP requests are made. Before using Her, you must configure it so it knows where to make those requests. In Rails, this is usually done in ‘config/initializers/her.rb`:
Constant Summary collapse
- FARADAY_OPTIONS =
Constants
[:request, :proxy, :ssl, :builder, :url, :parallel_manager, :params, :headers, :builder_class].freeze
Class Method Summary collapse
-
.setup(opts = {}, &block) ⇒ Object
Setup a default API connection.
Instance Method Summary collapse
-
#initialize(*args, &blk) ⇒ API
constructor
Create a new API object.
-
#setup(opts = {}, &blk) ⇒ Object
Setup the API connection.
Constructor Details
#initialize(*args, &blk) ⇒ API
Create a new API object. This is useful to create multiple APIs and use them with the ‘uses_api` method. If your application uses only one API, you should use Her::API.setup to configure the default API
28 29 30 |
# File 'lib/castle-her/api.rb', line 28 def initialize(*args, &blk) setup(*args, &blk) end |
Class Method Details
.setup(opts = {}, &block) ⇒ Object
Setup a default API connection. Accepted arguments and options are the same as #setup.
12 13 14 |
# File 'lib/castle-her/api.rb', line 12 def self.setup(opts={}, &block) @default_api = new(opts, &block) end |
Instance Method Details
#setup(opts = {}, &blk) ⇒ Object
Setup the API connection.
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/castle-her/api.rb', line 71 def setup(opts={}, &blk) opts[:url] = opts.delete(:base_uri) if opts.include?(:base_uri) # Support legacy :base_uri option = opts = .reject { |key, value| !FARADAY_OPTIONS.include?(key.to_sym) } @connection = Faraday.new() do |connection| yield connection if block_given? end self end |