Class: FerrisBueller::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/ferris_bueller/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



7
8
9
10
11
12
13
# 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

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



5
6
7
# File 'lib/ferris_bueller/client.rb', line 5

def connection
  @connection
end

Instance Method Details

#create_event(event_attributes) ⇒ Object



23
24
25
26
# 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) ⇒ Object



15
16
17
18
19
20
21
# 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) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# 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