vindi-hermes 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.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.rubocop.yml +13 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +100 -0
- data/LICENSE.txt +21 -0
- data/README.md +207 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/vindi.rb +76 -0
- data/lib/vindi/core_extensions/her_with_query_filter.rb +67 -0
- data/lib/vindi/middleware/rate_limit_validation.rb +23 -0
- data/lib/vindi/middleware/response_parser.rb +50 -0
- data/lib/vindi/models/address.rb +9 -0
- data/lib/vindi/models/bill.rb +26 -0
- data/lib/vindi/models/bill_item.rb +18 -0
- data/lib/vindi/models/charge.rb +9 -0
- data/lib/vindi/models/customer.rb +29 -0
- data/lib/vindi/models/discount.rb +8 -0
- data/lib/vindi/models/issue.rb +8 -0
- data/lib/vindi/models/model.rb +105 -0
- data/lib/vindi/models/notification.rb +8 -0
- data/lib/vindi/models/payment_method.rb +8 -0
- data/lib/vindi/models/payment_profile.rb +9 -0
- data/lib/vindi/models/period.rb +8 -0
- data/lib/vindi/models/plan.rb +90 -0
- data/lib/vindi/models/plan_item.rb +11 -0
- data/lib/vindi/models/pricing_schema.rb +8 -0
- data/lib/vindi/models/product.rb +25 -0
- data/lib/vindi/models/product_item.rb +8 -0
- data/lib/vindi/models/subscription.rb +32 -0
- data/lib/vindi/models/transaction.rb +8 -0
- data/lib/vindi/rate_limit.rb +18 -0
- data/lib/vindi/version.rb +5 -0
- data/vindi-hermes.gemspec +32 -0
- metadata +150 -0
@@ -0,0 +1,90 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Vindi
|
4
|
+
# Plans
|
5
|
+
#
|
6
|
+
# @example List active plans
|
7
|
+
#
|
8
|
+
# plans = Vindi::Plan.active
|
9
|
+
#
|
10
|
+
# @example Create a recurring plan
|
11
|
+
#
|
12
|
+
# plan = Vindi::Plan.new.tap do |p|
|
13
|
+
# p.name = "Monthly Plan"
|
14
|
+
# p.description = "This plan will be renewed every month in the same day"
|
15
|
+
# p.period = "monthly"
|
16
|
+
# p.recurring = true
|
17
|
+
# p.code = 1
|
18
|
+
# p.plan_items = [
|
19
|
+
# {
|
20
|
+
# cycles: nil,
|
21
|
+
# product_id: 1
|
22
|
+
# }
|
23
|
+
# ]
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# @example Create an yearly plan with installments
|
27
|
+
#
|
28
|
+
# plan = Vindi::Plan.new.tap do |p|
|
29
|
+
# p.name = "Yearly Plan"
|
30
|
+
# p.description = "This plan will be paid in 12 installments"
|
31
|
+
# p.period = "yearly"
|
32
|
+
# p.billing_cycles = 1
|
33
|
+
# p.installments = 12
|
34
|
+
# p.code = 1
|
35
|
+
# p.plan_items = [
|
36
|
+
# {
|
37
|
+
# cycles: nil,
|
38
|
+
# product_id: 1
|
39
|
+
# }
|
40
|
+
# ]
|
41
|
+
# end
|
42
|
+
#
|
43
|
+
class Plan < Model
|
44
|
+
# has_many :plan_items
|
45
|
+
# has_many :products, through: :plan_items
|
46
|
+
|
47
|
+
scope :recurring, -> { where(billing_cycles: nil) }
|
48
|
+
|
49
|
+
after_initialize :set_defaults
|
50
|
+
|
51
|
+
def recurring=(value)
|
52
|
+
self.billing_cycles = value ? nil : 0
|
53
|
+
end
|
54
|
+
|
55
|
+
def period=(value)
|
56
|
+
raise "invalid period" unless %w[monthly quarterly biannually yearly].include? value.to_s
|
57
|
+
|
58
|
+
send "set_#{value}"
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def set_defaults
|
64
|
+
self.billing_trigger_type = "beginning_of_period"
|
65
|
+
self.billing_trigger_day = 0
|
66
|
+
self.installments = 1
|
67
|
+
self.status = "active"
|
68
|
+
end
|
69
|
+
|
70
|
+
def set_monthly
|
71
|
+
self.interval = "months"
|
72
|
+
self.interval_count = 1
|
73
|
+
end
|
74
|
+
|
75
|
+
def set_quarterly
|
76
|
+
self.interval = "months"
|
77
|
+
self.interval_count = 3
|
78
|
+
end
|
79
|
+
|
80
|
+
def set_biannually
|
81
|
+
self.interval = "months"
|
82
|
+
self.interval_count = 6
|
83
|
+
end
|
84
|
+
|
85
|
+
def set_yearly
|
86
|
+
self.interval = "months"
|
87
|
+
self.interval_count = 12
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Vindi
|
4
|
+
# Products
|
5
|
+
#
|
6
|
+
# @example Active productts
|
7
|
+
#
|
8
|
+
# products = Vindi::Product.active
|
9
|
+
#
|
10
|
+
# @example Create a product
|
11
|
+
#
|
12
|
+
# palantir = Vindi::Product.new.tap do |p|
|
13
|
+
# p.code = "palantir"
|
14
|
+
# p.name = "Palantir"
|
15
|
+
# p.description = "The Twitch of Istari folk"
|
16
|
+
# p.pricing_schema = { price: 42.42 }
|
17
|
+
# p.save
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
class Product < Model
|
21
|
+
belongs_to :pricing_schema
|
22
|
+
|
23
|
+
has_many :plans
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Vindi
|
4
|
+
# Customer Subscriptions
|
5
|
+
#
|
6
|
+
# @example Subscribe a customer to a plan
|
7
|
+
#
|
8
|
+
# @subscription = Vindi::Subscription.new.tap do |s|
|
9
|
+
# s.customer_id = customer.id
|
10
|
+
# s.plan_id = plan.id
|
11
|
+
# s.payment_method_code = "credit_card"
|
12
|
+
# s.save
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
class Subscription < Model
|
16
|
+
belongs_to :customer
|
17
|
+
belongs_to :plan
|
18
|
+
|
19
|
+
attributes :plan_id, :customer_id, :payment_method_code
|
20
|
+
|
21
|
+
validates :plan_id, :customer_id, :payment_method_code, presence: true
|
22
|
+
|
23
|
+
# @example Cancel a subscription
|
24
|
+
#
|
25
|
+
# @subscription = Vindi::Customer.find(1).subscriptions.active.last
|
26
|
+
# @subscription.cancel!
|
27
|
+
#
|
28
|
+
def cancel!
|
29
|
+
destroy
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Vindi
|
4
|
+
class RateLimitError < StandardError; end
|
5
|
+
|
6
|
+
# Vindi API calls has a rate limit.
|
7
|
+
class RateLimit
|
8
|
+
class << self
|
9
|
+
attr_accessor :rate_limit_limit, :rate_limit_remaining, :rate_limit_reset
|
10
|
+
|
11
|
+
def update(rate = {})
|
12
|
+
@rate_limit_limit = rate[:limit].to_i
|
13
|
+
@rate_limit_remaining = rate[:remaining].to_i
|
14
|
+
@rate_limit_reset = Time.at(rate[:reset].to_i)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/vindi/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "vindi-hermes"
|
7
|
+
spec.version = Vindi::VERSION
|
8
|
+
spec.authors = ["Wedson Lima"]
|
9
|
+
spec.email = ["wedson.sousa.lima@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "Vindi API - Let the god of trade help you"
|
12
|
+
spec.description = "ActiveRecord-like way to interact with Vindi API"
|
13
|
+
spec.homepage = "https://github.com/wedsonlima/vindi-ruby"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
|
17
|
+
|
18
|
+
# Specify which files should be added to the gem when it is released.
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
20
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
21
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
22
|
+
end
|
23
|
+
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_dependency "faraday", "~> 1.4"
|
27
|
+
spec.add_dependency "faraday_middleware", "~> 1.0"
|
28
|
+
spec.add_dependency "her", "~> 1.1"
|
29
|
+
|
30
|
+
spec.add_development_dependency "httplog"
|
31
|
+
spec.add_development_dependency "rspec", "~> 3.2"
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vindi-hermes
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Wedson Lima
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-06-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.4'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.4'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday_middleware
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: her
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.1'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: httplog
|
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: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.2'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.2'
|
83
|
+
description: ActiveRecord-like way to interact with Vindi API
|
84
|
+
email:
|
85
|
+
- wedson.sousa.lima@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rubocop.yml"
|
92
|
+
- CHANGELOG.md
|
93
|
+
- CODE_OF_CONDUCT.md
|
94
|
+
- Gemfile
|
95
|
+
- Gemfile.lock
|
96
|
+
- LICENSE.txt
|
97
|
+
- README.md
|
98
|
+
- Rakefile
|
99
|
+
- bin/console
|
100
|
+
- bin/setup
|
101
|
+
- lib/vindi.rb
|
102
|
+
- lib/vindi/core_extensions/her_with_query_filter.rb
|
103
|
+
- lib/vindi/middleware/rate_limit_validation.rb
|
104
|
+
- lib/vindi/middleware/response_parser.rb
|
105
|
+
- lib/vindi/models/address.rb
|
106
|
+
- lib/vindi/models/bill.rb
|
107
|
+
- lib/vindi/models/bill_item.rb
|
108
|
+
- lib/vindi/models/charge.rb
|
109
|
+
- lib/vindi/models/customer.rb
|
110
|
+
- lib/vindi/models/discount.rb
|
111
|
+
- lib/vindi/models/issue.rb
|
112
|
+
- lib/vindi/models/model.rb
|
113
|
+
- lib/vindi/models/notification.rb
|
114
|
+
- lib/vindi/models/payment_method.rb
|
115
|
+
- lib/vindi/models/payment_profile.rb
|
116
|
+
- lib/vindi/models/period.rb
|
117
|
+
- lib/vindi/models/plan.rb
|
118
|
+
- lib/vindi/models/plan_item.rb
|
119
|
+
- lib/vindi/models/pricing_schema.rb
|
120
|
+
- lib/vindi/models/product.rb
|
121
|
+
- lib/vindi/models/product_item.rb
|
122
|
+
- lib/vindi/models/subscription.rb
|
123
|
+
- lib/vindi/models/transaction.rb
|
124
|
+
- lib/vindi/rate_limit.rb
|
125
|
+
- lib/vindi/version.rb
|
126
|
+
- vindi-hermes.gemspec
|
127
|
+
homepage: https://github.com/wedsonlima/vindi-ruby
|
128
|
+
licenses:
|
129
|
+
- MIT
|
130
|
+
metadata: {}
|
131
|
+
post_install_message:
|
132
|
+
rdoc_options: []
|
133
|
+
require_paths:
|
134
|
+
- lib
|
135
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: 2.5.0
|
140
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
requirements: []
|
146
|
+
rubygems_version: 3.0.3
|
147
|
+
signing_key:
|
148
|
+
specification_version: 4
|
149
|
+
summary: Vindi API - Let the god of trade help you
|
150
|
+
test_files: []
|