class FerrisBueller::Client

Attributes

connection[R]

Public Class Methods

new(options = {}) click to toggle source
# File lib/ferris_bueller/client.rb, line 7
def initialize(options = {})
  @url = from_options(:url, options)
  @token = from_options(:token, options)

  @connection = Faraday.new(url: @url)
  @connection.token_auth(@token)
end

Public Instance Methods

create_event(event_attributes) click to toggle source
# File lib/ferris_bueller/client.rb, line 23
def create_event(event_attributes)
  validate_event_attributes(event_attributes)
  self.connection.post '/api/events', event_attributes
end
from_options(key, options) click to toggle source
# File lib/ferris_bueller/client.rb, line 15
def from_options(key, options)
  if value = options[key]
    value
  else
    raise ArgumentError.new "#{key.inspect} is required."
  end
end
validate_event_attributes(event_attributes) click to toggle source
# File lib/ferris_bueller/client.rb, line 28
def validate_event_attributes(event_attributes)
  event = event_attributes[:event] || event_attributes['event']
  raise ArgumentError.new ":event is required." unless event

  [:title, :venue, :shows, :source_listing, :source].each do |key|
    unless event[key] || event[key.to_s]
      raise ArgumentError.new ":event => #{key.inspect} is required."
    end
  end
end