forest_liana 1.3.28 → 1.3.29
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/forest_liana/intercom_controller.rb +8 -1
- data/app/controllers/forest_liana/stripe_controller.rb +33 -0
- data/app/models/forest_liana/model/collection.rb +1 -1
- data/app/serializers/forest_liana/collection_serializer.rb +3 -0
- data/app/serializers/forest_liana/intercom_attribute_serializer.rb +1 -1
- data/app/serializers/forest_liana/intercom_conversation_serializer.rb +1 -1
- data/app/serializers/forest_liana/serializer_factory.rb +44 -8
- data/app/serializers/forest_liana/stripe_bank_account_serializer.rb +43 -0
- data/app/serializers/forest_liana/stripe_card_serializer.rb +1 -1
- data/app/serializers/forest_liana/stripe_invoice_serializer.rb +1 -1
- data/app/serializers/forest_liana/stripe_payment_serializer.rb +1 -1
- data/app/serializers/forest_liana/stripe_subscription_serializer.rb +45 -0
- data/app/services/forest_liana/intercom_attributes_getter.rb +3 -11
- data/app/services/forest_liana/intercom_conversations_getter.rb +3 -10
- data/app/services/forest_liana/operator_value_parser.rb +1 -1
- data/app/services/forest_liana/schema_adapter.rb +61 -31
- data/app/services/forest_liana/stripe_bank_accounts_getter.rb +86 -0
- data/app/services/forest_liana/stripe_cards_getter.rb +26 -22
- data/app/services/forest_liana/stripe_invoices_getter.rb +28 -26
- data/app/services/forest_liana/stripe_payments_getter.rb +28 -25
- data/app/services/forest_liana/stripe_subscriptions_getter.rb +97 -0
- data/config/routes.rb +5 -2
- data/lib/forest_liana/bootstraper.rb +205 -30
- data/lib/forest_liana/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 260b5a5f3205cc16a71e70e18ba1082f2e886d38
|
4
|
+
data.tar.gz: e3d7e787be1f394888c948d7db0c89c90866179d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f15bb5a2fe9c322dfa86639076a26d7cbe44ed33532e5ee8ae2c01ec282857619e9a3bf277067b52c51d25c02bb89204399d34cf0a51e0b69aef84780b90e48d
|
7
|
+
data.tar.gz: 7a98b3b22f891447a3f28357045478312621bf10662ced2d960f09cd4451109c93aa4aa8e4c01cf75f3e8d4ba7c25f6fed0aa0fa3fdd89a965ff74d4b880425d
|
@@ -5,6 +5,7 @@ module ForestLiana
|
|
5
5
|
getter.perform
|
6
6
|
|
7
7
|
render serializer: nil, json: serialize_models(getter.records, {
|
8
|
+
context: { type: get_serializer_type('intercom_conversations') },
|
8
9
|
count: getter.count
|
9
10
|
})
|
10
11
|
end
|
@@ -13,7 +14,13 @@ module ForestLiana
|
|
13
14
|
getter = IntercomAttributesGetter.new(params)
|
14
15
|
getter.perform
|
15
16
|
|
16
|
-
render json: serialize_model(getter.records
|
17
|
+
render serializer: nil, json: serialize_model(getter.records, {
|
18
|
+
context: { type: get_serializer_type('intercom_attributes') }
|
19
|
+
})
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_serializer_type(suffix)
|
23
|
+
"#{params[:collection]}_#{suffix}"
|
17
24
|
end
|
18
25
|
end
|
19
26
|
end
|
@@ -8,6 +8,7 @@ module ForestLiana
|
|
8
8
|
getter.perform
|
9
9
|
|
10
10
|
render serializer: nil, json: serialize_models(getter.records, {
|
11
|
+
context: { type: get_serializer_type('stripe_payments') },
|
11
12
|
count: getter.count,
|
12
13
|
include: ['customer']
|
13
14
|
})
|
@@ -31,6 +32,7 @@ module ForestLiana
|
|
31
32
|
getter.perform
|
32
33
|
|
33
34
|
render serializer: nil, json: serialize_models(getter.records, {
|
35
|
+
context: { type: get_serializer_type('stripe_cards') },
|
34
36
|
count: getter.count,
|
35
37
|
include: ['customer']
|
36
38
|
})
|
@@ -43,9 +45,40 @@ module ForestLiana
|
|
43
45
|
getter.perform
|
44
46
|
|
45
47
|
render serializer: nil, json: serialize_models(getter.records, {
|
48
|
+
context: { type: get_serializer_type('stripe_invoices') },
|
46
49
|
count: getter.count,
|
47
50
|
include: ['customer']
|
48
51
|
})
|
49
52
|
end
|
53
|
+
|
54
|
+
def subscriptions
|
55
|
+
getter = StripeSubscriptionsGetter.new(params,
|
56
|
+
request.headers['Stripe-Secret-Key'],
|
57
|
+
request.headers['Stripe-Reference'])
|
58
|
+
getter.perform
|
59
|
+
|
60
|
+
render serializer: nil, json: serialize_models(getter.records, {
|
61
|
+
context: { type: get_serializer_type('stripe_subscriptions') },
|
62
|
+
count: getter.count,
|
63
|
+
include: ['customer']
|
64
|
+
})
|
65
|
+
end
|
66
|
+
|
67
|
+
def bank_accounts
|
68
|
+
getter = StripeBankAccountsGetter.new(params,
|
69
|
+
request.headers['Stripe-Secret-Key'],
|
70
|
+
request.headers['Stripe-Reference'])
|
71
|
+
getter.perform
|
72
|
+
|
73
|
+
render serializer: nil, json: serialize_models(getter.records, {
|
74
|
+
context: { type: get_serializer_type('stripe_bank_accounts') },
|
75
|
+
count: getter.count,
|
76
|
+
include: ['customer']
|
77
|
+
})
|
78
|
+
end
|
79
|
+
|
80
|
+
def get_serializer_type(suffix)
|
81
|
+
"#{params[:collection]}_#{suffix}"
|
82
|
+
end
|
50
83
|
end
|
51
84
|
end
|
@@ -5,7 +5,7 @@ class ForestLiana::Model::Collection
|
|
5
5
|
extend ActiveModel::Naming
|
6
6
|
|
7
7
|
attr_accessor :name, :fields, :actions, :only_for_relationships, :is_virtual,
|
8
|
-
:is_read_only, :is_searchable
|
8
|
+
:is_read_only, :is_searchable, :display_name, :icon, :pagination_type
|
9
9
|
|
10
10
|
def initialize(attributes = {})
|
11
11
|
@actions = []
|
@@ -4,11 +4,14 @@ class ForestLiana::CollectionSerializer
|
|
4
4
|
include JSONAPI::Serializer
|
5
5
|
|
6
6
|
attribute :name
|
7
|
+
attribute :display_name
|
8
|
+
attribute :icon
|
7
9
|
attribute :fields
|
8
10
|
attribute :only_for_relationships
|
9
11
|
attribute :is_virtual
|
10
12
|
attribute :is_read_only
|
11
13
|
attribute :is_searchable
|
14
|
+
attribute :pagination_type
|
12
15
|
|
13
16
|
has_many :actions do
|
14
17
|
object.actions
|
@@ -29,6 +29,12 @@ module ForestLiana
|
|
29
29
|
elsif defined?(::Stripe::Invoice) &&
|
30
30
|
active_record_class == ::Stripe::Invoice
|
31
31
|
"ForestLiana::StripeInvoiceSerializer"
|
32
|
+
elsif defined?(::Stripe::Subscription) &&
|
33
|
+
active_record_class == ::Stripe::Subscription
|
34
|
+
"ForestLiana::StripeSubscriptionSerializer"
|
35
|
+
elsif defined?(::Stripe::BankAccount) &&
|
36
|
+
active_record_class == ::Stripe::BankAccount
|
37
|
+
"ForestLiana::StripeBankAccountSerializer"
|
32
38
|
elsif active_record_class == ForestLiana::Model::Stat
|
33
39
|
"ForestLiana::StatSerializer"
|
34
40
|
elsif active_record_class == ForestLiana::Model::Collection
|
@@ -118,15 +124,25 @@ module ForestLiana
|
|
118
124
|
private
|
119
125
|
|
120
126
|
def intercom_integration?
|
121
|
-
|
127
|
+
ForestLiana.integrations
|
122
128
|
.try(:[], :intercom)
|
123
|
-
.try(:[], :
|
129
|
+
.try(:[], :mapping)
|
130
|
+
.try(:include?, object.class.name)
|
124
131
|
end
|
125
132
|
|
126
133
|
def stripe_integration?
|
127
|
-
|
134
|
+
mapping = ForestLiana.integrations
|
128
135
|
.try(:[], :stripe)
|
129
|
-
.try(:[], :
|
136
|
+
.try(:[], :mapping)
|
137
|
+
|
138
|
+
if mapping
|
139
|
+
collection_names = mapping.map do |collection_name_and_field|
|
140
|
+
collection_name_and_field.split('.')[0]
|
141
|
+
end
|
142
|
+
collection_names.include?(object.class.name)
|
143
|
+
else
|
144
|
+
false
|
145
|
+
end
|
130
146
|
end
|
131
147
|
}
|
132
148
|
|
@@ -169,15 +185,13 @@ module ForestLiana
|
|
169
185
|
end
|
170
186
|
|
171
187
|
# Intercom
|
172
|
-
if active_record_class.name
|
173
|
-
.try(:[], :intercom).try(:[], :user_collection)
|
188
|
+
if has_intercom_integration?(active_record_class.name)
|
174
189
|
serializer.send(:has_many, :intercom_conversations) { }
|
175
190
|
serializer.send(:has_many, :intercom_attributes) { }
|
176
191
|
end
|
177
192
|
|
178
193
|
# Stripe
|
179
|
-
if active_record_class.name
|
180
|
-
.try(:[], :stripe).try(:[], :user_collection)
|
194
|
+
if has_stripe_integration?(active_record_class.name)
|
181
195
|
serializer.send(:has_many, :stripe_payments) { }
|
182
196
|
serializer.send(:has_many, :stripe_invoices) { }
|
183
197
|
serializer.send(:has_many, :stripe_cards) { }
|
@@ -195,6 +209,28 @@ module ForestLiana
|
|
195
209
|
active_record_class.to_s.tableize.to_sym
|
196
210
|
end
|
197
211
|
|
212
|
+
def has_intercom_integration?(collection_name)
|
213
|
+
ForestLiana.integrations
|
214
|
+
.try(:[], :intercom)
|
215
|
+
.try(:[], :mapping)
|
216
|
+
.try(:include?, collection_name)
|
217
|
+
end
|
218
|
+
|
219
|
+
def has_stripe_integration?(collection_name)
|
220
|
+
mapping = ForestLiana.integrations
|
221
|
+
.try(:[], :stripe)
|
222
|
+
.try(:[], :mapping)
|
223
|
+
|
224
|
+
if mapping
|
225
|
+
collection_names = mapping.map do |collection_name_and_field|
|
226
|
+
collection_name_and_field.split('.')[0]
|
227
|
+
end
|
228
|
+
collection_names.include?(collection_name)
|
229
|
+
else
|
230
|
+
false
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
198
234
|
def serializer_association(association)
|
199
235
|
case association.macro
|
200
236
|
when :has_one, :belongs_to
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module ForestLiana
|
2
|
+
class StripeCardSerializer
|
3
|
+
include JSONAPI::Serializer
|
4
|
+
|
5
|
+
attribute :account
|
6
|
+
attribute :account_holder_name
|
7
|
+
attribute :account_holder_type
|
8
|
+
attribute :bank_name
|
9
|
+
attribute :country
|
10
|
+
attribute :currency
|
11
|
+
attribute :default_for_currency
|
12
|
+
attribute :fingerprint
|
13
|
+
attribute :last4
|
14
|
+
attribute :rooting_number
|
15
|
+
attribute :status
|
16
|
+
|
17
|
+
has_one :customer
|
18
|
+
|
19
|
+
def self_link
|
20
|
+
"/forest#{super}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def type
|
24
|
+
@options[:context][:type] || 'stripe_bank_accounts'
|
25
|
+
end
|
26
|
+
|
27
|
+
def format_name(attribute_name)
|
28
|
+
attribute_name.to_s
|
29
|
+
end
|
30
|
+
|
31
|
+
def unformat_name(attribute_name)
|
32
|
+
attribute_name.to_s
|
33
|
+
end
|
34
|
+
|
35
|
+
def relationship_self_link(attribute_name)
|
36
|
+
nil
|
37
|
+
end
|
38
|
+
|
39
|
+
def relationship_related_link(attribute_name)
|
40
|
+
nil
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module ForestLiana
|
2
|
+
class StripeInvoiceSerializer
|
3
|
+
include JSONAPI::Serializer
|
4
|
+
|
5
|
+
attribute :cancel_at_period_end
|
6
|
+
attribute :canceled_at
|
7
|
+
attribute :created
|
8
|
+
attribute :current_period_end
|
9
|
+
attribute :current_period_start
|
10
|
+
attribute :ended_at
|
11
|
+
attribute :livemode
|
12
|
+
attribute :quantity
|
13
|
+
attribute :start
|
14
|
+
attribute :status
|
15
|
+
attribute :tax_percent
|
16
|
+
attribute :trial_end
|
17
|
+
attribute :trial_start
|
18
|
+
|
19
|
+
has_one :customer
|
20
|
+
|
21
|
+
def self_link
|
22
|
+
"/forest#{super}"
|
23
|
+
end
|
24
|
+
|
25
|
+
def type
|
26
|
+
@options[:context][:type] || 'stripe_subscriptions'
|
27
|
+
end
|
28
|
+
|
29
|
+
def format_name(attribute_name)
|
30
|
+
attribute_name.to_s
|
31
|
+
end
|
32
|
+
|
33
|
+
def unformat_name(attribute_name)
|
34
|
+
attribute_name.to_s
|
35
|
+
end
|
36
|
+
|
37
|
+
def relationship_self_link(attribute_name)
|
38
|
+
nil
|
39
|
+
end
|
40
|
+
|
41
|
+
def relationship_related_link(attribute_name)
|
42
|
+
nil
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -14,9 +14,8 @@ module ForestLiana
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def perform
|
17
|
-
resource = user_collection.find(@params[:id])
|
18
|
-
|
19
17
|
begin
|
18
|
+
resource = collection.find(@params[:id])
|
20
19
|
user = @intercom.users.find(email: resource.email)
|
21
20
|
|
22
21
|
user.segments = user.segments.map do |segment|
|
@@ -30,15 +29,8 @@ module ForestLiana
|
|
30
29
|
|
31
30
|
private
|
32
31
|
|
33
|
-
def
|
34
|
-
|
35
|
-
.try(:[], :intercom)
|
36
|
-
.try(:[], :user_collection)
|
37
|
-
.try(:constantize)
|
38
|
-
end
|
39
|
-
|
40
|
-
def user_collection?
|
41
|
-
user_collection.present?
|
32
|
+
def collection
|
33
|
+
@params[:collection].singularize.capitalize.constantize
|
42
34
|
end
|
43
35
|
end
|
44
36
|
end
|
@@ -27,7 +27,7 @@ module ForestLiana
|
|
27
27
|
|
28
28
|
def perform
|
29
29
|
begin
|
30
|
-
resource =
|
30
|
+
resource = collection.find(@params[:id])
|
31
31
|
@records = @intercom.conversations.find_all(
|
32
32
|
email: resource.email,
|
33
33
|
type: 'user',
|
@@ -40,15 +40,8 @@ module ForestLiana
|
|
40
40
|
|
41
41
|
private
|
42
42
|
|
43
|
-
def
|
44
|
-
|
45
|
-
.try(:[], :intercom)
|
46
|
-
.try(:[], :user_collection)
|
47
|
-
.try(:constantize)
|
48
|
-
end
|
49
|
-
|
50
|
-
def user_collection?
|
51
|
-
user_collection.present?
|
43
|
+
def collection
|
44
|
+
@params[:collection].singularize.capitalize.constantize
|
52
45
|
end
|
53
46
|
|
54
47
|
def link(conversation)
|
@@ -56,11 +56,14 @@ module ForestLiana
|
|
56
56
|
|
57
57
|
# Intercom
|
58
58
|
if ForestLiana.integrations.try(:[], :intercom)
|
59
|
-
.try(:[], :
|
59
|
+
.try(:[], :mapping).try(:include?, @model.name)
|
60
|
+
|
61
|
+
model_name = @model.table_name
|
62
|
+
|
60
63
|
collection.fields << {
|
61
64
|
field: :intercom_conversations,
|
62
65
|
type: ['String'],
|
63
|
-
reference:
|
66
|
+
reference: "#{model_name}_intercom_conversations.id",
|
64
67
|
column: nil,
|
65
68
|
is_searchable: false,
|
66
69
|
integration: 'intercom'
|
@@ -69,7 +72,7 @@ module ForestLiana
|
|
69
72
|
@collection.fields << {
|
70
73
|
field: :intercom_attributes,
|
71
74
|
type: 'String',
|
72
|
-
reference:
|
75
|
+
reference: "#{model_name}_intercom_attributes.id",
|
73
76
|
column: nil,
|
74
77
|
is_searchable: false,
|
75
78
|
integration: 'intercom'
|
@@ -77,34 +80,61 @@ module ForestLiana
|
|
77
80
|
end
|
78
81
|
|
79
82
|
# Stripe
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
83
|
+
stripe_mapping = ForestLiana.integrations.try(:[], :stripe)
|
84
|
+
.try(:[], :mapping)
|
85
|
+
|
86
|
+
if stripe_mapping
|
87
|
+
if stripe_mapping
|
88
|
+
.select { |mapping| mapping.split('.')[0] == @model.name }
|
89
|
+
.size > 0
|
90
|
+
|
91
|
+
model_name = @model.table_name
|
92
|
+
|
93
|
+
collection.fields << {
|
94
|
+
field: :stripe_payments,
|
95
|
+
type: ['String'],
|
96
|
+
reference: "#{model_name}_stripe_payments.id",
|
97
|
+
column: nil,
|
98
|
+
is_searchable: false,
|
99
|
+
integration: 'stripe'
|
100
|
+
}
|
101
|
+
|
102
|
+
collection.fields << {
|
103
|
+
field: :stripe_invoices,
|
104
|
+
type: ['String'],
|
105
|
+
reference: "#{model_name}_stripe_invoices.id",
|
106
|
+
column: nil,
|
107
|
+
is_searchable: false,
|
108
|
+
integration: 'stripe'
|
109
|
+
}
|
110
|
+
|
111
|
+
collection.fields << {
|
112
|
+
field: :stripe_cards,
|
113
|
+
type: ['String'],
|
114
|
+
reference: "#{model_name}_stripe_cards.id",
|
115
|
+
column: nil,
|
116
|
+
is_searchable: false,
|
117
|
+
integration: 'stripe'
|
118
|
+
}
|
119
|
+
|
120
|
+
collection.fields << {
|
121
|
+
field: :stripe_subscriptions,
|
122
|
+
type: ['String'],
|
123
|
+
reference: "#{model_name}_stripe_subscriptions.id",
|
124
|
+
column: nil,
|
125
|
+
is_searchable: false,
|
126
|
+
integration: 'stripe'
|
127
|
+
}
|
128
|
+
|
129
|
+
collection.fields << {
|
130
|
+
field: :stripe_bank_accounts,
|
131
|
+
type: ['String'],
|
132
|
+
reference: "#{model_name}_stripe_bank_accounts.id",
|
133
|
+
column: nil,
|
134
|
+
is_searchable: false,
|
135
|
+
integration: 'stripe'
|
136
|
+
}
|
137
|
+
end
|
108
138
|
end
|
109
139
|
|
110
140
|
# Paperclip url attribute
|