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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 59a2448650f0f71fb5c40df130c1d0a2b56b42da
4
- data.tar.gz: b1d47e46020d7e98ae156e1eff9bc553ce8b25a5
3
+ metadata.gz: dcbb61459cfd4774c5682fa69e7fffd461de6b03
4
+ data.tar.gz: ddd2906f15529f2d362405cce87e144dbdf558c6
5
5
  SHA512:
6
- metadata.gz: 9ca7f3b5751c6c26a4f261e0a6b3d2621b7753d8207f352af3fc9647a21116811539c0930d8caa57ae9a31a2c528bec8abcc9a90a98477698c4d5120fa107807
7
- data.tar.gz: e8f94e7f0ba5774e96ec661cb3f3f7ba3a9356085c6a066dc764a6157e8766bdf2e5ea113bfbf0acb512cc36b9d670680762c32eac8147cc3f98fdffc7ecefd6
6
+ metadata.gz: f87715cb329840ec4b71234ed2669d807fa7ee9dcd2de74315f300f70660ebfb96bf3d50c1190afb17b05e7676fb6c704d6cb32e3a508d4536d94d1b48b7158a
7
+ data.tar.gz: 7415778dff6c81f13246622d7732b8fb40d9da6addd673914051419f28c0072afb66f3f749c7f01f45f9114189f65d22fb787ca18520df7b0cc89ff8846355bd
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cashbox (0.0.15)
4
+ cashbox (0.0.16)
5
5
  activesupport
6
6
  addressable
7
7
  hashie
@@ -84,4 +84,4 @@ DEPENDENCIES
84
84
  webmock (~> 2.0)
85
85
 
86
86
  BUNDLED WITH
87
- 1.16.1
87
+ 1.16.2
@@ -45,7 +45,7 @@ module Cashbox
45
45
  autoload :Error
46
46
  autoload :Type
47
47
  autoload :Request
48
- autoload :Repository
48
+ autoload :Rest
49
49
 
50
50
  autoload_under 'model' do
51
51
  autoload :Model
@@ -1,7 +1,7 @@
1
1
  module Cashbox
2
2
  class Account < Model
3
3
  include Concern::Objectable
4
- include Concern::Persistable
4
+ include Rest::ReadWrite
5
5
 
6
6
  property :id
7
7
  property :vid
@@ -1,6 +1,6 @@
1
1
  module Cashbox
2
2
  class Address < Model
3
- include Cashbox::Concern::Objectable
3
+ include Concern::Objectable
4
4
 
5
5
  property :vid
6
6
  property :city
@@ -1,7 +1,7 @@
1
1
  module Cashbox
2
2
  class BillingPlan < Model
3
- include Cashbox::Concern::Objectable
4
- include Cashbox::Concern::Persistable
3
+ include Concern::Objectable
4
+ include Rest::ReadWrite
5
5
 
6
6
  property :id
7
7
  property :vid
@@ -1,6 +1,6 @@
1
1
  module Cashbox
2
2
  class BillingPlanPeriod < Model
3
- include Cashbox::Concern::Objectable
3
+ include Concern::Objectable
4
4
 
5
5
  property :cycles
6
6
  property :quantity
@@ -1,6 +1,6 @@
1
1
  module Cashbox
2
2
  class CreditCard < Model
3
- include Cashbox::Concern::Objectable
3
+ include Concern::Objectable
4
4
 
5
5
  property :vid
6
6
  property :account
@@ -1,6 +1,6 @@
1
1
  module Cashbox
2
2
  class Description < Model
3
- include Cashbox::Concern::Objectable
3
+ include Concern::Objectable
4
4
 
5
5
  property :description
6
6
  property :language
@@ -1,6 +1,6 @@
1
1
  module Cashbox
2
2
  class DirectDebit < Model
3
- include Cashbox::Concern::Objectable
3
+ include Concern::Objectable
4
4
 
5
5
  property :vid
6
6
  property :account
@@ -1,7 +1,7 @@
1
1
  module Cashbox
2
2
  class Entitlement < Model
3
- include Cashbox::Concern::Objectable
4
- include Cashbox::Concern::Persistable
3
+ include Concern::Objectable
4
+ include Rest::ReadWrite
5
5
 
6
6
  property :id
7
7
  property :description
@@ -1,7 +1,7 @@
1
1
  module Cashbox
2
2
  class Invoice < Model
3
3
  include Concern::Objectable
