cashbox 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.rspec +2 -0
  4. data/.ruby-version +1 -0
  5. data/CODE_OF_CONDUCT.md +74 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +107 -0
  9. data/Rakefile +6 -0
  10. data/cashbox.gemspec +33 -0
  11. data/lib/cashbox.rb +75 -0
  12. data/lib/cashbox/concern/objectable.rb +9 -0
  13. data/lib/cashbox/concern/persistable.rb +25 -0
  14. data/lib/cashbox/exception.rb +4 -0
  15. data/lib/cashbox/model/account.rb +19 -0
  16. data/lib/cashbox/model/address.rb +15 -0
  17. data/lib/cashbox/model/billing_plan.rb +16 -0
  18. data/lib/cashbox/model/billing_plan_period.rb +9 -0
  19. data/lib/cashbox/model/credit_card.rb +12 -0
  20. data/lib/cashbox/model/description.rb +8 -0
  21. data/lib/cashbox/model/entitlement.rb +10 -0
  22. data/lib/cashbox/model/model.rb +9 -0
  23. data/lib/cashbox/model/pay_pal.rb +10 -0
  24. data/lib/cashbox/model/payment_method.rb +14 -0
  25. data/lib/cashbox/model/period.rb +9 -0
  26. data/lib/cashbox/model/price.rb +8 -0
  27. data/lib/cashbox/model/product.rb +17 -0
  28. data/lib/cashbox/model/product_description.rb +5 -0
  29. data/lib/cashbox/model/product_price.rb +5 -0
  30. data/lib/cashbox/model/subscription.rb +30 -0
  31. data/lib/cashbox/model/subscription_item.rb +9 -0
  32. data/lib/cashbox/model/transaction.rb +31 -0
  33. data/lib/cashbox/model/transaction_item.rb +16 -0
  34. data/lib/cashbox/model/transaction_status.rb +10 -0
  35. data/lib/cashbox/model/transaction_status_pay_pal.rb +9 -0
  36. data/lib/cashbox/repository.rb +75 -0
  37. data/lib/cashbox/request.rb +23 -0
  38. data/lib/cashbox/type.rb +27 -0
  39. data/lib/cashbox/version.rb +3 -0
  40. metadata +222 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ebbd158f354848a72145bfa71d1c5e7956098765
