angellist_api 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. data/CHANGELOG.md +8 -0
  2. data/README.md +8 -2
  3. data/Rakefile +8 -25
  4. data/lib/angellist_api/authentication.rb +1 -4
  5. data/lib/angellist_api/client.rb +2 -0
  6. data/lib/angellist_api/client/activity_feeds.rb +19 -0
  7. data/lib/angellist_api/client/follows.rb +2 -2
  8. data/lib/angellist_api/client/tags.rb +1 -1
  9. data/lib/angellist_api/configuration.rb +4 -19
  10. data/lib/angellist_api/connection.rb +1 -1
  11. data/lib/angellist_api/request.rb +1 -1
  12. data/lib/angellist_api/version.rb +2 -1
  13. data/lib/faraday/request/angellist_api_oauth.rb +14 -0
  14. data/spec/lib/angellist_api/api_spec.rb +42 -0
  15. data/spec/lib/angellist_api/authentication_spec.rb +53 -0
  16. data/spec/lib/angellist_api/client/activity_feeds_spec.rb +16 -0
  17. data/spec/lib/angellist_api/client/follows_spec.rb +74 -0
  18. data/spec/lib/angellist_api/client/reviews_spec.rb +16 -0
  19. data/spec/lib/angellist_api/client/startup_roles_spec.rb +16 -0
  20. data/spec/lib/angellist_api/client/startups_spec.rb +23 -0
  21. data/spec/lib/angellist_api/client/status_updates_spec.rb +32 -0
  22. data/spec/lib/angellist_api/client/tags_spec.rb +40 -0
  23. data/spec/lib/angellist_api/client/users_spec.rb +30 -0
  24. data/spec/lib/angellist_api/configuration_spec.rb +49 -0
  25. data/spec/lib/angellist_api/error_spec.rb +126 -0
  26. data/spec/lib/angellist_api/request_spec.rb +51 -0
  27. data/spec/lib/angellist_api_spec.rb +38 -0
  28. data/spec/spec_helper.rb +14 -0
  29. metadata +154 -144
  30. data/lib/faraday/request/twitter_oauth.rb +0 -24
  31. data/lib/tasks/angellist_api_tasks.rake +0 -4
  32. data/test/angellist_api_test.rb +0 -7
  33. data/test/dummy/Rakefile +0 -7
  34. data/test/dummy/app/assets/javascripts/application.js +0 -9
  35. data/test/dummy/app/assets/stylesheets/application.css +0 -7
  36. data/test/dummy/app/controllers/application_controller.rb +0 -3
  37. data/test/dummy/app/helpers/application_helper.rb +0 -2
  38. data/test/dummy/app/views/layouts/application.html.erb +0 -14
  39. data/test/dummy/config.ru +0 -4
  40. data/test/dummy/config/application.rb +0 -42
  41. data/test/dummy/config/boot.rb +0 -10
  42. data/test/dummy/config/database.yml +0 -25
  43. data/test/dummy/config/environment.rb +0 -5
  44. data/test/dummy/config/environments/development.rb +0 -27
  45. data/test/dummy/config/environments/production.rb +0 -51
  46. data/test/dummy/config/environments/test.rb +0 -39
  47. data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
  48. data/test/dummy/config/initializers/inflections.rb +0 -10
  49. data/test/dummy/config/initializers/mime_types.rb +0 -5
  50. data/test/dummy/config/initializers/secret_token.rb +0 -7
  51. data/test/dummy/config/initializers/session_store.rb +0 -8
  52. data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
  53. data/test/dummy/config/locales/en.yml +0 -5
  54. data/test/dummy/config/routes.rb +0 -58
  55. data/test/dummy/public/404.html +0 -26
  56. data/test/dummy/public/422.html +0 -26
  57. data/test/dummy/public/500.html +0 -26
  58. data/test/dummy/public/favicon.ico +0 -0
  59. data/test/dummy/script/rails +0 -6
  60. data/test/test_helper.rb +0 -10