4
- include Concern::Persistable
4
+ include Rest::ReadWrite
5
5
 
6
6
  property :id
7
7
  property :vid
@@ -1,6 +1,6 @@
1
1
  module Cashbox
2
2
  class PayPal < Model
3
- include Cashbox::Concern::Objectable
3
+ include Concern::Objectable
4
4
 
5
5
  property :cancel_url
6
6
  property :reference_id
@@ -1,7 +1,8 @@
1
1
  module Cashbox
2
2
  class PaymentMethod < Model
3
- include Cashbox::Concern::Objectable
4
- include Cashbox::Concern::Persistable
3
+ include Concern::Objectable
4
+ include Rest::ReadWrite
5
+ include Rest::Archive
5
6
 
6
7
  property :id
7
8
  property :vid
@@ -1,6 +1,6 @@
1
1
  module Cashbox
2
2
  class Period < Model
3
- include Cashbox::Concern::Objectable
3
+ include Concern::Objectable
4
4
 
5
5
  property :cycles
6
6
  property :quantity
@@ -1,6 +1,6 @@
1
1
  module Cashbox
2
2
  class Price < Model
3
- include Cashbox::Concern::Objectable
3
+ include Concern::Objectable
4
4
 
5
5
  property :amount, coerce: Float
6
6
  property :currency
@@ -1,7 +1,7 @@
1
1
  module Cashbox
2
2
  class Product < Model
3
- include Cashbox::Concern::Objectable
4
- include Cashbox::Concern::Persistable
3
+ include Concern::Objectable
4
+ include Rest::ReadWrite
5
5
 
6
6
  property :id
7
7
  property :vid
@@ -1,5 +1,5 @@
1
1
  module Cashbox
2
2
  class ProductDescription < Cashbox::Description
3
- include Cashbox::Concern::Objectable
3
+ include Concern::Objectable
4
4
  end
5
5
  end
@@ -1,5 +1,5 @@
1
1
  module Cashbox
2
2
  class ProductPrice < Cashbox::Price
3
- include Cashbox::Concern::Objectable
3
+ include Concern::Objectable
4
4
  end
5
5
  end
@@ -1,7 +1,9 @@
1
1
  module Cashbox
2
2
  class Subscription < Model
3
- include Cashbox::Concern::Objectable
4
- include Cashbox::Concern::Persistable
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
@@ -1,6 +1,6 @@
1
1
  module Cashbox
2
2
  class SubscriptionItem < Model
3
- include Cashbox::Concern::Objectable
3
+ include Concern::Objectable
4
4
 
5
5
  property :id
6
6
  property :product, coerce: Cashbox::Product
@@ -1,7 +1,8 @@
1
1
  module Cashbox
2
2
  class Transaction < Model
3
- include Cashbox::Concern::Objectable
4
- include Cashbox::Concern::Persistable
3
+ include Concern::Objectable
4
+ include Rest::ReadWrite
5
+ include Rest::Cancel
5
6
 
6
7
  property :id
7
8
  property :vid
@@ -1,6 +1,6 @@
1
1
  module Cashbox
2
2
  class TransactionItem < Model
3
- include Cashbox::Concern::Objectable
3
+ include Concern::Objectable
4
4
 
5
5
  property :index_number
6
6
  property :item_type
@@ -1,6 +1,6 @@
1
1
  module Cashbox
2
2
  class TransactionStatus < Model
3
- include Cashbox::Concern::Objectable
3
+ include Concern::Objectable
4
4
 
5
5
  property :created, coerce: Cashbox::Type.DateTime
6
6
  property :payment_method_type
@@ -1,6 +1,6 @@
1
1
  module Cashbox
2
2
  class TransactionStatusPayPal < Model
3
- include Cashbox::Concern::Objectable
3
+ include Concern::Objectable
4
4
 
5
5
  property :token
6
6
  property :auth_code
@@ -0,0 +1,13 @@
1
+ require 'active_support/dependencies/autoload'
2
+
3
+ module Cashbox::Rest
4
+ extend ActiveSupport::Autoload
5
+
6
+ eager_autoload do
7
+ autoload :Archive
8
+ autoload :Cancel
9
+ autoload :Disentitle
10
+ autoload :Helpers
11
+ autoload :ReadWrite
12
+ end
13
+ end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Cashbox
2
- VERSION = "0.0.15"
2
+ VERSION = "0.0.16"
3
3
  end
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.15
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-05-18 00:00:00.000000000 Z
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
@@ -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