Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AngelList API role updates. #17

Merged
merged 2 commits into from
Mar 25, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions lib/angellist_api/client/startup_roles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,33 @@ class Client
#
# @see http://angel.co/api/spec/startup_roles
module StartupRoles
# Given a startup_id, returns the users involved in that startup. Given a
# user_id, returns the startups that user is involved in. If neither
# parameter is given, the authenticated user is used. Possible roles
# include founder, employee, past_investor, advisor, incubator and
# referrer. Roles are paginated and ordered by most recently declared
# first.
# Given a user_id, returns the companies that User is tagged in. Given a startup_id,
# returns either the users and companies tagged in the given Startup (if direction is
# incoming) or the companies which the given Startup is tagged in (if direction is
# outgoing). If neither parameter is given, the authenticated user is used. Possible
# roles include founder, employee, past_investor, current_investor, advisor, incubator
# and referrer. Roles are paginated and ordered by most recently declared first.
#
# @requires_authentication Optional
# @paginated Yes
#
# @param [Hash] options A customizable set of options.
# @option options [Integer] :user_id The user whose startup relationships
# you want to view.
# @option options [Integer] :startup_id The startup whose user
# relationships you want to view.
# @option options [String] :direction Only applies if startup_id is present.
# Either incoming or outgoing. Defaults to incoming.
# @option options [Integer] :page Specifies the page of results to
# retrieve.
#
# @example Get info about authenticated user's startups and roles.
# AngellistApi.get_startup_roles
#
# @example Get users involved in startup with ID 1234, and their roles.
# AngellistApi.get_startup_roles(:startup_id => 1234)
def get_startup_roles(options={})
options.merge!(:v => 1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're not exactly following semver very well with this gem because a.) somehow, someone released a 1.0 version to Rubygems without it being tagged or updated in code (found when I tried to push 9a3ea88 to rubygems), and b.) AngelList considers the API beta and isn't promising any API stability yet. So we really should still be on 0.x releases (I'm tempted to revert to a 0.x scheme and yank the 1.x versions honestly).

Anyhow, it seems pretty nasty to force this parameter on users without a major version bump, especially because there's no new method or name change and, as written, library users can't even choose to override this to keep the old behavior while they work to update their code. Seems like we ought to just document that the user must pass the v option himself to get the new behavior and that it will become default in the future (possibly emit a warning if it's called without the option, to warn users of AngelList's deprecation).

get("1/startup_roles", options)
end
end
Expand Down
20 changes: 20 additions & 0 deletions lib/angellist_api/client/startups.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,26 @@ def get_startups(ids)
def startup_search(options={})
get("1/startups/search", options)
end

# Returns a company's startup roles. If direction is outgoing, then it returns
# the companies which the given company is tagged in. If direction is incoming, or
# omitted, then it returns the users and companies which are tagged in the given
# company. Results are paginated.
#
# @requires_authentication Optional
# @paginated Yes
#
# @param id [Integer] ID of the desired startup.
# @option options [String] :direction Either incoming or outgoing. Defaults to
# incoming.
# @option options [Integer] :page Specifies the page of results to
# retrieve.
#
# @example Get
# AngellistApi.startup_roles(1234)
def startup_roles(id, options={})
get("1/startups/#{id}/roles")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, we forgot to pass the options to get here, so it's impossible to pass the direction 😖

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! Want me to fix that?

end
end
end
end
Expand Down
15 changes: 15 additions & 0 deletions lib/angellist_api/client/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@ def user_search(options={})
def me
get("1/me")
end

# Returns the companies that a user has been tagged in. Results are paginated.
#
# @requires_authentication Optional
# @paginated Yes
#
# @param [Integer] id ID of the desired user.
# @option options [Integer] :page Specifies the page of results to
# retrieve.
#
# @example Get a user's roles given an id.
# AngellistApi.user_roles(1234)
def user_roles(id)
get("1/users/#{id}/roles")
end
end
end
end
Expand Down
2,301 changes: 2,300 additions & 1 deletion spec/fixtures/cassettes/startup_roles.yml

Large diffs are not rendered by default.

602 changes: 601 additions & 1 deletion spec/fixtures/cassettes/startups.yml

Large diffs are not rendered by default.

521 changes: 520 additions & 1 deletion spec/fixtures/cassettes/users.yml

Large diffs are not rendered by default.

18 changes: 15 additions & 3 deletions spec/integration/startup_roles_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,26 @@
describe AngellistApi::Client::StartupRoles,
:vcr => { :cassette_name => 'startup_roles' } do

ROLES = %w[founder employee past_investor advisor incubator referrer]
let(:client) { AngellistApi::Client.new }

it "gets a startup's relationships" do
it "gets a startup's outgoing relationships" do
roles = client.get_startup_roles(:startup_id => 1124)
roles.startup_roles.each do |relationship|
ROLES.should include relationship.role
end
roles.startup_roles.first.should have_key :user
roles.startup_roles.first.should have_key :tagged
roles.startup_roles.first.tagged.should have_key :type
roles.startup_roles.first.tagged.type.should eq "User"
end

it "gets a startup's incoming relationships" do
roles = client.get_startup_roles(:startup_id => 1124, :direction => "incoming")
roles.startup_roles.each do |relationship|
ROLES.should include relationship.role
end
roles.startup_roles.first.should have_key :tagged
roles.startup_roles.first.tagged.should have_key :type
roles.startup_roles.first.tagged.type.should eq "User"
end

it "gets a user's relationships" do
Expand All @@ -20,6 +31,7 @@
ROLES.should include relationship.role
end
roles.startup_roles.first.should have_key :startup
roles.startup_roles.first.should have_key :tagged
end
end

16 changes: 16 additions & 0 deletions spec/integration/startups_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,21 @@
startup = client.startup_search(:domain => '500.co')
startup.angellist_url.should eq 'http://angel.co/500-startups-fund'
end

it 'gets a company\s startup roles' do
roles = client.startup_roles(1124)
roles.startup_roles.size.should be > 0
roles.startup_roles.each do |relationship|
ROLES.should include relationship.role
end
end

it 'gets a company\s outgoing startup roles' do
roles = client.startup_roles(1124)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:direction => "outgoing" also missing here :(

roles.startup_roles.size.should be > 0
roles.startup_roles.each do |relationship|
ROLES.should include relationship.role
end
end
end

8 changes: 8 additions & 0 deletions spec/integration/users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,13 @@
user = client.user_search(:slug => '500startups')
user.linkedin_url.should eq 'http://www.linkedin.com/company/500-startups'
end

it 'gets the companies that a user has been tagged in' do
roles = client.user_roles(2850)
roles.startup_roles.size.should be > 0
roles.startup_roles.each do |relationship|
ROLES.should include relationship.role
end
end
end

1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@

Dir['./spec/support/**/*.rb'].each { |f| require f }

ROLES = %w[founder employee past_investor advisor incubator referrer customer]