@@ -0,0 +1,8 @@
1
+ ## 0.1.2 - 22 March, 2012
2
+
3
+ - Relax Hashie dependency, in particular to avoid dep conflict with
4
+ omniauth-angellist.
5
+
6
+
7
+ <!-- vim: set tw=80 :-->
8
+
data/README.md CHANGED
@@ -1,10 +1,13 @@
1
1
  # The AngelList API Ruby Gem
2
- A Ruby wrapper for the AngelList REST APIs
2
+
3
+ A Ruby wrapper for the [AngelList REST APIs][].
3
4
 
4
5
  ## <a name="installation">Installation</a>
5
- gem install angellist-api
6
+
7
+ gem install angellist_api
6
8
 
7
9
  ## <a name="pulls">Submitting a Pull Request</a>
10
+
8
11
  1. Fork the project.
9
12
  2. Create a topic branch.
10
13
  3. Implement your feature or bug fix.
@@ -14,3 +17,6 @@ A Ruby wrapper for the AngelList REST APIs
14
17
  7. Run <tt>bundle exec rake spec</tt>. If your changes are not 100% covered, go back to step 6.
15
18
  8. Commit and push your changes.
16
19
  9. Submit a pull request. Please do not include changes to the gemspec, version, or history file. (If you want to create your own version for some reason, please do so in a separate commit.)
20
+
21
+ [AngelList REST APIs]: http://angel.co/api
22
+
data/Rakefile CHANGED
@@ -1,37 +1,20 @@
1
- #!/usr/bin/env rake
2
1
  begin
3
2
  require 'bundler/setup'
4
3
  rescue LoadError
5
4
  puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
5
  end
7
- begin
8
- require 'rdoc/task'
9
- rescue LoadError
10
- require 'rdoc/rdoc'
11
- require 'rake/rdoctask'
12
- RDoc::Task = Rake::RDocTask
13
- end
14
-
15
- RDoc::Task.new(:rdoc) do |rdoc|
16
- rdoc.rdoc_dir = 'rdoc'
17
- rdoc.title = 'AngellistApi'
18
- rdoc.options << '--line-numbers'
19
- rdoc.rdoc_files.include('README.rdoc')
20
- rdoc.rdoc_files.include('lib/**/*.rb')
21
- end
22
-
23
6
 
7
+ require 'yard'
24
8
 
25
9
  Bundler::GemHelper.install_tasks
26
10
 
27
- require 'rake/testtask'
11
+ require 'rspec/core/rake_task'
12
+ RSpec::Core::RakeTask.new(:spec)
28
13
 
29
- Rake::TestTask.new(:test) do |t|
30
- t.libs << 'lib'
31
- t.libs << 'test'
32
- t.pattern = 'test/**/*_test.rb'
33
- t.verbose = false
34
- end
14
+ task :test => :spec
15
+ task :default => :spec
35
16
 
17
+ YARD::Rake::YardocTask.new do |t|
18
+ t.files = ['lib/**/*.rb', 'README.md']
19
+ end
36
20
 
37
- task :default => :test
@@ -8,10 +8,7 @@ module AngellistApi
8
8
  # @return [Hash]
9
9
  def authentication
10
10
  {
11
- :consumer_key => consumer_key,
12
- :consumer_secret => consumer_secret,
13
- :token => oauth_token,
14
- :token_secret => oauth_token_secret,
11
+ :access_token => respond_to?(:access_token) ? access_token : nil,
15
12
  }
16
13
  end
17
14
 
@@ -6,6 +6,7 @@ module AngellistApi
6
6
  # Require client method modules after initializing the Client class in
7
7
  # order to avoid a superclass mismatch error, allowing those modules to be
8
8
  # Client-namespaced.
9
+ require 'angellist_api/client/activity_feeds'
9
10
  require 'angellist_api/client/follows'
10
11
  require 'angellist_api/client/reviews'
11
12
  require 'angellist_api/client/startups'
@@ -16,6 +17,7 @@ module AngellistApi
16
17
 
17
18
  alias :api_endpoint :endpoint
18
19
 
20
+ include AngellistApi::Client::ActivityFeeds
19
21
  include AngellistApi::Client::Follows
20
22
  include AngellistApi::Client::Reviews
