Sha256: 1e159f04624e472cb2f9015e8a16c4d0e313834cdd21f118b2370d8dd9bac682

Contents?: true

Size: 1.23 KB

Versions: 1

Compression:

Stored size: 1.23 KB

Contents

module Strava
  # Group events for Strava Clubs
  # 
  # @see http://strava.github.io/api/v3/club_group_events/ Strava Docs - Group Events
  class GroupEvent < Base

    def update(data, **opts)
      @response = data
      @id                     = data["id"]
      @resource_state         = data['resource_state']
    end

    def get_details
      return self if detailed?
      res = client.get(path_base).to_h
      update(res)
      res
    end

    def athletes(per_page: nil, page: nil)
      if page || per_page
        get_athletes(per_page: per_page, page: page)
      else
        get_athletes if @athletes.empty?
        @athletes.values
      end
    end

    def delete
      res = client.delete(path_base).to_h
    end

    # {"success"=>true, "active"=>false}
    def join
      res = client.post(path_rsvp).to_h
    end

    # {"success"=>true, "active"=>true, "membership"=>"member"}
    def leave
      res = client.delete(path_rsvp).to_h
    end

    private def path_base
      "group_events/#{id}"
    end

    private def path_rsvp
      "#{path_base}/rsvps"
    end

    private def path_athletes
      "#{path_base}/athletes"
    end

  end
end

__END__

ca = Strava::Athlete.current_athlete;
miz = ca.clubs.last;
miz.group_events

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
strava-0.1.0 lib/strava/group_event.rb