angellist_api 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. data/CHANGELOG.md +15 -0
  2. data/README.md +11 -6
  3. data/Rakefile +9 -0
  4. data/lib/angellist_api.rb +1 -3
  5. data/lib/angellist_api/api.rb +2 -4
  6. data/lib/angellist_api/authentication.rb +0 -1
  7. data/lib/angellist_api/client.rb +9 -1
  8. data/lib/angellist_api/client/activity_feeds.rb +29 -8
  9. data/lib/angellist_api/client/follows.rb +105 -63
  10. data/lib/angellist_api/client/jobs.rb +72 -0
  11. data/lib/angellist_api/client/reviews.rb +17 -6
  12. data/lib/angellist_api/client/search.rb +31 -0
  13. data/lib/angellist_api/client/startup_roles.rb +23 -8
  14. data/lib/angellist_api/client/startups.rb +49 -13
  15. data/lib/angellist_api/client/status_updates.rb +45 -24
  16. data/lib/angellist_api/client/tags.rb +52 -30
  17. data/lib/angellist_api/client/users.rb +39 -17
  18. data/lib/angellist_api/configuration.rb +24 -29
  19. data/lib/angellist_api/connection.rb +27 -29
  20. data/lib/angellist_api/core_ext/hash.rb +19 -0
  21. data/lib/angellist_api/error.rb +9 -32
  22. data/lib/angellist_api/error/bad_gateway.rb +7 -0
  23. data/lib/angellist_api/error/bad_request.rb +7 -0
  24. data/lib/angellist_api/error/enhance_your_calm.rb +13 -0
  25. data/lib/angellist_api/error/forbidden.rb +7 -0
  26. data/lib/angellist_api/error/internal_server_error.rb +7 -0
  27. data/lib/angellist_api/error/not_acceptable.rb +7 -0
  28. data/lib/angellist_api/error/not_found.rb +7 -0
  29. data/lib/angellist_api/error/service_unavailable.rb +7 -0
  30. data/lib/angellist_api/error/unauthorized.rb +7 -0
  31. data/lib/angellist_api/request.rb +11 -18
  32. data/lib/angellist_api/request/angellist_api_oauth.rb +16 -0
  33. data/lib/angellist_api/request/gateway.rb +18 -0
  34. data/lib/angellist_api/request/multipart_with_file.rb +36 -0
  35. data/lib/angellist_api/response/raise_client_error.rb +51 -0
  36. data/lib/angellist_api/response/raise_server_error.rb +27 -0
  37. data/lib/angellist_api/version.rb +1 -1
  38. data/spec/fixtures/cassettes/activity_feeds.yml +273 -0
  39. data/spec/fixtures/cassettes/follows.yml +1722 -0
  40. data/spec/fixtures/cassettes/jobs.yml +2052 -0
  41. data/spec/fixtures/cassettes/reviews.yml +93 -0
  42. data/spec/fixtures/cassettes/search.yml +169 -0
  43. data/spec/fixtures/cassettes/startup_roles.yml +1481 -0
  44. data/spec/fixtures/cassettes/startups.yml +532 -0
  45. data/spec/fixtures/cassettes/status_updates.yml +125 -0
  46. data/spec/fixtures/cassettes/tags.yml +762 -0
  47. data/spec/fixtures/cassettes/users.yml +275 -0
  48. data/spec/integration/activity_feeds_spec.rb +29 -0
  49. data/spec/integration/follows_spec.rb +60 -0
  50. data/spec/integration/jobs_spec.rb +36 -0
  51. data/spec/integration/reviews_spec.rb +15 -0
  52. data/spec/integration/search_spec.rb +27 -0
  53. data/spec/integration/startup_roles_spec.rb +25 -0
  54. data/spec/integration/startups_spec.rb +36 -0
  55. data/spec/integration/status_updates_spec.rb +18 -0
  56. data/spec/integration/tags_spec.rb +29 -0
  57. data/spec/integration/users_spec.rb +23 -0
  58. data/spec/spec_helper.rb +5 -2
  59. data/spec/support/vcr.rb +12 -0
  60. data/spec/{lib → unit/lib}/angellist_api/api_spec.rb +13 -15
  61. data/spec/unit/lib/angellist_api/authentication_spec.rb +49 -0
  62. data/spec/unit/lib/angellist_api/client/activity_feeds_spec.rb +22 -0
  63. data/spec/unit/lib/angellist_api/client/follows_spec.rb +82 -0
  64. data/spec/unit/lib/angellist_api/client/jobs_spec.rb +39 -0
  65. data/spec/unit/lib/angellist_api/client/reviews_spec.rb +14 -0
  66. data/spec/unit/lib/angellist_api/client/search_spec.rb +15 -0
  67. data/spec/unit/lib/angellist_api/client/startup_roles_spec.rb +14 -0
  68. data/spec/unit/lib/angellist_api/client/startups_spec.rb +40 -0
  69. data/spec/unit/lib/angellist_api/client/status_updates_spec.rb +30 -0
  70. data/spec/unit/lib/angellist_api/client/tags_spec.rb +39 -0
  71. data/spec/unit/lib/angellist_api/client/users_spec.rb +39 -0
  72. data/spec/{lib → unit/lib}/angellist_api/configuration_spec.rb +12 -11
  73. data/spec/unit/lib/angellist_api/error_spec.rb +124 -0
  74. data/spec/unit/lib/angellist_api/request_spec.rb +32 -0
  75. data/spec/unit/lib/angellist_api_spec.rb +42 -0
  76. metadata +128 -71
  77. data/lib/faraday/request/angellist_api_oauth.rb +0 -14
  78. data/lib/faraday/request/gateway.rb +0 -18
  79. data/lib/faraday/request/multipart_with_file.rb +0 -36
  80. data/lib/faraday/request/phoenix.rb +0 -18
  81. data/lib/faraday/response/raise_http_4xx.rb +0 -45
  82. data/lib/faraday/response/raise_http_5xx.rb +0 -24
  83. data/spec/lib/angellist_api/authentication_spec.rb +0 -53
  84. data/spec/lib/angellist_api/client/activity_feeds_spec.rb +0 -16
  85. data/spec/lib/angellist_api/client/follows_spec.rb +0 -74
  86. data/spec/lib/angellist_api/client/reviews_spec.rb +0 -16
  87. data/spec/lib/angellist_api/client/startup_roles_spec.rb +0 -16
  88. data/spec/lib/angellist_api/client/startups_spec.rb +0 -23
  89. data/spec/lib/angellist_api/client/status_updates_spec.rb +0 -32
  90. data/spec/lib/angellist_api/client/tags_spec.rb +0 -40
  91. data/spec/lib/angellist_api/client/users_spec.rb +0 -30
  92. data/spec/lib/angellist_api/error_spec.rb +0 -126
  93. data/spec/lib/angellist_api/request_spec.rb +0 -51
  94. data/spec/lib/angellist_api_spec.rb +0 -38