21
23
  include AngellistApi::Client::Startups
@@ -0,0 +1,19 @@
1
+ module AngellistApi
2
+ class Client
3
+ # Defines methods related to URLs
4
+ module ActivityFeeds
5
+
6
+ # Returns site activity. If authenticated and the personalized parameter is passed in, only activity from the authenticated user's social graph is returned. No more than 25 items will be returned. Results are paginated and ordered by most recent story first.
7
+ # @requires_authentication Optional
8
+ # @response_format `json`
9
+ # @param options [Hash] A customizable set of options.
10
+ # @option options [Integer] :personalized If set to 1 and a user is authenticated, only activity from the authenticated user's social graph is returned.
11
+ # @example
12
+ # AngellistApi.get_feed
13
+ def get_feed(options={})
14
+ get("1/feed", options, :format => :json, :phoenix => true)
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -55,7 +55,7 @@ module AngellistApi
55
55
  # @example Return objects that the given user is following, paginated and ordered by most recent follow first. See the type parameter to specify which class of objects to return.
56
56
  # AngellistApi.get_user_following
57
57
  def get_user_following(id, options={})
58
- get("1/users/#{id}/following ", options, :format => :json, :phoenix => true)
58
+ get("1/users/#{id}/following", options, :format => :json, :phoenix => true)
59
59
  end
60
60
 
61
61
  # Return ids of objects that the given user is following, paginated and ordered by most recent follow first. See the type parameter to specify which class of objects to return. Responds like GET /users/:id/followers/ids.
@@ -67,7 +67,7 @@ module AngellistApi
67
67
  # @example Return ids of objects that the given user is following, paginated and ordered by most recent follow first. See the type parameter to specify which class of objects to return. Responds like GET /users/:id/followers/ids.
68
68
  # AngellistApi.get_user_following_ids
69
69
  def get_user_following_ids(id, options={})
70
- get("1/users/#{id}/following/ids ", options, :format => :json, :phoenix => true)
70
+ get("1/users/#{id}/following/ids", options, :format => :json, :phoenix => true)
71
71
  end
72
72
 
73
73
  # Returns the given startup's followers, paginated and ordered by most recent follower first. Responds like GET /users/:id/followers.
@@ -39,7 +39,7 @@ module AngellistApi
39
39
  # @option options [String] :order May be one of popularity, asc or desc. Startups will be ordered by number of followers, ascending id or descending id, respectively. Defaults to desc
40
40
  # @example Returns Returns startups that are tagged with the given tag or a child of the given tag. Results are paginated and ordered according to the order parameter.
41
41
  # AngellistApi.get_tag_startups
42
- def get_tag_startups(options = {})
42
+ def get_tag_startups(id, options = {})
43
43
  get("1/tags/#{id}/startups", options, :format => :json, :phoenix => true)
44
44
  end
45
45
  end
@@ -6,13 +6,10 @@ module AngellistApi
6
6
  # An array of valid keys in the options hash when configuring a {AngellistApi::API}
7
7
  VALID_OPTIONS_KEYS = [
8
8
  :adapter,
9
- :consumer_key,
10
- :consumer_secret,
11
9
  :endpoint,
12
10
  :format,
13
11
  :gateway,
14
- :oauth_token,
15
- :oauth_token_secret,
12
+ :access_token,
16
13
  :proxy,
17
14
  :user_agent,
18
15
  :faraday_options].freeze
@@ -20,12 +17,6 @@ module AngellistApi
20
17
  # The adapter that will be used to connect if none is set
21
18
  DEFAULT_ADAPTER = :net_http
22
19
 
23
- # By default, don't set an application key
24
- DEFAULT_CONSUMER_KEY = nil
25
-
26
- # By default, don't set an application secret
27
- DEFAULT_CONSUMER_SECRET = nil
28
-
29
20
  # The endpoint that will be used to connect if none is set
30
21
  DEFAULT_ENDPOINT = "https://api.angel.co/".freeze
31
22
 
@@ -34,11 +25,8 @@ module AngellistApi
34
25
  # @note JSON is preferred over XML because it is more concise and faster to parse.
