Omniauth-Stripe-Connect 开源项目教程
1. 项目的目录结构及介绍
omniauth-stripe-connect/
├── Gemfile
├── Gemfile.lock
├── LICENSE
├── README.md
├── Rakefile
├── lib/
│ ├── omniauth/
│ │ ├── strategies/
│ │ │ └── stripe_connect.rb
│ └── omniauth-stripe_connect.rb
├── omniauth-stripe_connect.gemspec
└── spec/
├── omniauth/
│ ├── strategies/
│ │ └── stripe_connect_spec.rb
└── spec_helper.rb
Gemfile
和Gemfile.lock
:定义了项目的依赖关系。LICENSE
:项目的许可证。README.md
:项目的说明文档。Rakefile
:用于定义Rake任务。lib/
:包含项目的主要代码。omniauth/
:OmniAuth策略的目录。strategies/
:具体的策略实现。stripe_connect.rb
:Stripe Connect的策略实现。
omniauth-stripe_connect.rb
:项目的主文件。
omniauth-stripe_connect.gemspec
:项目的gemspec文件,定义了gem的元数据。spec/
:包含测试文件。omniauth/
:测试策略的目录。strategies/
:具体的策略测试。stripe_connect_spec.rb
:Stripe Connect策略的测试。
spec_helper.rb
:测试辅助文件。
2. 项目的启动文件介绍
项目的启动文件是 lib/omniauth-stripe_connect.rb
,它负责加载OmniAuth的Stripe Connect策略。
require "omniauth"
require "omniauth-oauth2"
module OmniAuth
module Strategies
class StripeConnect < OmniAuth::Strategies::OAuth2
option :name, "stripe_connect"
option :client_options, {
:site => "https://connect.stripe.com",
:authorize_url => "/oauth/authorize",
:token_url => "/oauth/token"
}
uid { raw_info['id'] }
info do
{
:name => raw_info['display_name'],
:email => raw_info['email'],
:scope => raw_info['scope']
}
end
extra do
{
:raw_info => raw_info
}
end
def raw_info
@raw_info ||= access_token.get('/v1/account').parsed
end
end
end
end
OmniAuth.config.add_camelization 'stripe_connect', 'StripeConnect'
3. 项目的配置文件介绍
项目的配置文件主要是 omniauth-stripe_connect.gemspec
,它定义了gem的元数据和依赖关系。
Gem::Specification.new do |spec|
spec.name = "omniauth-stripe-connect"
spec.version = "1.0.0"
spec.authors = ["Isaac Sanders"]
spec.email = ["isaac@isaacbfsanders.com"]
spec.description = %q{OmniAuth strategy for Stripe Connect.}
spec.summary = %q{OmniAuth strategy for Stripe Connect.}
spec.homepage = "https://github.com/isaacsanders/omniauth-stripe-connect"
spec.license = "MIT"
spec.files = `git ls-files`.split($/)
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]
spec.add_dependency "omniauth", "~> 1.0"
spec.add_dependency "omniauth-oauth2", "~> 1.1"
spec.add_development_dependency "bundler", "~> 1.3"
spec.add_development_dependency "rake"
spec.add_development_dependency "rspec", "~> 3.0"
end
这个文件定义了gem的名称、版本、作者、描述、依赖关系等信息。