cashbox 0.0.15 → 0.0.16
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 +4 -4
- data/Gemfile.lock +2 -2
- data/lib/cashbox.rb +1 -1
- data/lib/cashbox/model/account.rb +1 -1
- data/lib/cashbox/model/address.rb +1 -1
- data/lib/cashbox/model/billing_plan.rb +2 -2
- data/lib/cashbox/model/billing_plan_period.rb +1 -1
- data/lib/cashbox/model/credit_card.rb +1 -1
- data/lib/cashbox/model/description.rb +1 -1
- data/lib/cashbox/model/direct_debit.rb +1 -1
- data/lib/cashbox/model/entitlement.rb +2 -2
- data/lib/cashbox/model/invoice.rb +1 -1
- data/lib/cashbox/model/pay_pal.rb +1 -1
- data/lib/cashbox/model/payment_method.rb +3 -2
- data/lib/cashbox/model/period.rb +1 -1
- data/lib/cashbox/model/price.rb +1 -1
- data/lib/cashbox/model/product.rb +2 -2
- data/lib/cashbox/model/product_description.rb +1 -1
- data/lib/cashbox/model/product_price.rb +1 -1
- data/lib/cashbox/model/subscription.rb +4 -2
- data/lib/cashbox/model/subscription_item.rb +1 -1
- data/lib/cashbox/model/transaction.rb +3 -2
- data/lib/cashbox/model/transaction_item.rb +1 -1
- data/lib/cashbox/model/transaction_status.rb +1 -1
- data/lib/cashbox/model/transaction_status_pay_pal.rb +1 -1
- data/lib/cashbox/rest.rb +13 -0
- data/lib/cashbox/rest/archive.rb +16 -0
- data/lib/cashbox/rest/cancel.rb +16 -0
- data/lib/cashbox/rest/disentitle.rb +16 -0
- data/lib/cashbox/rest/helpers.rb +36 -0
- data/lib/cashbox/rest/read_write.rb +66 -0
- data/lib/cashbox/version.rb +1 -1
- metadata +8 -4
- data/lib/cashbox/concern/persistable.rb +0 -25
- data/lib/cashbox/repository.rb +0 -89
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: dcbb61459cfd4774c5682fa69e7fffd461de6b03
|
|
4
|
+
data.tar.gz: ddd2906f15529f2d362405cce87e144dbdf558c6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f87715cb329840ec4b71234ed2669d807fa7ee9dcd2de74315f300f70660ebfb96bf3d50c1190afb17b05e7676fb6c704d6cb32e3a508d4536d94d1b48b7158a
|
|
7
|
+
data.tar.gz: 7415778dff6c81f13246622d7732b8fb40d9da6addd673914051419f28c0072afb66f3f749c7f01f45f9114189f65d22fb787ca18520df7b0cc89ff8846355bd
|
data/Gemfile.lock
CHANGED
data/lib/cashbox.rb
CHANGED
data/lib/cashbox/model/period.rb
CHANGED
data/lib/cashbox/model/price.rb
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
module Cashbox
|
|
2
2
|
class Subscription < Model
|
|
3
|
-
include
|
|
4
|
-
include
|
|
3
|
+
include Concern::Objectable
|
|
4
|
+
include Rest::ReadWrite
|
|
5
|
+
include Rest::Cancel
|
|
6
|
+
include Rest::Disentitle
|
|
5
7
|
|
|
6
8
|
property :id
|
|
7
9
|
property :vid
|
data/lib/cashbox/rest.rb
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require 'active_support/concern'
|
|
2
|
+
|
|
3
|
+
module Cashbox::Rest
|
|
4
|
+
module Archive
|
|
5
|
+
extend ActiveSupport::Concern
|
|
6
|
+
|
|
7
|
+
included do
|
|
8
|
+
include Cashbox::Rest::Helpers
|
|
9
|
+
|
|
10
|
+
def archive
|
|
11
|
+
request = Cashbox::Request.new(:post, route(self.vid), { body: { active: false }.to_json })
|
|
12
|
+
self.class.cast(self, request.response)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require 'active_support/concern'
|
|
2
|
+
|
|
3
|
+
module Cashbox::Rest
|
|
4
|
+
module Cancel
|
|
5
|
+
extend ActiveSupport::Concern
|
|
6
|
+
|
|
7
|
+
included do
|
|
8
|
+
include Cashbox::Rest::Helpers
|
|
9
|
+
|
|
10
|
+
def cancel
|
|
11
|
+
request = Cashbox::Request.new(:post, "#{route(self.vid)}/actions/cancel")
|
|
12
|
+
self.class.cast(self, request.response)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require 'active_support/concern'
|
|
2
|
+
|
|
3
|
+
module Cashbox::Rest
|
|
4
|
+
module Disentitle
|
|
5
|
+
extend ActiveSupport::Concern
|
|
6
|
+
|
|
7
|
+
included do
|
|
8
|
+
include Cashbox::Rest::Helpers
|
|
9
|
+
|
|
10
|
+
def disentitle
|
|
11
|
+
request = Cashbox::Request.new(:post, "#{route(self.vid)}/actions/cancel", { body: { disentitle: 'Yes' }.to_json })
|
|
12
|
+
self.class.cast(self, request.response)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
require 'active_support/inflector'
|
|
2
|
+
require 'addressable/uri'
|
|
3
|
+
require 'active_support/concern'
|
|
4
|
+
|
|
5
|
+
module Cashbox::Rest
|
|
6
|
+
module Helpers
|
|
7
|
+
extend ActiveSupport::Concern
|
|
8
|
+
|
|
9
|
+
included do
|
|
10
|
+
def route(id=nil)
|
|
11
|
+
self.class.route(id)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
class_methods do
|
|
16
|
+
def route(id=nil)
|
|
17
|
+
class_name = self.name.split('::').last
|
|
18
|
+
tableized_class_name = ActiveSupport::Inflector.tableize(class_name)
|
|
19
|
+
[ '', tableized_class_name, id ].compact.join('/')
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def cast(instance, hash)
|
|
23
|
+
case hash['object']
|
|
24
|
+
when 'List'
|
|
25
|
+
hash['data'].map do |data|
|
|
26
|
+
instance.class.new(data)
|
|
27
|
+
end
|
|
28
|
+
when 'Error'
|
|
29
|
+
raise Cashbox::Error.new(hash['message'])
|
|
30
|
+
else
|
|
31
|
+
instance.deep_merge!(hash)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
require 'active_support/concern'
|
|
2
|
+
|
|
3
|
+
module Cashbox::Rest
|
|
4
|
+
module ReadWrite
|
|
5
|
+
extend ActiveSupport::Concern
|
|
6
|
+
|
|
7
|
+
DEFAULT_LIMIT = 100.freeze
|
|
8
|
+
|
|
9
|
+
included do
|
|
10
|
+
include Cashbox::Rest::Helpers
|
|
11
|
+
|
|
12
|
+
def save
|
|
13
|
+
save!
|
|
14
|
+
rescue Exception
|
|
15
|
+
false
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def save!
|
|
19
|
+
request = Cashbox::Request.new(:post, route(self.vid), { body: self.to_json })
|
|
20
|
+
self.class.cast(self, request.response)
|
|
21
|
+
true
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
class_methods do
|
|
26
|
+
def find(id)
|
|
27
|
+
request = Cashbox::Request.new(:get, route(id))
|
|
28
|
+
self.cast(self.new, request.response)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def first
|
|
32
|
+
where({ limit: 1 }).first
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def all
|
|
36
|
+
where
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def where(params = {})
|
|
40
|
+
Hashie.symbolize_keys!(params)
|
|
41
|
+
query(params, params.delete(:limit))
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
private
|
|
45
|
+
|
|
46
|
+
def query(params, max)
|
|
47
|
+
params = Hashie::Mash.new(params)
|
|
48
|
+
|
|
49
|
+
params.limit ||= DEFAULT_LIMIT
|
|
50
|
+
params.limit = params.limit.to_i
|
|
51
|
+
params.limit = max if max && max < params.limit
|
|
52
|
+
|
|
53
|
+
response = Cashbox::Request.new(:get, route, { query: params }).response
|
|
54
|
+
objects = cast(self.new, response)
|
|
55
|
+
|
|
56
|
+
if (response.next && (max.nil? || objects.count < max))
|
|
57
|
+
max -= objects.count if max
|
|
58
|
+
params = Addressable::URI.parse(response.next).query_values
|
|
59
|
+
objects.concat(query(params, max))
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
objects
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
data/lib/cashbox/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: cashbox
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.16
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jonathon Storer
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2018-
|
|
11
|
+
date: 2018-06-07 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -172,7 +172,6 @@ files:
|
|
|
172
172
|
- codeship-steps.yml
|
|
173
173
|
- lib/cashbox.rb
|
|
174
174
|
- lib/cashbox/concern/objectable.rb
|
|
175
|
-
- lib/cashbox/concern/persistable.rb
|
|
176
175
|
- lib/cashbox/error.rb
|
|
177
176
|
- lib/cashbox/model/account.rb
|
|
178
177
|
- lib/cashbox/model/address.rb
|
|
@@ -198,8 +197,13 @@ files:
|
|
|
198
197
|
- lib/cashbox/model/transaction_item.rb
|
|
199
198
|
- lib/cashbox/model/transaction_status.rb
|
|
200
199
|
- lib/cashbox/model/transaction_status_pay_pal.rb
|
|
201
|
-
- lib/cashbox/repository.rb
|
|
202
200
|
- lib/cashbox/request.rb
|
|
201
|
+
- lib/cashbox/rest.rb
|
|
202
|
+
- lib/cashbox/rest/archive.rb
|
|
203
|
+
- lib/cashbox/rest/cancel.rb
|
|
204
|
+
- lib/cashbox/rest/disentitle.rb
|
|
205
|
+
- lib/cashbox/rest/helpers.rb
|
|
206
|
+
- lib/cashbox/rest/read_write.rb
|
|
203
207
|
- lib/cashbox/type.rb
|
|
204
208
|
- lib/cashbox/version.rb
|
|
205
209
|
homepage: https://github.com/legalshield/cashbox
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
require 'active_support/concern'
|
|
2
|
-
|
|
3
|
-
module Cashbox::Concern
|
|
4
|
-
module Persistable
|
|
5
|
-
extend ActiveSupport::Concern
|
|
6
|
-
|
|
7
|
-
included do
|
|
8
|
-
extend Forwardable
|
|
9
|
-
extend SingleForwardable
|
|
10
|
-
|
|
11
|
-
def_single_delegators :repository, :where, :all, :first, :find
|
|
12
|
-
def_instance_delegators :repository, :save, :save!, :destroy
|
|
13
|
-
|
|
14
|
-
def repository
|
|
15
|
-
@repository ||= Cashbox::Repository.new(self)
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
class_methods do
|
|
20
|
-
def repository
|
|
21
|
-
Cashbox::Repository.new(self.new)
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
data/lib/cashbox/repository.rb
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
require 'active_support/inflector'
|
|
2
|
-
require 'addressable/uri'
|
|
3
|
-
|
|
4
|
-
module Cashbox
|
|
5
|
-
class Repository
|
|
6
|
-
DEFAULT_LIMIT = 100.freeze
|
|
7
|
-
|
|
8
|
-
attr_reader :instance
|
|
9
|
-
|
|
10
|
-
def initialize(instance)
|
|
11
|
-
@instance = instance
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def first
|
|
15
|
-
where({ limit: 1 }).first
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def all
|
|
19
|
-
where
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def find(id)
|
|
23
|
-
raise ArgumentError.new("Cannot find Resource with id 'nil'") unless id
|
|
24
|
-
cast(Cashbox::Request.new(:get, route(id)).response)
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def where(query = {})
|
|
28
|
-
Hashie.symbolize_keys!(query)
|
|
29
|
-
_where(query, query.delete(:limit))
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def save
|
|
33
|
-
save!
|
|
34
|
-
rescue Exception
|
|
35
|
-
false
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def save!
|
|
39
|
-
request = Cashbox::Request.new(:post, route(@instance.vid), { body: @instance.to_json })
|
|
40
|
-
cast(request.response)
|
|
41
|
-
true
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def destroy
|
|
45
|
-
request = Cashbox::Request.new(:post, "#{route(@instance.vid)}/actions/cancel")
|
|
46
|
-
cast(request.response)
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
private
|
|
50
|
-
|
|
51
|
-
def _where(query, max)
|
|
52
|
-
query = Hashie::Mash.new(query)
|
|
53
|
-
|
|
54
|
-
query.limit ||= DEFAULT_LIMIT
|
|
55
|
-
query.limit = query.limit.to_i
|
|
56
|
-
query.limit = max if max && max < query.limit
|
|
57
|
-
|
|
58
|
-
response = Cashbox::Request.new(:get, route, { query: query }).response
|
|
59
|
-
objects = cast(response)
|
|
60
|
-
|
|
61
|
-
if (response.next && (max.nil? || objects.count < max))
|
|
62
|
-
max -= objects.count if max
|
|
63
|
-
query = Addressable::URI.parse(response.next).query_values
|
|
64
|
-
objects.concat(_where(query, max))
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
objects
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
def route(id=nil)
|
|
71
|
-
class_name = @instance.class.name.split('::').last
|
|
72
|
-
tableized_class_name = ActiveSupport::Inflector.tableize(class_name)
|
|
73
|
-
[ '', tableized_class_name, id ].compact.join('/')
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
def cast(hash)
|
|
77
|
-
case hash['object']
|
|
78
|
-
when 'List'
|
|
79
|
-
hash['data'].map do |data|
|
|
80
|
-
@instance.class.new(data)
|
|
81
|
-
end
|
|
82
|
-
when 'Error'
|
|
83
|
-
raise Cashbox::Error.new(hash['message'])
|
|
84
|
-
else
|
|
85
|
-
@instance.deep_merge!(hash)
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
end
|
|
89
|
-
end
|