Sha256: b25ea823815c0443c3ebc36bb2ae73c7ec4e22379c1ce113f84393770152d585

Contents?: true

Size: 670 Bytes

Versions: 2

Compression:

Stored size: 670 Bytes

Contents

module Ahub
  class Group
    extend Ahub::APIHelpers
    include Ahub::ClassHelpers

    attr_reader :name
    def initialize(attrs)
      @id =  attrs[:id]
      @name = attrs[:name]
    end

    def add(user_id)
      add_user(user_id)
    end

    def self.find_by_name(group_name)
      matches = find_all
      matches.find{|group| group.name.downcase.strip == group_name.downcase.strip}
    end

    def add_user(user_id)
      raise Exception("No Group Id") unless id

      move_url = "#{self.class.base_url}/#{id}/add.json?users=#{user_id}"
      RestClient.put("#{move_url}", self.class.admin_headers)
      true
    rescue => e
      false
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ahub-0.2.0 lib/ahub/group.rb
ahub-0.1.17 lib/ahub/group.rb