Sha256: a0b7a2747e8944785688344171ece980c434d5c4fc536083c51f17f33a79eee5

Contents?: true

Size: 1.16 KB

Versions: 19

Compression:

Stored size: 1.16 KB

Contents

require 'her'
require 'quandl/her/patch'

module Quandl
module Client
  class << self
    
    def use(url)
      self.rest_url = url
    end
    
    def token
      @token
    end
    def token=(token)
      @token = token
      reload_models
    end
    
    def her_api
      # setup api
      api = Her::API.new
      api.setup url: rest_url do |c|
        c.use TokenAuthentication
        c.use Faraday::Request::UrlEncoded
        # c.use Her::Middleware::DefaultParseJSON
        c.use Quandl::Client::Middleware::ParseJSON
        c.use Faraday::Adapter::NetHttp
      end
    end

    def rest_url
      @rest_url ||= "http://localhost:3000/api/#{API_VERSION}/"
    end
    
    def rest_url=(url)
      url = "http://#{url}" if ( url =~ /^http:\/\// ) == nil
      url = File.join(url, "#{API_VERSION}/")
      @rest_url = url
      reload_models
      @rest_url
    end
    
    def reload_models
      Models.use_api( her_api )
    end
    
    class TokenAuthentication < Faraday::Middleware
      def call(env)
        env[:request_headers]["X-API-Token"] = Quandl::Client.token if Quandl::Client.token.present?
        @app.call(env)
      end
    end
    
  end 
end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
quandl_client-0.1.17 lib/quandl/client/her.rb
quandl_client-0.1.16 lib/quandl/client/her.rb
quandl_client-0.1.15 lib/quandl/client/her.rb
quandl_client-0.1.14 lib/quandl/client/her.rb
quandl_client-0.1.13 lib/quandl/client/her.rb
quandl_client-0.1.12 lib/quandl/client/her.rb
quandl_client-0.1.11 lib/quandl/client/her.rb
quandl_client-0.1.10 lib/quandl/client/her.rb
quandl_client-0.1.9 lib/quandl/client/her.rb
quandl_client-0.1.8 lib/quandl/client/her.rb
quandl_client-0.1.7 lib/quandl/client/her.rb
quandl_client-0.1.6 lib/quandl/client/her.rb
quandl_client-0.1.5 lib/quandl/client/her.rb
quandl_client-0.1.4 lib/quandl/client/her.rb
quandl_client-0.1.3 lib/quandl/client/her.rb
quandl_client-0.1.2 lib/quandl/client/her.rb
quandl_client-0.1.0 lib/quandl/client/her.rb
quandl_client-0.0.16 lib/quandl/client/her.rb
quandl_client-0.0.15 lib/quandl/client/her.rb