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 23
  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_path(api_path = nil) click to toggle source

Set or returns the model path for the url

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

Class methods

# File lib/quaderno-ruby/base.rb, line 126
def self.auth_token
  @@auth_token
end
auth_token=(auth_token) click to toggle source
# File lib/quaderno-ruby/base.rb, line 44
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 56
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
  elsif response.response.is_a?(Net::HTTPServerError)
    raise_exception(Quaderno::Exceptions::ServerError, 'Server error', response)
  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 36
def self.configure
  yield self
end
default_headers() click to toggle source
# File lib/quaderno-ruby/base.rb, line 147
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 143
def self.is_a_document?(document = nil)
  @_document ||= document
end
me(options = {}) click to toggle source
# File lib/quaderno-ruby/base.rb, line 100
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 74
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
subdomain() click to toggle source
# File lib/quaderno-ruby/base.rb, line 134
def self.subdomain
  @_subdomain = @@subdomain
end
url() click to toggle source
# File lib/quaderno-ruby/base.rb, line 130
def self.url
  @@url
end
url=(url) click to toggle source
# File lib/quaderno-ruby/base.rb, line 48
def self.url=(url)
  @@url = url
end
user_agent_header() click to toggle source
# File lib/quaderno-ruby/base.rb, line 151
def self.user_agent_header
  { "User-Agent" => ["Quaderno Ruby Gem #{Quaderno::VERSION}", @@user_agent_suffix].compact.join(' - ') }
end
user_agent_header=(custom_user_agent) click to toggle source
# File lib/quaderno-ruby/base.rb, line 52
def self.user_agent_header=(custom_user_agent)
  @@user_agent_suffix = custom_user_agent
end
version_header() click to toggle source
# File lib/quaderno-ruby/base.rb, line 155
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 120
def to_hash
  self.marshal_dump
end