class Schoolkeep::Client

Attributes

api_key[R]

Public Class Methods

new(api_key) click to toggle source
# File lib/schoolkeep/client.rb, line 10
def initialize(api_key)
  @api_key = api_key
end

Public Instance Methods

delete(name) click to toggle source
# File lib/schoolkeep/client.rb, line 27
def delete(name)
  unless TEMPLATE_NAMES.include? name
    raise InvalidTemplateName.new("#{name} is an invalid template")
  end
  connection.delete "/v1/custom_templates.json", {
    id: name
  }
end
get_fixtures() click to toggle source
# File lib/schoolkeep/client.rb, line 36
def get_fixtures
  connection.get "/v1/fixtures.yaml"
end
upload(name, path, engine) click to toggle source
# File lib/schoolkeep/client.rb, line 14
def upload(name, path, engine)
  unless TEMPLATE_NAMES.include? name
    raise InvalidTemplateName.new("#{name} is an invalid template")
  end
  connection.post "/v1/custom_templates.json", {
    custom_template: {
      name: name,
      body: Faraday::UploadIO.new(path, 'text/plain; charset=utf-8'),
      engine: engine
    }
  }
end

Private Instance Methods

connection() click to toggle source
# File lib/schoolkeep/client.rb, line 42
def connection
  @conenction ||= Faraday.new(
    url: Schoolkeep.api_url,
    ssl: { ca_file: File.join(GEM_ROOT, "config/ca-bundle.crt") }
  ) do |faraday|
    faraday.headers["X-Api-Key"] = api_key
    faraday.request :multipart
    faraday.request :url_encoded
    faraday.adapter Faraday.default_adapter
  end
end