lib/hackerone/client/program.rb in hackerone-client-0.4.0 vs lib/hackerone/client/program.rb in hackerone-client-0.5.0

- old
+ new

@@ -19,10 +19,47 @@ def attributes OpenStruct.new(@program[:attributes]) end + def member?(username) + find_member(username).present? + end + + def group?(groupname) + find_group(groupname).present? + end + + def find_member(username) + members.find { |member| member.user.username == username } + end + + def find_group(groupname) + groups.find { |group| group.name == groupname } + end + private + + def members + @members ||= relationships.members[:data].map { |member_data| Member.new(member_data) } + end + + def groups + @groups ||= relationships.groups[:data].map { |group_data| Group.new(group_data) } + end + + def relationships + # Relationships are only included in the /programs/:id call, + # which is why we need to do a separate call here. + @relationships ||= begin + response = HackerOne::Client::Api.hackerone_api_connection.get do |req| + req.url "programs/#{id}" + end + + data = HackerOne::Client::Api.parse_response(response) + OpenStruct.new(data[:relationships]) + end + end def self.my_programs @my_programs ||= begin response = HackerOne::Client::Api.hackerone_api_connection.get do |req| req.url "me/programs"