4
+ data.tar.gz: c5b5461efa73a63be4664d2365f8744630e9f2c4
5
+ SHA512:
6
+ metadata.gz: f351afc15d6e16fa75321b98298a72fd6069281ff3da94b11ec73b539d2e78d1e61c375ddee2f629418443080ae9f6face4ea340c44705120dbec715ddbb5294
7
+ data.tar.gz: d62ed9ed3f33e8406bd49763215d33a72d1bda1b8959e3cb73993211927f0e6858550149cd958596fb6d50fb8e8ecc5e41fbaf7b74b946f57b853902010dd657
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /.DS_store
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.3
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at JonathonStorer@legalshieldcorp.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in vindicia.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Jonathon Storer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,107 @@
1
+ # Cashbox
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'cashbox'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install cashbox
18
+
19
+ ## Usage
20
+
21
+ #### Requiring
22
+
23
+ ```ruby
24
+ require "cashbox"
25
+ ```
26
+
27
+ #### Setup
28
+
29
+ The library needs to be configured with your account's username & password which is available from your account rep. To configure the gem run:
30
+
31
+ ```ruby
32
+ Cashbox.config({ username: 'me', password: 'sekret' })
33
+ ```
34
+
35
+ or
36
+
37
+ ```ruby
38
+ Cashbox.config do |c|
39
+ c.username = 'me'
40
+ c.password = 'sekret'
41
+ end
42
+ ```
43
+
44
+ #### Switch Environments
45
+
46
+ ```ruby
47
+ >> Cashbox.production!
48
+ => "https://api.vindicia.com"
49
+
50
+ >> Cashbox.sandbox!
51
+ => "https://api.prodtest.vindicia.com"
52
+
53
+ >> Cashbox.test!
54
+ => "http://example.com"
55
+ # also sets
56
+ # Cashbox.username == 'username'
57
+ # Cashbox.password == 'password'
58
+ ```
59
+
60
+ #### Fetching
61
+
62
+ ```ruby
63
+ Cashbox::Product.all => [<Cashbox::Product object="Product">, ...]
64
+
65
+ Cashbox::Product.where(status: 'Active') => [<Cashbox::Product object="Product">, ...]
66
+
67
+ Cashbox::Product.first => <Cashbox::Product object="Product">
68
+ ```
69
+
70
+ #### Finding
71
+
72
+ ```ruby
73
+ Cashbox::Product.find("6fd70003fdb24c3b8104ccfccab4bb492b27a326") => <Cashbox::Product object="Product">
74
+ Cashbox::Product.find("my-user-defined-id") => <Cashbox::Product object="Product">
75
+
76
+ product = Cashbox::Product.first
77
+ product_by_id = Cashbox::Product.find(product.id)
78
+ product_by_vid = Cashbox::Product.find(product.vid)
79
+
80
+ product_by_id == product_by_vid
81
+ => true
82
+
83
+ product_by_id === product_by_vid
84
+ => true
85
+ ```
86
+
87
+ #### Saving
88
+
89
+ ```ruby
90
+ account = Cashbox::Account.find(self.vid)
91
+ account.email = "new_email@example.com"
92
+ account.name = "New Name"
93
+ account.save
94
+ ```
95
+
96
+ ## Development
97
+
98
+ After checking out the repo, run `bundle install` to install dependencies. Then, run `bundle exec rake` to run the tests. You can also run `bundle console` for an interactive prompt that will allow you to experiment.
99
+
100
+ ## Contributing
101
+
102
+ Bug reports and pull requests are welcome on GitHub at https://github.com/LegalShield/cashbox. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
103
+
104
+
105
+ ## License
106
+
107
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/cashbox.gemspec ADDED
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cashbox/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'cashbox'
8
+ spec.version = Cashbox::VERSION
9
+ spec.authors = ['Jonathon Storer']
10
+ spec.email = ['engineering@legalshieldcorp.com']
11
+
12
+ spec.required_ruby_version = '~> 2.0'
13
+
14
+ spec.summary = %q{Cashbox Rest Client}
15
+ spec.description = %q{Cashbox Rest Client}
16
+ spec.homepage = 'https://github.com/legalshield/cashbox'
17
+ spec.license = 'MIT'
18
+
19
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.13'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ spec.add_development_dependency 'rspec', '~> 3.0'
25
+ spec.add_development_dependency 'rspec-its', '~> 1.2'
26
+ spec.add_development_dependency 'webmock', '~> 2.0'
27
+ spec.add_development_dependency 'pry-byebug', '~> 2.0'
28
+
29
+ spec.add_dependency 'httparty'
30
+ spec.add_dependency 'activesupport'
31
+ spec.add_dependency 'hashie'
32
+ spec.add_dependency 'addressable'
33
+ end
data/lib/cashbox.rb ADDED
@@ -0,0 +1,75 @@
1
+ require 'httparty'
2
+ require 'hashie'
3
+ require 'active_support/dependencies/autoload'
4
+
5
+ module Cashbox
6
+ extend ActiveSupport::Autoload
7
+
8
+ class << self
9
+ attr_accessor :username, :password
10
+
11
+ def config(hash = {})
12
+ if block_given?
13
+ yield(self)
14
+ else
15
+ hash.each { |k, v| self.send("#{k}=", v) }
16
+ end
17
+ end
18
+
19
+ end
20
+
21
+ def self.production!
22
+ Cashbox::Request.base_uri('https://api.vindicia.com')
23
+ end
24
+
25
+ def self.sandbox!
26
+ Cashbox::Request.base_uri('https://api.prodtest.vindicia.com')
27
+ end
28
+
29
+ def self.test!
30
+ Cashbox.username = 'username'
31
+ Cashbox.password = 'password'
32
+ Cashbox::Request.base_uri('http://example.com')
33
+ end
34
+
35
+ def self.debug!
36
+ Cashbox::Request.debug_output $stdout
37
+ end
38
+
39
+ eager_autoload do
40
+ autoload :VERSION
41
+ autoload :Exception
42
+ autoload :Type
43
+ autoload :Request
44
+ autoload :Repository
45
+
46
+ autoload_under 'model' do
47
+ autoload :Model
48
+ autoload :Account
49
+ autoload :Address
50
+ autoload :BillingPlan
51
+ autoload :BillingPlanPeriod
52
+ autoload :CreditCard
53
+ autoload :Description
54
+ autoload :Entitlement
55
+ autoload :PayPal
56
+ autoload :PaymentMethod
57
+ autoload :Period
58
+ autoload :Price
59
+ autoload :Product
60
+ autoload :ProductDescription
61
+ autoload :ProductPrice
62
+ autoload :Subscription
63
+ autoload :SubscriptionItem
64
+ autoload :Transaction
65
+ autoload :TransactionItem
66
+ autoload :TransactionStatus
67
+ autoload :TransactionStatusPayPal
68
+ end
69
+ end
70
+
71
+ module Concern
72
+ autoload :Objectable, 'cashbox/concern/objectable'
73
+ autoload :Persistable, 'cashbox/concern/persistable'
74
+ end
75
+ end
@@ -0,0 +1,9 @@
1
+ module Cashbox::Concern
2
+ module Objectable
3
+ def self.included(base)
4
+ base.class_eval do
5
+ property :object, transform_with: -> (v) { self.name.split('::').last }, default: -> { self.name.split('::').last }
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,25 @@
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_delegator :repository, :save
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
@@ -0,0 +1,4 @@
1
+ module Cashbox
2
+ class Exception < Exception
3
+ end
4
+ end
@@ -0,0 +1,19 @@
1
+ module Cashbox
2
+ class Account < Model
3
+ include Cashbox::Concern::Objectable
4
+ include Cashbox::Concern::Persistable
5
+
6
+ property :id
7
+ property :vid
8
+ property :created, coerce: Cashbox::Type.DateTime
9
+ property :default_currency
10
+ property :email
11
+ property :email_type
12
+ property :language
13
+ property :metadata
14
+ property :name
15
+ property :notify_before_billing
16
+ property :payment_methods, coerce: Cashbox::Type.List(Cashbox::PaymentMethod)
17
+ property :shipping_address, coerce: Cashbox::Address
18
+ end
19
+ end
@@ -0,0 +1,15 @@
1
+ module Cashbox
2
+ class Address < Model
3
+ include Cashbox::Concern::Objectable
4
+
5
+ property :vid
6
+ property :city
7
+ property :country
8
+ property :district
9
+ property :fax
10
+ property :line1
11
+ property :name
12
+ property :phone
13
+ property :postal_code
14
+ end
15
+ end
@@ -0,0 +1,16 @@
1
+ module Cashbox
2
+ class BillingPlan < Model
3
+ include Cashbox::Concern::Objectable
4
+ include Cashbox::Concern::Persistable
5
+
6
+ property :id
7
+ property :vid
8
+ property :billing_descriptor
9
+ property :billing_notification_days
10
+ property :created, coerce: Cashbox::Type.DateTime
11
+ property :description
12
+ property :message
13
+ property :periods, coerce: Cashbox::Type.List(Cashbox::BillingPlanPeriod)
14
+ property :status
15
+ end
16
+ end
@@ -0,0 +1,9 @@
1
+ module Cashbox
2
+ class BillingPlanPeriod < Model
3
+ include Cashbox::Concern::Objectable
4
+
5
+ property :cycles
6
+ property :quantity
7
+ property :type
8
+ end
9
+ end
@@ -0,0 +1,12 @@
1
+ module Cashbox
2
+ class CreditCard < Model
3
+ include Cashbox::Concern::Objectable
4
+
5
+ property :vid
6
+ property :account
7
+ property :account_length
8
+ property :bin
9
+ property :expiration_date
10
+ property :last_digits
11
+ end
12
+ end
@@ -0,0 +1,8 @@
1
+ module Cashbox
2
+ class Description < Model
3
+ include Cashbox::Concern::Objectable
4
+
5
+ property :description
6
+ property :language
7
+ end
8
+ end
@@ -0,0 +1,10 @@
1
+ module Cashbox
2
+ class Entitlement < Model
3
+ include Cashbox::Concern::Objectable
4
+ include Cashbox::Concern::Persistable
5
+
6
+ property :id
7
+ property :description
8
+ property :message
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ module Cashbox
2
+ class Model < Hashie::Trash
3
+ include Hashie::Extensions::MergeInitializer
4
+ include Hashie::Extensions::IgnoreUndeclared
5
+ include Hashie::Extensions::IndifferentAccess
6
+ include Hashie::Extensions::Dash::PropertyTranslation
7
+ include Hashie::Extensions::Dash::Coercion
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ module Cashbox
2
+ class PayPal < Model
3
+ include Cashbox::Concern::Objectable
4
+
5
+ property :cancel_url
6
+ property :reference_id
7
+ property :request_reference_id
8
+ property :return_url
9
+ end
10
+ end
@@ -0,0 +1,14 @@
1
+ module Cashbox
2
+ class PaymentMethod < Model
3
+ include Cashbox::Concern::Objectable
4
+ include Cashbox::Concern::Persistable
5
+
6
+ property :id
7
+ property :vid
8
+ property :created, coerce: Cashbox::Type.DateTime
9
+ property :credit_card, coerce: Cashbox::CreditCard
10
+ property :paypal, coerce: Cashbox::PayPal
11
+ property :primary
12
+ property :type
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ module Cashbox
2
+ class Period < Model
3
+ include Cashbox::Concern::Objectable
4
+
5
+ property :cycles
6
+ property :quantity
7
+ property :type
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ module Cashbox
2
+ class Price < Model
3
+ include Cashbox::Concern::Objectable
4
+
5
+ property :amount, coerce: Float
6
+ property :currency
7
+ end
8
+ end
@@ -0,0 +1,17 @@
1
+ module Cashbox
2
+ class Product < Model
3
+ include Cashbox::Concern::Objectable
4
+ include Cashbox::Concern::Persistable
5
+
6
+ property :id
7
+ property :vid
8
+ property :created, coerce: Cashbox::Type.DateTime
9
+ property :billing_descriptor
10
+ property :credit_granted
11
+ property :default_billing_plan, coerce: Cashbox::BillingPlan
12
+ property :descriptions, coerce: Cashbox::Type.List(Cashbox::ProductDescription)
13
+ property :entitlements, coerce: Cashbox::Type.List(Cashbox::Entitlement)
14
+ property :prices, coerce: Cashbox::Type.List(Cashbox::ProductPrice)
15
+ property :status
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ module Cashbox
2
+ class ProductDescription < Cashbox::Description
3
+ include Cashbox::Concern::Objectable
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Cashbox
2
+ class ProductPrice < Cashbox::Price
3
+ include Cashbox::Concern::Objectable
4
+ end
5
+ end
@@ -0,0 +1,30 @@
1
+ module Cashbox
2
+ class Subscription < Model
3
+ include Cashbox::Concern::Objectable
4
+ include Cashbox::Concern::Persistable
5
+
6
+ property :id
7
+ property :vid
8
+ property :created, coerce: Cashbox::Type.DateTime
9
+ property :account, coerce: Cashbox::Account
10
+ property :billing_day
11
+ property :billing_plan, coerce: Cashbox::BillingPlan
12
+ property :billing_state
13
+ property :cancel_reason
14
+ property :currency
15
+ property :default_billing_plan, coerce: Cashbox::BillingPlan
16
+ property :description
17
+ property :ends, coerce: Cashbox::Type.DateTime
18
+ property :entitled_through, coerce: Cashbox::Type.DateTime
19
+ property :items, coerce: Cashbox::Type.List(Cashbox::SubscriptionItem)
20
+ property :message
21
+ property :minimum_commitment
22
+ property :most_recent_billing, coerce: Cashbox::Type.DateTime
23
+ property :next_billing, coerce: Cashbox::Type.DateTime
24
+ property :notify_on_transition, coerce: Cashbox::Type.Boolean
25
+ property :payment_method, coerce: Cashbox::PaymentMethod
26
+ property :policy
27
+ property :starts, coerce: Cashbox::Type.DateTime
28
+ property :status
29
+ end
30
+ end
@@ -0,0 +1,9 @@
1
+ module Cashbox
2
+ class SubscriptionItem < Model
3
+ include Cashbox::Concern::Objectable
4
+
5
+ property :id
6
+ property :product, coerce: Cashbox::Product
7
+ property :index_number, from: :index
8
+ end
9
+ end
@@ -0,0 +1,31 @@
1
+ module Cashbox
2
+ class Transaction < Model
3
+ include Cashbox::Concern::Objectable
4
+ include Cashbox::Concern::Persistable
5
+
6
+ property :id
7
+ property :vid
8
+ property :account, coerce: Cashbox::Account
9
+ property :affiliate
10
+ property :amount, coerce: Float
11
+ property :billing_attempt, coerce: Integer
12
+ property :billing_descriptor
13
+ property :billing_plan_sequence, coerce: Integer
14
+ property :created, coerce: Cashbox::Type.DateTime
15
+ property :currency
16
+ property :items, coerce: Cashbox::Type.List(Cashbox::TransactionItem)
17
+ property :metadata
18
+ property :original_billing_date, coerce: Cashbox::Type.DateTime
19
+ property :payment_processor
20
+ property :payment_processor_transaction_id
21
+ property :shipping_address, coerce: Cashbox::Address
22
+ property :source_payment_method, coerce: Cashbox::PaymentMethod
23
+ property :status_log, coerce: Cashbox::Type.List(Cashbox::TransactionStatus)
24
+ property :sales_tax_address, coerce: Cashbox::Address
25
+ property :source_ip
26
+ property :sub_affiliate
27
+ property :subscription, coerce: Cashbox::Subscription
28
+ property :subscription_sequence
29
+ property :to_be_captured, coerce: Cashbox::Type.Boolean
30
+ end
31
+ end
@@ -0,0 +1,16 @@
1
+ module Cashbox
2
+ class TransactionItem < Model
3
+ include Cashbox::Concern::Objectable
4
+
5
+ property :index_number
6
+ property :item_type
7
+ property :name
8
+ property :quantity
9
+ property :service_period_ends, coerce: Cashbox::Type.DateTime
10
+ property :service_period_starts, coerce: Cashbox::Type.DateTime
11
+ property :sku
12
+ property :tax_classification
13
+ property :tax_type
14
+ property :total
15
+ end
16
+ end
@@ -0,0 +1,10 @@
1
+ module Cashbox
2
+ class TransactionStatus < Model
3
+ include Cashbox::Concern::Objectable
4
+
5
+ property :created, coerce: Cashbox::Type.DateTime
6
+ property :payment_method_type
7
+ property :paypal_status, coerce: Cashbox::TransactionStatusPayPal
8
+ property :status
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ module Cashbox
2
+ class TransactionStatusPayPal < Model
3
+ include Cashbox::Concern::Objectable
4
+
5
+ property :token
6
+ property :auth_code
7
+ property :redirect_url
8
+ end
9
+ end
@@ -0,0 +1,75 @@
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
+ request = Cashbox::Request.new(:post, route(@instance.vid), { body: @instance.to_json })
34
+ cast(request.response)
35
+ end
36
+
37
+ private
38
+
39
+ def _where(query, max)
40
+ query = Hashie::Mash.new(query)
41
+
42
+ query.limit ||= DEFAULT_LIMIT
43
+ query.limit = query.limit.to_i
44
+ query.limit = max if max && max < query.limit
45
+
46
+ response = Cashbox::Request.new(:get, route, { query: query }).response
47
+ objects = cast(response)
48
+
49
+ if (response.next && (max.nil? || objects.count < max))
50
+ max -= objects.count if max
51
+ query = Addressable::URI.parse(response.next).query_values
52
+ objects.concat(_where(query, max))
53
+ end
54
+
55
+ objects
56
+ end
57
+
58
+ def route(id=nil)
59
+ class_name = @instance.class.name.split('::').last
60
+ tableized_class_name = ActiveSupport::Inflector.tableize(class_name)
61
+ [ '', tableized_class_name, id ].compact.join('/')
62
+ end
63
+
64
+ def cast(hash)
65
+ case hash['object']
66
+ when 'List'
67
+ hash['data'].map do |data|
68
+ @instance.class.new(data)
69
+ end
70
+ else
71
+ @instance.deep_merge!(hash)
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,23 @@
1
+ module Cashbox
2
+ class Request
3
+ include HTTParty
4
+ format :json
5
+ base_uri 'https://api.vindicia.com'
6
+
7
+ def initialize(method, path, options = {})
8
+ @method = method
9
+ @path = path
10
+ @options = options
11
+ end
12
+
13
+ def response
14
+ Hashie::Mash.new(self.class.send(@method, @path, @options.merge(default_options)))
15
+ end
16
+
17
+ private
18
+
19
+ def default_options
20
+ { basic_auth: { username: Cashbox.username, password: Cashbox.password }}
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,27 @@
1
+ module Cashbox::Type
2
+ def self.List(type)
3
+ @list ||= {}
4
+ @list[type] ||= -> (data) do
5
+ data = data.is_a?(Hash) ? data['data'] : data
6
+ data.map { |value| type.new(value) }
7
+ end
8
+ @list[type]
9
+ end
10
+
11
+ def self.DateTime
12
+ @date_time ||= -> (value) { DateTime.parse(value) }
13
+ end
14
+
15
+ def self.Boolean
16
+ @boolean ||= -> (value) do
17
+ case value
18
+ when String
19
+ !!(value =~ /\A(true|t|yes|y|1)\z/i)
20
+ when Numeric
21
+ !value.to_i.zero?
22
+ else
23
+ value == true
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module Cashbox
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,222 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cashbox
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jonathon Storer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-04-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-its
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.2'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry-byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '2.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: httparty
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
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: activesupport
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: hashie
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: addressable
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: Cashbox Rest Client
154
+ email:
155
+ - engineering@legalshieldcorp.com
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - ".gitignore"
161
+ - ".rspec"
162
+ - ".ruby-version"
163
+ - CODE_OF_CONDUCT.md
164
+ - Gemfile
165
+ - LICENSE.txt
166
+ - README.md
167
+ - Rakefile
168
+ - cashbox.gemspec
169
+ - lib/cashbox.rb
170
+ - lib/cashbox/concern/objectable.rb
171
+ - lib/cashbox/concern/persistable.rb
172
+ - lib/cashbox/exception.rb
173
+ - lib/cashbox/model/account.rb
174
+ - lib/cashbox/model/address.rb
175
+ - lib/cashbox/model/billing_plan.rb
176
+ - lib/cashbox/model/billing_plan_period.rb
177
+ - lib/cashbox/model/credit_card.rb
178
+ - lib/cashbox/model/description.rb
179
+ - lib/cashbox/model/entitlement.rb
180
+ - lib/cashbox/model/model.rb
181
+ - lib/cashbox/model/pay_pal.rb
182
+ - lib/cashbox/model/payment_method.rb
183
+ - lib/cashbox/model/period.rb
184
+ - lib/cashbox/model/price.rb
185
+ - lib/cashbox/model/product.rb
186
+ - lib/cashbox/model/product_description.rb
187
+ - lib/cashbox/model/product_price.rb
188
+ - lib/cashbox/model/subscription.rb
189
+ - lib/cashbox/model/subscription_item.rb
190
+ - lib/cashbox/model/transaction.rb
191
+ - lib/cashbox/model/transaction_item.rb
192
+ - lib/cashbox/model/transaction_status.rb
193
+ - lib/cashbox/model/transaction_status_pay_pal.rb
194
+ - lib/cashbox/repository.rb
195
+ - lib/cashbox/request.rb
196
+ - lib/cashbox/type.rb
197
+ - lib/cashbox/version.rb
198
+ homepage: https://github.com/legalshield/cashbox
199
+ licenses:
200
+ - MIT
201
+ metadata: {}
202
+ post_install_message:
203
+ rdoc_options: []
204
+ require_paths:
205
+ - lib
206
+ required_ruby_version: !ruby/object:Gem::Requirement
207
+ requirements:
208
+ - - "~>"
209
+ - !ruby/object:Gem::Version
210
+ version: '2.0'
211
+ required_rubygems_version: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ requirements: []
217
+ rubyforge_project:
218
+ rubygems_version: 2.6.8
219
+ signing_key:
220
+ specification_version: 4
221
+ summary: Cashbox Rest Client
222
+ test_files: []