angellist_api 0.0.1
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.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +37 -0
- data/lib/angellist_api.rb +28 -0
- data/lib/angellist_api/api.rb +24 -0
- data/lib/angellist_api/authentication.rb +25 -0
- data/lib/angellist_api/client.rb +27 -0
- data/lib/angellist_api/client/follows.rb +96 -0
- data/lib/angellist_api/client/reviews.rb +17 -0
- data/lib/angellist_api/client/startup_roles.rb +18 -0
- data/lib/angellist_api/client/startups.rb +28 -0
- data/lib/angellist_api/client/status_updates.rb +40 -0
- data/lib/angellist_api/client/tags.rb +47 -0
- data/lib/angellist_api/client/users.rb +37 -0
- data/lib/angellist_api/configuration.rb +90 -0
- data/lib/angellist_api/connection.rb +48 -0
- data/lib/angellist_api/error.rb +59 -0
- data/lib/angellist_api/request.rb +43 -0
- data/lib/angellist_api/version.rb +3 -0
- data/lib/tasks/angellist_api_tasks.rake +4 -0
- data/test/angellist_api_test.rb +7 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +9 -0
- data/test/dummy/app/assets/stylesheets/application.css +7 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +42 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +27 -0
- data/test/dummy/config/environments/production.rb +51 -0
- data/test/dummy/config/environments/test.rb +39 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +10 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +58 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +26 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/test_helper.rb +10 -0
- metadata +136 -0
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'angellist_api/version'
|
2
|
+
|
3
|
+
module AngellistApi
|
4
|
+
# Defines constants and methods related to configuration
|
5
|
+
module Configuration
|
6
|
+
# An array of valid keys in the options hash when configuring a {AngellistApi::API}
|
7
|
+
VALID_OPTIONS_KEYS = [
|
8
|
+
:adapter,
|
9
|
+
:consumer_key,
|
10
|
+
:consumer_secret,
|
11
|
+
:endpoint,
|
12
|
+
:format,
|
13
|
+
:gateway,
|
14
|
+
:oauth_token,
|
15
|
+
:oauth_token_secret,
|
16
|
+
:proxy,
|
17
|
+
:user_agent,
|
18
|
+
:media_endpoint,
|
19
|
+
:faraday_options].freeze
|
20
|
+
|
21
|
+
# The adapter that will be used to connect if none is set
|
22
|
+
DEFAULT_ADAPTER = :net_http
|
23
|
+
|
24
|
+
# By default, don't set an application key
|
25
|
+
DEFAULT_CONSUMER_KEY = nil
|
26
|
+
|
27
|
+
# By default, don't set an application secret
|
28
|
+
DEFAULT_CONSUMER_SECRET = nil
|
29
|
+
|
30
|
+
# The endpoint that will be used to connect if none is set
|
31
|
+
DEFAULT_ENDPOINT = 'https://api.angel.co/1'.freeze
|
32
|
+
|
33
|
+
# The response format appended to the path and sent in the 'Accept' header if none is set
|
34
|
+
#
|
35
|
+
# @note JSON is preferred over XML because it is more concise and faster to parse.
|
36
|
+
DEFAULT_FORMAT = :json
|
37
|
+
|
38
|
+
# By default, don't set a user oauth token
|
39
|
+
DEFAULT_OAUTH_TOKEN = nil
|
40
|
+
|
41
|
+
# By default, don't set a user oauth secret
|
42
|
+
DEFAULT_OAUTH_TOKEN_SECRET = nil
|
43
|
+
|
44
|
+
# By default, don't use a proxy server
|
45
|
+
DEFAULT_PROXY = nil
|
46
|
+
|
47
|
+
# The value sent in the 'User-Agent' header if none is set
|
48
|
+
DEFAULT_USER_AGENT = "AngellistApi Ruby Gem #{AngellistApi::VERSION}".freeze
|
49
|
+
|
50
|
+
DEFAULT_GATEWAY = nil
|
51
|
+
|
52
|
+
DEFAULT_FARADAY_OPTIONS = {}.freeze
|
53
|
+
|
54
|
+
# @private
|
55
|
+
attr_accessor *VALID_OPTIONS_KEYS
|
56
|
+
|
57
|
+
# When this module is extended, set all configuration options to their default values
|
58
|
+
def self.extended(base)
|
59
|
+
base.reset
|
60
|
+
end
|
61
|
+
|
62
|
+
# Convenience method to allow configuration options to be set in a block
|
63
|
+
def configure
|
64
|
+
yield self
|
65
|
+
end
|
66
|
+
|
67
|
+
# Create a hash of options and their values
|
68
|
+
def options
|
69
|
+
options = {}
|
70
|
+
VALID_OPTIONS_KEYS.each{|k| options[k] = send(k)}
|
71
|
+
options
|
72
|
+
end
|
73
|
+
|
74
|
+
# Reset all configuration options to defaults
|
75
|
+
def reset
|
76
|
+
self.adapter = DEFAULT_ADAPTER
|
77
|
+
self.consumer_key = DEFAULT_CONSUMER_KEY
|
78
|
+
self.consumer_secret = DEFAULT_CONSUMER_SECRET
|
79
|
+
self.endpoint = DEFAULT_ENDPOINT
|
80
|
+
self.format = DEFAULT_FORMAT
|
81
|
+
self.oauth_token = DEFAULT_OAUTH_TOKEN
|
82
|
+
self.oauth_token_secret = DEFAULT_OAUTH_TOKEN_SECRET
|
83
|
+
self.proxy = DEFAULT_PROXY
|
84
|
+
self.user_agent = DEFAULT_USER_AGENT
|
85
|
+
self.gateway = DEFAULT_GATEWAY
|
86
|
+
self.faraday_options = DEFAULT_FARADAY_OPTIONS
|
87
|
+
self
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'faraday_middleware'
|
2
|
+
require 'faraday/request/phoenix'
|
3
|
+
require 'faraday/request/multipart_with_file'
|
4
|
+
require 'faraday/request/gateway'
|
5
|
+
require 'faraday/request/twitter_oauth'
|
6
|
+
require 'faraday/response/raise_http_4xx'
|
7
|
+
require 'faraday/response/raise_http_5xx'
|
8
|
+
|
9
|
+
module AngellistApi
|
10
|
+
# @private
|
11
|
+
module Connection
|
12
|
+
private
|
13
|
+
|
14
|
+
def connection(options={})
|
15
|
+
merged_options = faraday_options.merge({
|
16
|
+
:headers => {
|
17
|
+
'Accept' => "application/#{format}",
|
18
|
+
'User-Agent' => user_agent
|
19
|
+
},
|
20
|
+
:proxy => proxy,
|
21
|
+
:ssl => {:verify => false},
|
22
|
+
:url => options.fetch(:endpoint, api_endpoint)
|
23
|
+
})
|
24
|
+
|
25
|
+
Faraday.new(merged_options) do |builder|
|
26
|
+
builder.use Faraday::Request::Phoenix if options[:phoenix]
|
27
|
+
builder.use Faraday::Request::MultipartWithFile
|
28
|
+
builder.use Faraday::Request::AngellistApiOAuth, authentication if authenticated?
|
29
|
+
builder.use Faraday::Request::Multipart
|
30
|
+
builder.use Faraday::Request::UrlEncoded
|
31
|
+
builder.use Faraday::Request::Gateway, gateway if gateway
|
32
|
+
builder.use Faraday::Response::RaiseHttp4xx
|
33
|
+
unless options[:raw]
|
34
|
+
case options.fetch(:format, format).to_s.downcase
|
35
|
+
when 'json', 'phoenix'
|
36
|
+
builder.use Faraday::Response::Mashify
|
37
|
+
builder.use Faraday::Response::ParseJson
|
38
|
+
when 'xml'
|
39
|
+
builder.use Faraday::Response::Mashify
|
40
|
+
builder.use Faraday::Response::ParseXml
|
41
|
+
end
|
42
|
+
end
|
43
|
+
builder.use Faraday::Response::RaiseHttp5xx
|
44
|
+
builder.adapter(adapter)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module AngellistApi
|
2
|
+
# Custom error class for rescuing from all AngellistApi errors
|
3
|
+
class Error < StandardError
|
4
|
+
attr_reader :http_headers
|
5
|
+
|
6
|
+
def initialize(message, http_headers)
|
7
|
+
@http_headers = Hash[http_headers]
|
8
|
+
super message
|
9
|
+
end
|
10
|
+
|
11
|
+
def ratelimit_reset
|
12
|
+
Time.at(@http_headers.values_at('x-ratelimit-reset', 'X-RateLimit-Reset').detect{|value| value}.to_i)
|
13
|
+
end
|
14
|
+
|
15
|
+
def ratelimit_limit
|
16
|
+
@http_headers.values_at('x-ratelimit-limit', 'X-RateLimit-Limit').detect{|value| value}.to_i
|
17
|
+
end
|
18
|
+
|
19
|
+
def ratelimit_remaining
|
20
|
+
@http_headers.values_at('x-ratelimit-remaining', 'X-RateLimit-Remaining').detect{|value| value}.to_i
|
21
|
+
end
|
22
|
+
|
23
|
+
def retry_after
|
24
|
+
[(ratelimit_reset - Time.now).ceil, 0].max
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Raised when AngellistApi returns the HTTP status code 400
|
29
|
+
class BadRequest < Error; end
|
30
|
+
|
31
|
+
# Raised when AngellistApi returns the HTTP status code 401
|
32
|
+
class Unauthorized < Error; end
|
33
|
+
|
34
|
+
# Raised when AngellistApi returns the HTTP status code 403
|
35
|
+
class Forbidden < Error; end
|
36
|
+
|
37
|
+
# Raised when AngellistApi returns the HTTP status code 404
|
38
|
+
class NotFound < Error; end
|
39
|
+
|
40
|
+
# Raised when AngellistApi returns the HTTP status code 406
|
41
|
+
class NotAcceptable < Error; end
|
42
|
+
|
43
|
+
# Raised when AngellistApi returns the HTTP status code 420
|
44
|
+
class EnhanceYourCalm < Error
|
45
|
+
# The number of seconds your application should wait before requesting date from the API again
|
46
|
+
def retry_after
|
47
|
+
@http_headers.values_at('retry-after', 'Retry-After').detect {|value| value }.to_i
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Raised when AngellistApi returns the HTTP status code 500
|
52
|
+
class InternalServerError < Error; end
|
53
|
+
|
54
|
+
# Raised when AngellistApi returns the HTTP status code 502
|
55
|
+
class BadGateway < Error; end
|
56
|
+
|
57
|
+
# Raised when AngellistApi returns the HTTP status code 503
|
58
|
+
class ServiceUnavailable < Error; end
|
59
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module AngellistApi
|
2
|
+
# Defines HTTP request methods
|
3
|
+
module Request
|
4
|
+
# Perform an HTTP GET request
|
5
|
+
def get(path, params={}, options={})
|
6
|
+
request(:get, path, params, options)
|
7
|
+
end
|
8
|
+
|
9
|
+
def post(path, params={}, options={})
|
10
|
+
request(:post, path, params, options)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Perform an HTTP PUT request
|
14
|
+
def put(path, params={}, options={})
|
15
|
+
request(:put, path, params, options)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Perform an HTTP DELETE request
|
19
|
+
def delete(path, params={}, options={})
|
20
|
+
request(:delete, path, params, options)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
# Perform an HTTP request
|
26
|
+
def request(method, path, params, options)
|
27
|
+
response = connection(options).send(method) do |request|
|
28
|
+
case method.to_sym
|
29
|
+
when :get, :delete
|
30
|
+
request.url(formatted_path(path, options), params)
|
31
|
+
when :post, :put
|
32
|
+
request.path = formatted_path(path, options)
|
33
|
+
request.body = params unless params.empty?
|
34
|
+
end
|
35
|
+
end
|
36
|
+
options[:raw] ? response : response.body
|
37
|
+
end
|
38
|
+
|
39
|
+
def formatted_path(path, options={})
|
40
|
+
[path, options.fetch(:format, format)].compact.join('.')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/test/dummy/Rakefile
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
3
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
4
|
+
|
5
|
+
require File.expand_path('../config/application', __FILE__)
|
6
|
+
|
7
|
+
Dummy::Application.load_tasks
|
@@ -0,0 +1,9 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into including all the files listed below.
|
2
|
+
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
|
3
|
+
// be included in the compiled file accessible from http://example.com/assets/application.js
|
4
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
5
|
+
// the compiled file.
|
6
|
+
//
|
7
|
+
//= require jquery
|
8
|
+
//= require jquery_ujs
|
9
|
+
//= require_tree .
|
@@ -0,0 +1,7 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll automatically include all the stylesheets available in this directory
|
3
|
+
* and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
|
4
|
+
* the top of the compiled file, but it's generally better to create a new file per style scope.
|
5
|
+
*= require_self
|
6
|
+
*= require_tree .
|
7
|
+
*/
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
require 'rails/all'
|
4
|
+
|
5
|
+
Bundler.require
|
6
|
+
require "angellist_api"
|
7
|
+
|
8
|
+
module Dummy
|
9
|
+
class Application < Rails::Application
|
10
|
+
# Settings in config/environments/* take precedence over those specified here.
|
11
|
+
# Application configuration should go into files in config/initializers
|
12
|
+
# -- all .rb files in that directory are automatically loaded.
|
13
|
+
|
14
|
+
# Custom directories with classes and modules you want to be autoloadable.
|
15
|
+
# config.autoload_paths += %W(#{config.root}/extras)
|
16
|
+
|
17
|
+
# Only load the plugins named here, in the order given (default is alphabetical).
|
18
|
+
# :all can be used as a placeholder for all plugins not explicitly named.
|
19
|
+
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
|
20
|
+
|
21
|
+
# Activate observers that should always be running.
|
22
|
+
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
|
23
|
+
|
24
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
25
|
+
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
26
|
+
# config.time_zone = 'Central Time (US & Canada)'
|
27
|
+
|
28
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
29
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
30
|
+
# config.i18n.default_locale = :de
|
31
|
+
|
32
|
+
# Configure the default encoding used in templates for Ruby 1.9.
|
33
|
+
config.encoding = "utf-8"
|
34
|
+
|
35
|
+
# Configure sensitive parameters which will be filtered from the log file.
|
36
|
+
config.filter_parameters += [:password]
|
37
|
+
|
38
|
+
# Enable the asset pipeline
|
39
|
+
config.assets.enabled = true
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# SQLite version 3.x
|
2
|
+
# gem install sqlite3
|
3
|
+
#
|
4
|
+
# Ensure the SQLite 3 gem is defined in your Gemfile
|
5
|
+
# gem 'sqlite3'
|
6
|
+
development:
|
7
|
+
adapter: sqlite3
|
8
|
+
database: db/development.sqlite3
|
9
|
+
pool: 5
|
10
|
+
timeout: 5000
|
11
|
+
|
12
|
+
# Warning: The database defined as "test" will be erased and
|
13
|
+
# re-generated from your development database when you run "rake".
|
14
|
+
# Do not set this db to the same as development or production.
|
15
|
+
test:
|
16
|
+
adapter: sqlite3
|
17
|
+
database: db/test.sqlite3
|
18
|
+
pool: 5
|
19
|
+
timeout: 5000
|
20
|
+
|
21
|
+
production:
|
22
|
+
adapter: sqlite3
|
23
|
+
database: db/production.sqlite3
|
24
|
+
pool: 5
|
25
|
+
timeout: 5000
|
@@ -0,0 +1,27 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
3
|
+
|
4
|
+
# In the development environment your application's code is reloaded on
|
5
|
+
# every request. This slows down response time but is perfect for development
|
6
|
+
# since you don't have to restart the web server when you make code changes.
|
7
|
+
config.cache_classes = false
|
8
|
+
|
9
|
+
# Log error messages when you accidentally call methods on nil.
|
10
|
+
config.whiny_nils = true
|
11
|
+
|
12
|
+
# Show full error reports and disable caching
|
13
|
+
config.consider_all_requests_local = true
|
14
|
+
config.action_controller.perform_caching = false
|
15
|
+
|
16
|
+
# Don't care if the mailer can't send
|
17
|
+
config.action_mailer.raise_delivery_errors = false
|
18
|
+
|
19
|
+
# Print deprecation notices to the Rails logger
|
20
|
+
config.active_support.deprecation = :log
|
21
|
+
|
22
|
+
# Only use best-standards-support built into browsers
|
23
|
+
config.action_dispatch.best_standards_support = :builtin
|
24
|
+
|
25
|
+
# Do not compress assets
|
26
|
+
config.assets.compress = false
|
27
|
+
end
|