aptible-billing 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7762b872f5e635edf9da78afd40176ca1f61469c
4
+ data.tar.gz: c8d358f84e5d72479f65bc1db419ebc56a96eb14
5
+ SHA512:
6
+ metadata.gz: df525f141c80e4c625761855cf3044fdcc17eb93ee7309e288e0fe9467091f75203462299940e0df8d0c122c9b4c808211aaa0ebe34e0af3af46480a3e9e3960
7
+ data.tar.gz: 44dfc600c43296034fa5c89bec8fb6717707052ae5808ee1b9cd2712eac4454485e4bb5e2c8e7489444ae76d732dc0f847da636b5b07756e22e15a824c5c6e0d
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .idea
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ rvm:
2
+ - "2.1"
3
+ - 2.0.0
4
+ - jruby
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in aptible-billing-billing.gemspec
4
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Aptible, Inc.
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # ![](https://raw.github.com/aptible/straptible/master/lib/straptible/rails/templates/public.api/icon-60px.png) Aptible::Billing::Ruby
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/aptible-billing-ruby.png)](https://rubygems.org/gems/aptible-billing-ruby)
4
+ [![Build Status](https://travis-ci.org/aptible/aptible-billing-ruby.png?branch=master)](https://travis-ci.org/aptible/aptible-billing-ruby)
5
+ [![Dependency Status](https://gemnasium.com/aptible/aptible-billing-ruby.png)](https://gemnasium.com/aptible/aptible-billing-ruby)
6
+
7
+ TODO: Add description.
8
+
9
+ ## Installation
10
+
11
+ Add the following line to your application's Gemfile.
12
+
13
+ gem 'aptible-billing-ruby'
14
+
15
+ And then run `bundle install`.
16
+
17
+ ## Usage
18
+
19
+ TODO: Add usage notes.
20
+
21
+ ## Contributing
22
+
23
+ 1. Fork the project.
24
+ 1. Commit your changes, with specs.
25
+ 1. Ensure that your code passes specs (`rake spec`) and meets Aptible's Ruby style guide (`rake rubocop`).
26
+ 1. Create a new pull request on GitHub.
27
+
28
+ ## Copyright and License
29
+
30
+ MIT License, see [LICENSE](LICENSE.md) for details.
31
+
32
+ Copyright (c) 2015 [Aptible](https://www.aptible.com), Blake Pettersson, and contributors.
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'aptible/tasks'
4
+ Aptible::Tasks.load_tasks
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ require 'English'
6
+ require 'aptible/billing/version'
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = 'aptible-billing'
10
+ spec.version = Aptible::Billing::VERSION
11
+ spec.authors = ['Blake Pettersson']
12
+ spec.email = ['blake@aptible.com']
13
+ spec.description = 'Ruby client for billing.aptible.com'
14
+ spec.summary = 'Ruby client for billing.aptible.com'
15
+ spec.homepage = 'https://github.com/aptible/aptible-billing-ruby'
16
+ spec.license = 'MIT'
17
+
18
+ spec.files = `git ls-files`.split($RS)
19
+ spec.test_files = spec.files.grep(/^spec\//)
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_dependency 'stripe', '>= 1.13.0'
23
+ spec.add_dependency 'aptible-resource', '>= 0.2.1'
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.10'
26
+ spec.add_development_dependency 'aptible-tasks'
27
+ spec.add_development_dependency 'simplecov'
28
+ spec.add_development_dependency 'rake'
29
+ spec.add_development_dependency 'rspec-its'
30
+ spec.add_development_dependency 'rspec', '~> 2.0'
31
+ end
@@ -0,0 +1,35 @@
1
+ require 'stripe'
2
+
3
+ module Aptible
4
+ module Billing
5
+ class BillingDetail < Resource
6
+ field :id
7
+ field :created_at, type: Time
8
+ field :updated_at, type: Time
9
+ field :stripe_customer_id
10
+ field :stripe_subscription_id
11
+ field :stripe_subscription_status
12
+ field :plan
13
+ field :billing_contact_id
14
+
15
+ def stripe_customer
16
+ return nil if stripe_customer_id.nil?
17
+ @stripe_customer ||= Stripe::Customer.retrieve(stripe_customer_id)
18
+ end
19
+
20
+ def can_manage_compliance?
21
+ %w(production pilot).include?(plan)
22
+ end
23
+
24
+ def subscription
25
+ return nil if stripe_subscription_id.nil?
26
+ subscriptions = stripe_customer.subscriptions
27
+ @subscription ||= subscriptions.retrieve(stripe_subscription_id)
28
+ end
29
+
30
+ def subscribed?
31
+ !!stripe_subscription_id
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,17 @@
1
+ require 'aptible/resource'
2
+
3
+ module Aptible
4
+ module Billing
5
+ class Resource < Aptible::Resource::Base
6
+ def namespace
7
+ 'Aptible::Billing'
8
+ end
9
+
10
+ def root_url
11
+ Aptible::Billing.configuration.root_url
12
+ end
13
+ end
14
+ end
15
+ end
16
+
17
+ require 'aptible/billing/billing_detail'
@@ -0,0 +1,5 @@
1
+ module Aptible
2
+ module Billing
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,16 @@
1
+ require 'gem_config'
2
+ require 'aptible/billing/version'
3
+
4
+ module Aptible
5
+ module Billing
6
+ include GemConfig::Base
7
+
8
+ with_configuration do
9
+ has :root_url,
10
+ classes: [String],
11
+ default: ENV['APTIBLE_BILLING_ROOT_URL'] || 'https://billing.aptible.com'
12
+ end
13
+ end
14
+ end
15
+
16
+ require 'aptible/billing/resource'
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe Aptible::Billing::BillingDetail do
4
+
5
+ describe '#can_manage_compliance?' do
6
+ it 'should return true with compliance plan' do
7
+ subject.stub(:plan) { 'production' }
8
+ expect(subject.can_manage_compliance?).to be_true
9
+ end
10
+
11
+ it 'should return false without compliance plan' do
12
+ subject.stub(:plan) { 'platform' }
13
+ expect(subject.can_manage_compliance?).to be_false
14
+ end
15
+ end
16
+
17
+ describe '#subscribed?' do
18
+ it 'should return true with valid subscription ID' do
19
+ subject.stub(:stripe_subscription_id) { 'sub_4YrmiVa3vMpaGA' }
20
+ expect(subject.subscribed?).to be_true
21
+ end
22
+
23
+ it 'should return false without valid subscription ID' do
24
+ expect(subject.subscribed?).to be_false
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+ require 'rspec/its'
3
+
4
+ describe Aptible::Billing::Resource do
5
+ its(:namespace) { should eq 'Aptible::Billing' }
6
+ its(:root_url) { should eq 'https://billing.aptible.com' }
7
+ end
@@ -0,0 +1,29 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe Aptible::Billing do
4
+ subject { Aptible::Billing::BillingDetail.new }
5
+
6
+ it 'should have a configurable root_url' do
7
+ config = described_class.configuration
8
+ expect(config).to be_a GemConfig::Configuration
9
+ expect(config.root_url).to eq 'https://billing.aptible.com'
10
+ end
11
+
12
+ # Not sure why this test is failing
13
+ pending 'uses ENV["APTIBLE_BILLING_ROOT_URL"] if defined' do
14
+ config = described_class.configuration
15
+ set_env 'APTIBLE_BILLING_ROOT_URL', 'http://foobar.com' do
16
+ config.reset
17
+ expect(config.root_url).to eq 'http://foobar.com'
18
+ end
19
+ end
20
+
21
+ it 'should be able to override root_url programatically' do
22
+ config = described_class.configuration
23
+ Aptible::Billing.configure do |config|
24
+ config.root_url = 'http://foobar.com'
25
+ end
26
+
27
+ expect(config.root_url).to eq 'http://foobar.com'
28
+ end
29
+ end
@@ -0,0 +1,10 @@
1
+ def set_env(*args, &block)
2
+ hash = args.first.is_a?(Hash) ? args.first : Hash[*args]
3
+ old_values = Hash[hash.map { |k, _| [k, ENV[k]] }]
4
+ begin
5
+ hash.each { |k, v| ENV[k] = v }
6
+ yield
7
+ ensure
8
+ old_values.each { |k, v| ENV[k] = v }
9
+ end
10
+ end
@@ -0,0 +1,15 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+
4
+ # Load shared spec files
5
+ Dir["#{File.dirname(__FILE__)}/shared/**/*.rb"].each do |file|
6
+ require file
7
+ end
8
+
9
+ # Require library up front
10
+ require 'aptible/billing'
11
+
12
+
13
+ RSpec.configure do |config|
14
+ config.before { Aptible::Billing.configuration.reset }
15
+ end
metadata ADDED
@@ -0,0 +1,178 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aptible-billing
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Blake Pettersson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: stripe
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.13.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.13.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: aptible-resource
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 0.2.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: 0.2.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: aptible-tasks
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec-its
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: '2.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ~>
123
+ - !ruby/object:Gem::Version
124
+ version: '2.0'
125
+ description: Ruby client for billing.aptible.com
126
+ email:
127
+ - blake@aptible.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - .gitignore
133
+ - .rspec
134
+ - .travis.yml
135
+ - Gemfile
136
+ - LICENSE.md
137
+ - README.md
138
+ - Rakefile
139
+ - aptible-billing-ruby.gemspec
140
+ - lib/aptible/billing.rb
141
+ - lib/aptible/billing/billing_detail.rb
142
+ - lib/aptible/billing/resource.rb
143
+ - lib/aptible/billing/version.rb
144
+ - spec/aptible/billing/billing_detail_spec.rb
145
+ - spec/aptible/billing/resource_spec.rb
146
+ - spec/aptible/billing_spec.rb
147
+ - spec/shared/set_env.rb
148
+ - spec/spec_helper.rb
149
+ homepage: https://github.com/aptible/aptible-billing-ruby
150
+ licenses:
151
+ - MIT
152
+ metadata: {}
153
+ post_install_message:
154
+ rdoc_options: []
155
+ require_paths:
156
+ - lib
157
+ required_ruby_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - '>='
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ required_rubygems_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - '>='
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ requirements: []
168
+ rubyforge_project:
169
+ rubygems_version: 2.4.5
170
+ signing_key:
171
+ specification_version: 4
172
+ summary: Ruby client for billing.aptible.com
173
+ test_files:
174
+ - spec/aptible/billing/billing_detail_spec.rb
175
+ - spec/aptible/billing/resource_spec.rb
176
+ - spec/aptible/billing_spec.rb
177
+ - spec/shared/set_env.rb
178
+ - spec/spec_helper.rb