@@ -1,14 +0,0 @@
1
- require 'faraday'
2
-
3
- module Faraday
4
- class Request::AngellistApiOAuth < Faraday::Middleware
5
- def call(env)
6
- env[:request_headers]['Authorization'] = "Bearer #{@options[:access_token]}" if @options[:access_token]
7
- @app.call(env)
8
- end
9
-
10
- def initialize(app, options)
11
- @app, @options = app, options
12
- end
13
- end
14
- end
@@ -1,18 +0,0 @@
1
- require 'faraday'
2
-
3
- # @private
4
- module Faraday
5
- # @private
6
- class Request::Gateway < Faraday::Middleware
7
- def call(env)
8
- url = env[:url].dup
9
- url.host = @gateway
10
- env[:url] = url
11
- @app.call(env)
12
- end
13
-
14
- def initialize(app, gateway)
15
- @app, @gateway = app, gateway
16
- end
17
- end
18
- end
@@ -1,36 +0,0 @@
1
- require 'faraday'
2
-
3
- # @private
4
- module Faraday
5
- # @private
6
- class Request::MultipartWithFile < Faraday::Middleware
7
- def call(env)
8
- if env[:body].is_a?(Hash)
9
- env[:body].each do |key, value|
10
- if value.is_a?(File)
11
- env[:body][key] = Faraday::UploadIO.new(value, mime_type(value.path), value.path)
12
- elsif value.is_a?(Hash) && (value['io'].is_a?(IO) || value['io'].is_a?(StringIO))
13
- env[:body][key] = Faraday::UploadIO.new(value['io'], mime_type('.'+value['type']), '')
14
- end
15
- end
16
- end
17
-
18
- @app.call(env)
19
- end
20
-
21
- private
22
-
23
- def mime_type(path)
24
- case path
25
- when /\.jpe?g/i
26
- 'image/jpeg'
27
- when /\.gif$/i
28
- 'image/gif'
29
- when /\.png$/i
30
- 'image/png'
31
- else
32
- 'application/octet-stream'
33
- end
34
- end
35
- end
36
- end
@@ -1,18 +0,0 @@
1
- require 'faraday'
2
-
3
- module Faraday
4
- class Request::Phoenix < Faraday::Middleware
5
- def call(env)
6
- # Not sure what what the X-Phx (Phoenix?) header is for but it's
7
- # required to access certain undocumented resources
8
- # e.g. GET urls/resolve
9
- env[:request_headers]['X-Phx'] = 'true'
10
-
11
- @app.call(env)
12
- end
13
-
14
- def initialize(app)
15
- @app = app
16
- end
17
- end
18
- end
@@ -1,45 +0,0 @@
1
- require 'faraday'
2
-
3
- # @private
4
- module Faraday
5
- # @private
6
- class Response::RaiseHttp4xx < Response::Middleware
7
- def on_complete(env)
8
- case env[:status].to_i
9
- when 400
10
- raise AngellistApi::BadRequest.new(error_message(env), env[:response_headers])
11
- when 401
12
- raise AngellistApi::Unauthorized.new(error_message(env), env[:response_headers])
13
- when 403
14
- raise AngellistApi::Forbidden.new(error_message(env), env[:response_headers])
15
- when 404
16
- raise AngellistApi::NotFound.new(error_message(env), env[:response_headers])
17
- when 406
18
- raise AngellistApi::NotAcceptable.new(error_message(env), env[:response_headers])
19
- when 420
20
- raise AngellistApi::EnhanceYourCalm.new(error_message(env), env[:response_headers])
21
- end
22
- end
23
-
24
- private
25
-
26
- def error_message(env)
27
- "#{env[:method].to_s.upcase} #{env[:url].to_s}: #{env[:status]}#{error_body(env[:body])}"
28
- end
29
-
30
- def error_body(body)
31
- if body.nil?
32
- nil
33
- elsif body['error']
34
- ": #{body['error']}"
35
- elsif body['errors']
36
- first = Array(body['errors']).first
37
- if first.kind_of? Hash
38
- ": #{first['message'].chomp}"
39
- else
40
- ": #{first.chomp}"
41
- end
42
- end
43
- end
44
- end
45
- end
@@ -1,24 +0,0 @@
1
- require 'faraday'
2
-
3
- # @private
4
- module Faraday
5
- # @private
6
- class Response::RaiseHttp5xx < Response::Middleware
7
- def on_complete(env)
8
- case env[:status].to_i
9
- when 500
10
- raise AngellistApi::InternalServerError.new(error_message(env, "Something is technically wrong."), env[:response_headers])
11
- when 502
12
- raise AngellistApi::BadGateway.new(error_message(env, "AngellistApi is down or being upgraded."), env[:response_headers])
13
- when 503
14
- raise AngellistApi::ServiceUnavailable.new(error_message(env, "(__-){ AngellistApi is over capacity."), env[:response_headers])
15
- end
16
- end
17
-
18
- private
19
-
20
- def error_message(env, body=nil)
21
- "#{env[:method].to_s.upcase} #{env[:url].to_s}: #{[env[:status].to_s + ':', body].compact.join(' ')} You should follow @angellistapi for frequent updates. And please, send your feedback to api@angel.co. Happy hacking!"
22
- end
23
- end
24
- end
@@ -1,53 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe AngellistApi::Authentication do
4
- class BasicClass
5
- include AngellistApi::Authentication
6
- end
7
-
8
- class FullClass
9
- include AngellistApi::Authentication
10
- attr_accessor :access_token
11
- end
12
-
13
- describe "#authentication" do
14
- context "without auth variables defined" do
15
- it "should return a hash with nil values" do
16
- a = BasicClass.new
17
- a.send(:authentication).values.any?.should be_false
18
- end
19
- end
20
-
21
- context "with auth variables defined" do
22
- before(:each) do
23
- @a = FullClass.new
24
- end
25
-
26
- it "should return a hash with nil values if auth variables are not set" do
27
- @a.send(:authentication).values.all?.should be_false
28
- end
29
-
30
- it "should return a hash with nil values if auth variables are set" do
31
- @a.access_token = "token"
32
- @a.send(:authentication).values.all?.should be_true
33
- end
34
- end
35
- end
36
-
37
- describe "#authenticated?" do
38
- before(:each) do
39
- @a = FullClass.new
40
- end
41
-
42
- it "should return false if authentication has any nil values" do
43
- @a.expects(:authentication).returns({:access_token=>nil})
44
- @a.send(:authenticated?).should be_false
45
- end
46
-
47
- it "should return true if authentication has no nil values" do
48
- @a.expects(:authentication).returns({:access_token=>"1"})
49
- @a.send(:authenticated?).should be_true
50
- end
51
- end
52
-
53
- end
@@ -1,16 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe AngellistApi::Client::ActivityFeeds do
4
- before(:each) do
5
- @client = AngellistApi::Client.new
6
- end
7
-
8
- describe "#get_feed" do
9
- it "should get 1/feed" do
10
- options = { :some => "options" }
11
- @client.expects(:get).with("1/feed", options, :format => :json, :phoenix => true).returns("success")
12
- @client.get_feed(options).should == "success"
13
- end
14
- end
15
-
16
- end
@@ -1,74 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe AngellistApi::Client::Follows do
4
- before(:each) do
5
- @client = AngellistApi::Client.new
6
- end
7
-
8
- describe "#new_follow" do
9
- it "should post to 1/follows" do
10
- options = { :some => "options" }
11
- @client.expects(:post).with("1/follows", options, :format => :json, :phoenix => true).returns("success")
12
- @client.new_follow(options).should == "success"
13
- end
14
- end
15
-
16
- describe "#delete_follow" do
17
- it "should delete 1/follows" do
18
- options = { :some => "options" }
19
- @client.expects(:delete).with("1/follows", options, :format => :json, :phoenix => true).returns("success")
20
- @client.delete_follow(options).should == "success"
21
- end
22
- end
23
-
24
- describe "#get_user_followers" do
25
- it "should get 1/users/<id>/followers" do
26
- id = "123"
27
- @client.expects(:get).with("1/users/#{id}/followers", :format => :json, :phoenix => true).returns("success")
28
- @client.get_user_followers(id).should == "success"
29
- end
30
- end
31
-
32
- describe "#get_user_follower_ids" do
33
- it "should get 1/users/<id>/followers/ids" do
34
- id = "123"
35
- @client.expects(:get).with("1/users/#{id}/followers/ids", :format => :json, :phoenix => true).returns("success")
36
- @client.get_user_follower_ids(id).should == "success"
37
- end
38
- end
39
-
40
- describe "#get_user_following" do
41
- it "should get 1/users/<id>/following" do
42
- id = "123"
43
- options = { :some => "options" }
44
- @client.expects(:get).with("1/users/#{id}/following", options, :format => :json, :phoenix => true).returns("success")
45
- @client.get_user_following(id, options).should == "success"
46
- end
47
- end
48
-
49
- describe "#get_user_following_ids" do
50
- it "should get 1/users/<id>/following/ids" do
51
- id = "123"
52
- options = { :some => "options" }
53
- @client.expects(:get).with("1/users/#{id}/following/ids", options, :format => :json, :phoenix => true).returns("success")
54
- @client.get_user_following_ids(id, options).should == "success"
55
- end
56
- end
57
-
58
- describe "#get_startup_followers" do
59
- it "should get 1/startups/<id>/followers" do
60
- id = "123"
61
- @client.expects(:get).with("1/startups/#{id}/followers", :format => :json, :phoenix => true).returns("success")
62
- @client.get_startup_followers(id).should == "success"
63
- end
64
- end
65
-
66
- describe "#get_startup_follower_ids" do
67
- it "should get 1/startups/<id>/followers/ids" do
68
- id = "123"
69
- @client.expects(:get).with("1/startups/#{id}/followers/ids", :format => :json, :phoenix => true).returns("success")
70
- @client.get_startup_follower_ids(id).should == "success"
71
- end
72
- end
73
-
74
- end
@@ -1,16 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe AngellistApi::Client::Reviews do
4
- before(:each) do
5
- @client = AngellistApi::Client.new
6
- end
7
-
8
- describe "#get_reviews" do
9
- it "should get 1/reviews" do
10
- options = { :some => "options" }
11
- @client.expects(:get).with("1/reviews", options, :format => :json, :phoenix => true).returns("success")
12
- @client.get_reviews(options).should == "success"
13
- end
14
- end
15
-
16
- end
@@ -1,16 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe AngellistApi::Client::StartupRoles do
4
- before(:each) do
5
- @client = AngellistApi::Client.new
6
- end
7
-
8
- describe "#get_startup_roles" do
9
- it "should get to 1/follows" do
10
- options = { :some => "options" }
11
- @client.expects(:get).with("1/startup_roles", options, :format => :json, :phoenix => true).returns("success")
12
- @client.get_startup_roles(options).should == "success"
13
- end
14
- end
15
-
16
- end
@@ -1,23 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe AngellistApi::Client::Startups do
4
- before(:each) do
5
- @client = AngellistApi::Client.new
6
- end
7
-
8
- describe "#get_startup" do
9
- it "should get 1/startups/<id>" do
10
- id = "123"
11
- @client.expects(:get).with("1/startups/#{id}", :format => :json, :phoenix => true).returns("success")
12
- @client.get_startup(id).should == "success"
13
- end
14
- end
15
-
16
- describe "#startup_search" do
17
- it "should get 1/startups/search" do
18
- options = { :some => "options" }
19
- @client.expects(:get).with("1/startups/search", options, :format => :json, :phoenix => true).returns("success")
20
- @client.startup_search(options).should == "success"
21
- end
22
- end
23
- end
@@ -1,32 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe AngellistApi::Client::StatusUpdates do
4
- before(:each) do
5
- @client = AngellistApi::Client.new
6
- end
7
-
8
- describe "#get_status_updates" do
9
- it "should get 1/status_updates" do
10
- options = { :some => "options" }
11
- @client.expects(:get).with("1/status_updates", options, :format => :json, :phoenix => true).returns("success")
12
- @client.get_status_updates(options).should == "success"
13
- end
14
- end
15
-
16
- describe "#post_status_updates" do
17
- it "should post to 1/status_updates" do
18
- options = { :some => "options" }
19
- @client.expects(:post).with("1/status_updates", options, :format => :json, :phoenix => true).returns("success")
20
- @client.post_status_updates(options).should == "success"
21
- end
22
- end
23
-
24
- describe "#delete_status_updates" do
25
- it "should delete 1/status_updates/<id>" do
26
- id = "123"
27
- @client.expects(:delete).with("1/status_updates/#{id}", :format => :json, :phoenix => true).returns("success")
28
- @client.delete_status_updates(id).should == "success"
29
- end
30
- end
31
-
32
- end
@@ -1,40 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe AngellistApi::Client::Tags do
4
- before(:each) do
5
- @client = AngellistApi::Client.new
6
- end
7
-
8
- describe "#get_tag" do
9
- it "should get 1/tags/<id>" do
10
- id = "123"
11
- @client.expects(:get).with("1/tags/#{id}", :format => :json, :phoenix => true).returns("success")
12
- @client.get_tag(id).should == "success"
13
- end
14
- end
15
-
16
- describe "#get_tag_children" do
17
- it "should get 1/tags/<id>/children" do
18
- id = "123"
19
- @client.expects(:get).with("1/tags/#{id}/children", :format => :json, :phoenix => true).returns("success")
20
- @client.get_tag_children(id).should == "success"
21
- end
22
- end
23
-
24
- describe "#get_tag_parents" do
25
- it "should get 1/tags/<id>/parents" do
26
- id = "123"
27
- @client.expects(:get).with("1/tags/#{id}/parents", :format => :json, :phoenix => true).returns("success")
28
- @client.get_tag_parents(id).should == "success"
29
- end
30
- end
31
-
32
- describe "#get_tag_startups" do
33
- it "should get 1/tags/<id>/startups" do
34
- id = "123"
35
- options = { :some => "options" }
36
- @client.expects(:get).with("1/tags/#{id}/startups", options, :format => :json, :phoenix => true).returns("success")
37
- @client.get_tag_startups(id, options).should == "success"
38
- end
39
- end
40
- end
@@ -1,30 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe AngellistApi::Client::Users do
4
- before(:each) do
5
- @client = AngellistApi::Client.new
6
- end
7
-
8
- describe "#get_user" do
9
- it "should get 1/users/<id>" do
10
- id = "123"
11
- @client.expects(:get).with("1/users/#{id}", :format => :json, :phoenix => true).returns("success")
12
- @client.get_user(id).should == "success"
13
- end
14
- end
15
-
16
- describe "#user_search" do
17
- it "should get 1/users/search" do
18
- options = { :some => "options "}
19
- @client.expects(:get).with("1/users/search", options, :format => :json, :phoenix => true).returns("success")
20
- @client.user_search(options).should == "success"
21
- end
22
- end
23
-
24
- describe "#me" do
25
- it "should get 1/me" do
26
- @client.expects(:get).with("1/me", :format => :json, :phoenix => true).returns("success")
27
- @client.me.should == "success"
28
- end
29
- end
30
- end