lib/her/api.rb in her-0.3.3 vs lib/her/api.rb in her-0.3.4

- old
+ new

@@ -4,14 +4,14 @@ class API # @private attr_reader :base_uri, :connection, :options # Setup a default API connection. Accepted arguments and options are the same as {API#setup}. - def self.setup(attrs={}, &block) # {{{ + def self.setup(attrs={}, &block) @@default_api = new @@default_api.setup(attrs, &block) - end # }}} + end # Setup the API connection. # # @param [Hash] attrs the Faraday options # @option attrs [String] :url The main HTTP API root (eg. `https://api.example.com`) @@ -47,25 +47,25 @@ # Her::API.setup :url => "https://api.example.com" do |connection| # connection.use Faraday::Request::UrlEncoded # connection.use MyCustomParser # connection.use Faraday::Adapter::NetHttp # end - def setup(attrs={}) # {{{ + def setup(attrs={}) attrs[:url] = attrs.delete(:base_uri) if attrs.include?(:base_uri) # Support legacy :base_uri option @base_uri = attrs[:url] @options = attrs @connection = Faraday.new(attrs.slice(:url, :ssl)) do |connection| yield connection if block_given? end - end # }}} + end # Define a custom parsing procedure. The procedure is passed the response object and is # expected to return a hash with three keys: a main data Hash, an errors Array # and a metadata Hash. # # @private - def request(attrs={}) # {{{ + def request(attrs={}) method = attrs.delete(:_method) path = attrs.delete(:_path) headers = attrs.delete(:_headers) attrs.delete_if { |key, value| key.to_s =~ /^_/ } # Remove all internal parameters response = @connection.send method do |request| @@ -78,14 +78,14 @@ request.url path request.body = attrs end end response.env[:body] - end # }}} + end private # @private - def self.default_api(attrs={}) # {{{ + def self.default_api(attrs={}) defined?(@@default_api) ? @@default_api : nil - end # }}} + end end end