class Quaderno::Base

Constants

PRODUCTION_URL
SANDBOX_URL

Public Class Methods

api_model(klass) click to toggle source

Class methods

# File lib/quaderno-ruby/base.rb, line 20
  def self.api_model(klass)
    instance_eval <<-END
      def api_model
        #{klass}
      end
    END
    class_eval <<-END
      def api_model
        #{klass}
      end
    END
  end
api_version=(api_version) click to toggle source
# File lib/quaderno-ruby/base.rb, line 37
def self.api_version=(api_version)
  @@api_version = api_version
end
auth_token=(auth_token) click to toggle source
# File lib/quaderno-ruby/base.rb, line 41
def self.auth_token=(auth_token)
  @@auth_token = auth_token
end
authorization(auth_token, mode = nil) click to toggle source
# File lib/quaderno-ruby/base.rb, line 49
def self.authorization(auth_token, mode = nil)
  mode ||= :production
  url = mode == :sandbox ? SANDBOX_URL : PRODUCTION_URL
  response = get("#{url}authorization.json", basic_auth: { username: auth_token }, headers: default_headers)

  if response.code == 200
    data = self.new(response.parsed_response)
    data.rate_limit_info = response

    data
  else
    raise_exception(Quaderno::Exceptions::InvalidSubdomainOrToken, 'Invalid subdomain or token', response)
  end
end
configure() { |self| ... } click to toggle source
# File lib/quaderno-ruby/base.rb, line 33
def self.configure
  yield self
end
me(options = {}) click to toggle source
# File lib/quaderno-ruby/base.rb, line 91
def self.me(options = {})
  options[:auth_token] ||= auth_token
  options[:api_url] ||= url

  authentication = get_authentication(options)

  party_response = get("#{authentication[:url]}me.json",
    basic_auth: authentication[:basic_auth],
    headers: default_headers.merge(authentication[:headers])
  )

  check_exception_for(party_response, { subdomain_or_token: true })

  data = self.new(party_response.parsed_response)
  data.rate_limit_info = party_response

  data
end
ping(options = {}) click to toggle source

Check the connection

# File lib/quaderno-ruby/base.rb, line 65
def self.ping(options = {})
  begin
    options[:auth_token] ||= auth_token
    options[:api_url] ||= url

    authentication = get_authentication(options)

    party_response = get("#{authentication[:url]}ping.json",
      basic_auth: authentication[:basic_auth],
      headers: default_headers.merge(authentication[:headers])
    )

    check_exception_for(party_response, { subdomain_or_token: true })
  rescue Errno::ECONNREFUSED
    return Quaderno::Base.new({ status: false })
  end

  data = self.new({ status: true })
  data.rate_limit_info = party_response

  data
end
Also aliased as: rate_limit_info
rate_limit_info(options = {})
Alias for: ping
url=(url) click to toggle source
# File lib/quaderno-ruby/base.rb, line 45
def self.url=(url)
  @@url = url
end

Private Class Methods

api_path(api_path = nil) click to toggle source

Set or returns the model path for the url

# File lib/quaderno-ruby/base.rb, line 130
def self.api_path(api_path = nil)
  @_api_path ||= api_path
end
auth_token() click to toggle source

Class methods

# File lib/quaderno-ruby/base.rb, line 117
def self.auth_token
  @@auth_token
end
default_headers() click to toggle source
# File lib/quaderno-ruby/base.rb, line 138
def self.default_headers
  user_agent_header.merge(version_header)
end
is_a_document?(document = nil) click to toggle source
# File lib/quaderno-ruby/base.rb, line 134
def self.is_a_document?(document = nil)
  @_document ||= document
end
subdomain() click to toggle source
# File lib/quaderno-ruby/base.rb, line 125
def self.subdomain
  @_subdomain = @@subdomain
end
url() click to toggle source
# File lib/quaderno-ruby/base.rb, line 121
def self.url
  @@url
end
user_agent_header() click to toggle source
# File lib/quaderno-ruby/base.rb, line 142
def self.user_agent_header
  { "User-Agent" => "Quaderno Ruby Gem #{Quaderno::VERSION}" }
end
version_header() click to toggle source
# File lib/quaderno-ruby/base.rb, line 146
def self.version_header
  { 'Accept' => @@api_version.to_i.zero? ? "application/json" : "application/json; api_version=#{@@api_version.to_i}"}
end

Public Instance Methods

to_hash() click to toggle source

Instance methods

# File lib/quaderno-ruby/base.rb, line 111
def to_hash
  self.marshal_dump
end