class Bookboon::Client

Attributes

last_request[RW]

Public Class Methods

new() { |config| ... } click to toggle source
# File lib/bookboon/client.rb, line 5
def initialize
  if block_given?
    yield(config)
  end
end

Public Instance Methods

book(id) click to toggle source
# File lib/bookboon/client.rb, line 23
def book(id)
  get("books/#{id}")
end
categories() click to toggle source
# File lib/bookboon/client.rb, line 11
def categories
  get("categories")
end
category(id) click to toggle source
# File lib/bookboon/client.rb, line 15
def category(id)
  get("categories/#{id}")
end
download_book(id, handle) click to toggle source
# File lib/bookboon/client.rb, line 27
def download_book(id, handle)
  post("books/#{id}/download", body: { handle: handle })

  @last_request.headers['location']
end

Protected Instance Methods

config() click to toggle source

TODO: Implement /questions TODO: Implement /recommendations

# File lib/bookboon/client.rb, line 38
def config
  @config ||= Bookboon::Config.new
end
get(path, options = {}) click to toggle source
# File lib/bookboon/client.rb, line 59
def get(path, options = {})
  request(:get, path, options)
end
post(path, options = {}) click to toggle source
# File lib/bookboon/client.rb, line 63
def post(path, options = {})
  request(:post, path, options)
end
request(method, path, options) click to toggle source
# File lib/bookboon/client.rb, line 42
def request(method, path, options)
  uri = URI("https://bookboon.com/api/#{path}")

  options = {
    basic_auth: {
      username: config.id,
      password: config.secret,
    },
    headers: config.headers,
    follow_redirects: false,
  }.merge(options)

  @last_request = HTTParty.send(method, uri, options)

  @last_request.parsed_response
end