35
26
  DEFAULT_FORMAT = :json
36
27
 
37
- # By default, don't set a user oauth token
38
- DEFAULT_OAUTH_TOKEN = nil
39
-
40
- # By default, don't set a user oauth secret
41
- DEFAULT_OAUTH_TOKEN_SECRET = nil
28
+ # By default, don't set a user oauth access token
29
+ DEFAULT_ACCESS_TOKEN = nil
42
30
 
43
31
  # By default, don't use a proxy server
44
32
  DEFAULT_PROXY = nil
@@ -73,12 +61,9 @@ module AngellistApi
73
61
  # Reset all configuration options to defaults
74
62
  def reset
75
63
  self.adapter = DEFAULT_ADAPTER
76
- self.consumer_key = DEFAULT_CONSUMER_KEY
77
- self.consumer_secret = DEFAULT_CONSUMER_SECRET
78
64
  self.endpoint = DEFAULT_ENDPOINT
79
65
  self.format = DEFAULT_FORMAT
80
- self.oauth_token = DEFAULT_OAUTH_TOKEN
81
- self.oauth_token_secret = DEFAULT_OAUTH_TOKEN_SECRET
66
+ self.access_token = DEFAULT_ACCESS_TOKEN
82
67
  self.proxy = DEFAULT_PROXY
83
68
  self.user_agent = DEFAULT_USER_AGENT
84
69
  self.gateway = DEFAULT_GATEWAY
@@ -2,7 +2,7 @@ require 'faraday_middleware'
2
2
  require 'faraday/request/phoenix'
3
3
  require 'faraday/request/multipart_with_file'
4
4
  require 'faraday/request/gateway'
5
- require 'faraday/request/twitter_oauth'
5
+ require 'faraday/request/angellist_api_oauth'
6
6
  require 'faraday/response/raise_http_4xx'
7
7
  require 'faraday/response/raise_http_5xx'
8
8
 
@@ -37,7 +37,7 @@ module AngellistApi
37
37
  end
38
38
 
39
39
  def formatted_path(path, options={})
40
- [path, options.fetch(:format, format)].compact.join('.')
40
+ path
41
41
  end
42
42
  end
43
43
  end
@@ -1,3 +1,4 @@
1
1
  module AngellistApi
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.2"
3
3
  end
4
+
@@ -0,0 +1,14 @@
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
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe AngellistApi::API do
4
+
5
+ describe "#initialize" do
6
+ context "without passing new options" do
7
+ it "should use the default options" do
8
+ api = AngellistApi::API.new
9
+ AngellistApi::Configuration::VALID_OPTIONS_KEYS.each do |valid_key|
10
+ api.send(valid_key).should == AngellistApi.options[valid_key]
11
+ end
12
+ end
13
+ end
14
+
15
+ context "while passing custom options" do
16
+ it "should use the new options" do
17
+ key_to_overwrite = AngellistApi.options.keys.first
18
+ overwrite_value = "NEW VALUE!!"
19
+
20
+ api = AngellistApi::API.new(key_to_overwrite => overwrite_value)
21
+ AngellistApi::Configuration::VALID_OPTIONS_KEYS.each do |valid_key|
22
+ expected_value = valid_key == key_to_overwrite ? overwrite_value : AngellistApi.options[valid_key]
23
+ api.send(valid_key).should == expected_value
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ describe "configuration" do
30
+ before(:each) do
31
+ @api = AngellistApi::API.new
32
+ end
33
+
34
+ AngellistApi::Configuration::VALID_OPTIONS_KEYS.each do |config_key|
35
+ it "should allow the value of #{config_key} to be set" do
36
+ lambda { @api.send("#{config_key}=", "SOME NEW VALUE") }.should_not raise_error
37
+ @api.send(config_key).should == "SOME NEW VALUE"
38
+ end
39
+ end
40
+ end
41
+
42
+ end
@@ -0,0 +1,53 @@
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
@@ -0,0 +1,16 @@
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
@@ -0,0 +1,74 @@
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
@@ -0,0 +1,16 @@
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