paybase 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: be537f6099169d86de5f8b68713a07f718ffec6f
4
+ data.tar.gz: c4065039acada1ae99e41e0c75a8f35bd0cbc76a
5
+ SHA512:
6
+ metadata.gz: b846d356c02dae2fb2de381e59b5dd8bac790ecfe1a117ab0d2829ef7380405a8a9d7d960c8c076504344819d6f2908af8e49d22926f32b48e4d8bcd431d5c48
7
+ data.tar.gz: 0bab74f36020ecd377db5cc863b44e2b4ac5ec45473b9a563c1408cbce354e0b49f940e5741cef0b61670ba32df72860b82381e29ecf10c84aa10699a430c6f9
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.0
5
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :test do
4
+ gem 'pry'
5
+ gem 'rspec'
6
+ gem 'webmock'
7
+ end
8
+
9
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,70 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ paybase (0.0.1)
5
+ activesupport
6
+ httparty
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (5.2.2)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (>= 0.7, < 2)
14
+ minitest (~> 5.1)
15
+ tzinfo (~> 1.1)
16
+ addressable (2.6.0)
17
+ public_suffix (>= 2.0.2, < 4.0)
18
+ coderay (1.1.2)
19
+ concurrent-ruby (1.1.4)
20
+ crack (0.4.3)
21
+ safe_yaml (~> 1.0.0)
22
+ diff-lcs (1.3)
23
+ hashdiff (0.3.7)
24
+ httparty (0.16.1)
25
+ multi_xml (>= 0.5.2)
26
+ i18n (1.5.3)
27
+ concurrent-ruby (~> 1.0)
28
+ method_source (0.9.2)
29
+ minitest (5.11.3)
30
+ multi_xml (0.6.0)
31
+ pry (0.12.2)
32
+ coderay (~> 1.1.0)
33
+ method_source (~> 0.9.0)
34
+ public_suffix (3.0.3)
35
+ rake (10.5.0)
36
+ rspec (3.5.0)
37
+ rspec-core (~> 3.5.0)
38
+ rspec-expectations (~> 3.5.0)
39
+ rspec-mocks (~> 3.5.0)
40
+ rspec-core (3.5.4)
41
+ rspec-support (~> 3.5.0)
42
+ rspec-expectations (3.5.0)
43
+ diff-lcs (>= 1.2.0, < 2.0)
44
+ rspec-support (~> 3.5.0)
45
+ rspec-mocks (3.5.0)
46
+ diff-lcs (>= 1.2.0, < 2.0)
47
+ rspec-support (~> 3.5.0)
48
+ rspec-support (3.5.0)
49
+ safe_yaml (1.0.4)
50
+ thread_safe (0.3.6)
51
+ tzinfo (1.2.5)
52
+ thread_safe (~> 0.1)
53
+ webmock (3.3.0)
54
+ addressable (>= 2.3.6)
55
+ crack (>= 0.3.2)
56
+ hashdiff
57
+
58
+ PLATFORMS
59
+ ruby
60
+
61
+ DEPENDENCIES
62
+ bundler (~> 1.16)
63
+ paybase!
64
+ pry
65
+ rake (~> 10.0)
66
+ rspec
67
+ webmock
68
+
69
+ BUNDLED WITH
70
+ 1.16.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Justin Seidl
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,17 @@
1
+ ### Paybase ruby client library
2
+
3
+ Client library for talking to [Paybase API](https://paybase.io/docs).
4
+
5
+ #### Usage
6
+
7
+ First, initialize the client:
8
+
9
+ ```ruby
10
+ client = Paybase::Client.new("PAYBASE_ACCESS_TOKEN")
11
+ ```
12
+
13
+ Make a request to the API:
14
+
15
+ ```ruby
16
+ client.customers
17
+ ```
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/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "paybase"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/paybase.rb ADDED
@@ -0,0 +1,10 @@
1
+ require "active_support/core_ext/hash"
2
+ require "httparty"
3
+ require "paybase/version"
4
+ require "paybase/relation"
5
+ require "paybase/resource"
6
+ require "paybase/resource_collection"
7
+ require "paybase/client"
8
+
9
+ module Paybase
10
+ end
@@ -0,0 +1,34 @@
1
+ require "paybase/client/connection"
2
+
3
+ require "paybase/client/accounts"
4
+ require "paybase/client/banks"
5
+ # require "paybase/client/cards"
6
+ # require "paybase/client/documents"
7
+ require "paybase/client/customers"
8
+ # require "paybase/client/guests"
9
+ # require "paybase/client/statements"
10
+ require "paybase/client/transactions"
11
+
12
+ module Paybase
13
+ class Client
14
+ include HTTParty
15
+ include Paybase::Client::Connection
16
+ include Paybase::Client::Accounts
17
+ include Paybase::Client::Banks
18
+ # include Paybase::Client::Cards
19
+ # include Paybase::Client::Documents
20
+ include Paybase::Client::Customers
21
+ # include Paybase::Client::Guests
22
+ # include Paybase::Client::Statements
23
+ include Paybase::Client::Transactions
24
+
25
+ base_uri "https://api-json.sandbox.paybase.io/v1"
26
+ format :json
27
+
28
+ def initialize(access_token = nil)
29
+ access_token ||= ENV["PAYBASE_ACCESS_TOKEN"]
30
+ self.class.default_options.merge!(headers: { 'Content-Type' => 'application/json', 'X-Token' => access_token })
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,15 @@
1
+ module Paybase
2
+ class Client
3
+ module Accounts
4
+
5
+ def create_account(options)
6
+ post("/accounts", options)
7
+ end
8
+
9
+ def account(id)
10
+ get("/account/#{id}")
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,23 @@
1
+ module Paybase
2
+ class Client
3
+ module Banks
4
+
5
+ def banks(options = {})
6
+ get("/bank-accounts", options)
7
+ end
8
+
9
+ def create_bank(options)
10
+ post("/bank-accounts", options)
11
+ end
12
+
13
+ def bank(id)
14
+ get("/bank-account/#{id}")
15
+ end
16
+
17
+ def update_bank(id, options)
18
+ patch("/bank-account/#{id}", options)
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,48 @@
1
+ module Paybase
2
+ class Client
3
+ module Connection
4
+
5
+ def get(path, options = {})
6
+ request :get, path, options
7
+ end
8
+
9
+ def post(path, options = {})
10
+ request :post, path, options
11
+ end
12
+
13
+ def put(path, options = {})
14
+ request :put, path, options
15
+ end
16
+
17
+ def patch(path, options = {})
18
+ request :patch, path, options
19
+ end
20
+
21
+ def delete(path, options = {})
22
+ request :delete, path, options
23
+ end
24
+
25
+ private
26
+
27
+ def request(http_method, path, options)
28
+ response = self.class.send(http_method, path, { body: options })
29
+ data = response.parsed_response
30
+ parse_data(data)
31
+ end
32
+
33
+ def parse_data(original_data)
34
+ return unless original_data
35
+
36
+ data = original_data.keys.count <= 2 ? original_data.values.first : original_data
37
+
38
+ case data
39
+ when Hash then Resource.new(self, data)
40
+ when Array then ResourceCollection.new(self, original_data)
41
+ when nil then nil
42
+ else data
43
+ end
44
+ end
45
+
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,23 @@
1
+ module Paybase
2
+ class Client
3
+ module Customers
4
+
5
+ def customers(options = {})
6
+ get("/customers", options)
7
+ end
8
+
9
+ def create_individual(options)
10
+ post("/customers/individual", options)
11
+ end
12
+
13
+ def customer(id)
14
+ get("/customers/#{id}")
15
+ end
16
+
17
+ def update_customer(id, options)
18
+ patch("/customers/#{id}", options)
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,27 @@
1
+ module Paybase
2
+ class Client
3
+ module Transactions
4
+
5
+ def transactions(options = {})
6
+ get("/txs", options)
7
+ end
8
+
9
+ def internal(options)
10
+ post("/txs/internal", options)
11
+ end
12
+
13
+ def inbound(options)
14
+ post("/txs/inbound", options)
15
+ end
16
+
17
+ def outbound(options)
18
+ post("/txs/outbound", options)
19
+ end
20
+
21
+ def transaction(id)
22
+ get("/tx/#{id}")
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,9 @@
1
+ module Paybase
2
+ class Relation < Struct.new(:client, :href)
3
+
4
+ def get(options = {})
5
+ client.get href, options
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,36 @@
1
+ module Paybase
2
+ class Resource
3
+
4
+ attr_reader :rels, :data
5
+
6
+ def initialize(client, data)
7
+ data = {} unless data.is_a?(Hash)
8
+
9
+ @client = client
10
+
11
+ data = data.with_indifferent_access
12
+
13
+ links = data.delete(:links) { ActiveSupport::HashWithIndifferentAccess.new }
14
+ links[:self] = { href: data.delete(:href) } if data.has_key?(:href)
15
+
16
+ @data = OpenStruct.new(data.with_indifferent_access)
17
+
18
+ @rels = parse_links(links)
19
+ end
20
+
21
+ def parse_links(links)
22
+ (links || {}).each_with_object({}) do |(relation, value), result|
23
+ result[relation] = Relation.new(@client, value[:href]) if value[:href]
24
+ end.with_indifferent_access
25
+ end
26
+
27
+ def method_missing(method_sym, *arguments, &block)
28
+ if @data.respond_to?(method_sym)
29
+ @data.send(method_sym)
30
+ else
31
+ super
32
+ end
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,57 @@
1
+ module Paybase
2
+ class ResourceCollection < Resource
3
+
4
+ include Enumerable
5
+
6
+ attr_reader :options
7
+
8
+ def initialize(client, data, options = {})
9
+ data = {} unless data.is_a?(Hash)
10
+ data = data.with_indifferent_access
11
+
12
+ @client = client
13
+
14
+ meta_data = data.delete(:meta) { Hash.new }
15
+
16
+ collection = Array(data.values.first).map do |item|
17
+ Resource.new(client, item)
18
+ end
19
+
20
+ links = {}
21
+
22
+ if meta_data.has_key?("pagination")
23
+ @total_pages = meta_data["pagination"]["total_pages"]
24
+ @current_page = meta_data["pagination"]["current_page"]
25
+ links = {
26
+ next: {
27
+ href: meta_data["pagination"]["next_page"]
28
+ },
29
+ prev: {
30
+ href: meta_data["pagination"]["prev_page"]
31
+ },
32
+ }
33
+ end
34
+
35
+ @data = OpenStruct.new(meta: meta_data, collection: collection)
36
+ @rels = parse_links(links)
37
+ @options = options.with_indifferent_access
38
+ end
39
+
40
+ def each
41
+ return enum_for(:each) unless block_given?
42
+
43
+ collection.each { |item| yield item }
44
+
45
+ return self if @current_page == @total_pages
46
+
47
+ rel = @rels[:next] or return self
48
+ resource_collection = rel.get(@options.except(:page))
49
+ resource_collection.each(&Proc.new)
50
+
51
+ @data = OpenStruct.new(meta: resource_collection.meta,
52
+ collection: collection + resource_collection.collection)
53
+ @rels = resource_collection.rels
54
+ end
55
+
56
+ end
57
+ end
@@ -0,0 +1,3 @@
1
+ module Paybase
2
+ VERSION = "0.0.1"
3
+ end
data/paybase.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "paybase/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "paybase"
8
+ spec.version = Paybase::VERSION
9
+ spec.authors = ["Vertbase"]
10
+ spec.email = ["dev@vertbase.com"]
11
+ spec.summary = %q{API Client for the Paybase API}
12
+ spec.description = %q{API Client for the Paybase API}
13
+ spec.homepage = "https://github.com/vertbase/paybase"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency "httparty"
24
+ spec.add_dependency "activesupport"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.16"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec", "~> 3.0"
29
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: paybase
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Vertbase
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-02-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.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.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description: API Client for the Paybase API
84
+ email:
85
+ - dev@vertbase.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - Gemfile.lock
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/setup
100
+ - lib/paybase.rb
101
+ - lib/paybase/client.rb
102
+ - lib/paybase/client/accounts.rb
103
+ - lib/paybase/client/banks.rb
104
+ - lib/paybase/client/connection.rb
105
+ - lib/paybase/client/customers.rb
106
+ - lib/paybase/client/transactions.rb
107
+ - lib/paybase/relation.rb
108
+ - lib/paybase/resource.rb
109
+ - lib/paybase/resource_collection.rb
110
+ - lib/paybase/version.rb
111
+ - paybase.gemspec
112
+ homepage: https://github.com/vertbase/paybase
113
+ licenses:
114
+ - MIT
115
+ metadata: {}
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ requirements: []
131
+ rubyforge_project:
132
+ rubygems_version: 2.6.4
133
+ signing_key:
134
+ specification_version: 4
135
+ summary: API Client for the Paybase API
136
+ test_files: []