Class: FerrisBueller::Client
- Inherits:
-
Object
- Object
- FerrisBueller::Client
- Defined in:
- lib/ferris_bueller/client.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Instance Method Summary collapse
- #create_event(event_attributes) ⇒ Object
- #from_options(key, options) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #validate_event_attributes(event_attributes) ⇒ Object
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( = {}) @url = (:url, ) @token = (:token, ) @connection = Faraday.new(url: @url) @connection.token_auth(@token) end |
Instance Attribute Details
#connection ⇒ Object (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 (key, ) if value = [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 |