Sha256: fbee4da6ee88285d541d091738bc31ff5faa11c40c25de84ddcc031c0b12851d

Contents?: true

Size: 1.38 KB

Versions: 8

Compression:

Stored size: 1.38 KB

Contents

module Evvnt
  # Public: Returns events info from the EVVNT API
  class Event < Evvnt::Base

    ##
    # GET /events List Events
    define_action :index

    ##
    # GET /events/:event_id Get one event
    define_action :show

    ##
    # POST /events  Create an event
    define_action :create

    ##
    # PUT /events/:event_id  Update an event
    define_action :update

    ##
    # GET /events/ours(/:id) Get events of you and your created users
    define_action :ours

    ##
    # GET /events/mine  List my events
    define_action :mine


    private


    def format_hash_attribute(key, value)
      case key
      when "links"
        format_links_attribute(key, value)
      when "prices"
        format_prices_attribute(key, value)
      else
        super
      end
    end

    def format_array_attribute(key, value)
      case key
      when /^(image\_urls|sub\_category\_ids)$/
        send(:"format_#{key}_attribute", key, value)
      else
        super
      end
    end

    def format_image_urls_attribute(_key, value)
      value
    end

    def format_sub_category_ids_attribute(_key, value)
      value
    end

    def format_links_attribute(_key, value)
      value.to_a.map { |name, url| Evvnt::Link.new(name: name, url: url) }
    end

    def format_prices_attribute(_key, value)
      value.to_a.map { |name, price| Evvnt::Price.new(name: name, value: price) }
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
evvnt-0.2.6 lib/evvnt/event.rb
evvnt-0.2.5 lib/evvnt/event.rb
evvnt-0.2.4 lib/evvnt/event.rb
evvnt-0.2.3 lib/evvnt/event.rb
evvnt-0.2.2 lib/evvnt/event.rb
evvnt-0.2.1 lib/evvnt/event.rb
evvnt-0.2.0 lib/evvnt/event.rb
evvnt-0.1.0 lib/evvnt/event.rb