superp-hyperwallet-ruby 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8bab20265126828ece2dd345ce564f054213056e
4
+ data.tar.gz: bcb3381ed2451dc2826f767ce721ecc8f86b09f7
5
+ SHA512:
6
+ metadata.gz: e222cd5ddf85f2faa1740d115b48774be27f6dcf7ecd1e3d7dde169881cafe24a17680877bfa9cfaaed3ba46f9facc1a03191fce42811cde115443f9753f5012
7
+ data.tar.gz: 569d4ae6a1f33b0c2185c2a65ca0faf681ef867454563a00f67e21610c116e8a4e9f4c53e6efd8410a2a879feab4000d88cd9bbe5349244915019d073ca29b1e
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.0
5
+ before_install: gem install bundler -v 1.12.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hyperwallet-rails.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 tmartin314
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.
@@ -0,0 +1,77 @@
1
+ [![Gem Version](https://badge.fury.io/rb/hyperwallet-ruby.svg)](https://badge.fury.io/rb/hyperwallet-ruby)
2
+ [![Build Status](https://travis-ci.org/devato/hyperwallet-ruby.svg?branch=master)](https://travis-ci.org/devato/hyperwallet-ruby)
3
+
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'hyperwallet-ruby'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install hyperwallet-ruby
20
+
21
+ ## Configuration
22
+
23
+ To configure the gem using your credentials:
24
+
25
+ ```
26
+ Hyperwallet.api_user = ENV['HYPERWALLET_API_USER']
27
+ Hyperwallet.api_password = ENV['HYPERWALLET_API_PASS']
28
+ Hyperwallet.api_base = ENV['HYPERWALLET_API_BASE']
29
+ ```
30
+
31
+ ## Users API
32
+
33
+ To create a user:
34
+
35
+ ```
36
+ Hyperwallet::User.create({valid: user_data})
37
+ ```
38
+
39
+ To find a user:
40
+
41
+ ```
42
+ Hyperwallet::User.find(user_key_id)
43
+ ```
44
+
45
+ ## Payments API
46
+
47
+ To create a payment:
48
+
49
+ ```
50
+ Hyperwallet::Payment.create({valid: payment_data})
51
+ ```
52
+
53
+ ## TODO
54
+
55
+ 1. Add Prepaid Cards methods - WIP
56
+ 2. Add Bank Accounts methods - WIP
57
+ 3. Add Status Transitions methods - WIP
58
+ 4. Add Transfer Method Configurations methods - WIP
59
+ 5. Add Balances methods - WIP
60
+ 6. Add Programs method - WIP
61
+ 7. Add Accounts method - WIP
62
+
63
+ ## Development
64
+
65
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
66
+
67
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
68
+
69
+ ## Contributing
70
+
71
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Devato/hyperwallet-ruby.
72
+
73
+
74
+ ## License
75
+
76
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
77
+
@@ -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
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "hyperwallet/rails"
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
@@ -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
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hyperwallet/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "superp-hyperwallet-ruby"
8
+ spec.version = Hyperwallet::VERSION
9
+ spec.authors = ["Troy Martin"]
10
+ spec.email = ["troy@devatotech.com"]
11
+ spec.required_ruby_version = '>= 2.0.0'
12
+
13
+ spec.summary = %q{Ruby bindings for the Hyperwallet REST API.}
14
+ spec.description = %q{Ruby bindings for the Hyperwallet REST API.}
15
+ spec.homepage = "https://github.com/superp/hyperwallet-ruby"
16
+ spec.license = "MIT"
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+ spec.add_dependency('rest-client')
23
+ spec.add_dependency('multi_json')
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.12"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.0"
28
+ spec.add_development_dependency "rspec-its"
29
+
30
+ end
@@ -0,0 +1 @@
1
+ require 'hyperwallet'
@@ -0,0 +1,92 @@
1
+ require 'rest_client'
2
+ require 'multi_json'
3
+
4
+ require "hyperwallet/version"
5
+
6
+ require "hyperwallet/hyperwallet_error"
7
+ require "hyperwallet/util"
8
+
9
+ require "hyperwallet/hyperwallet_object"
10
+ require "hyperwallet/user"
11
+ require "hyperwallet/payment"
12
+ require "hyperwallet/program"
13
+
14
+ module Hyperwallet
15
+
16
+ class << self
17
+ attr_accessor :api_user, :api_password, :api_base, :debug
18
+ end
19
+
20
+ def self.api_url(operation='', api_version = 3)
21
+ "#{api_base}/rest/v#{api_version}#{operation}"
22
+ end
23
+
24
+ def self.request(method, url, params = {}, headers = {}, api_version = 3)
25
+ http_method = method.to_s.downcase.to_sym
26
+ case http_method
27
+ when :post, :put
28
+ headers[:content_type] ||= "application/json"
29
+ payload = params.to_json
30
+ else
31
+ # Make params into GET parameters
32
+ url += "#{URI.parse(url).query ? '&' : '?'}#{uri_encode(params)}" if params && params.any?
33
+ payload = nil
34
+ end
35
+
36
+ request_opts = {
37
+ :headers => headers,
38
+ :method => method,
39
+ :verify_ssl => false,
40
+ :url => api_url(url, api_version),
41
+ :user => api_user,
42
+ :password => api_password,
43
+ :payload => payload
44
+ }
45
+ begin
46
+ response = execute_request(request_opts)
47
+ handle_api_error(response.code, response.body) unless [200, 201, 204].include?(response.code.to_i)
48
+ rescue RestClient::ExceptionWithResponse => e
49
+ if rcode = e.http_code and rbody = e.http_body
50
+ handle_api_error(rcode, rbody)
51
+ else
52
+ raise
53
+ end
54
+ end
55
+
56
+ parse(response)
57
+ end
58
+
59
+ def self.execute_request(opts)
60
+ puts "REQUEST: #{opts.to_s}" if debug
61
+ RestClient::Request.execute(opts)
62
+ end
63
+
64
+ def self.handle_api_error(rcode, rbody)
65
+ case rcode
66
+ when 400, 404
67
+ raise InvalidRequestError.new("Your request is invalid: #{rbody.inspect}", rcode, rbody)
68
+ when 401
69
+ raise AuthenticationError.new("Your API user or password is invalid: #{rbody.inspect}", rcode, rbody)
70
+ else
71
+ raise APIError.new("API Error: #{rbody.inspect}", rcode, rbody)
72
+ end
73
+ end
74
+
75
+ def self.parse(response)
76
+ puts "RESPONSE: #{response.body}" if debug
77
+ return {} if response.body.empty?
78
+
79
+ begin
80
+ MultiJson.load(response.body)
81
+ rescue MultiJson::DecodeError
82
+ raise APIError.new("Invalid response from the API: #{response.body.inspect}")
83
+ end
84
+ end
85
+
86
+ private
87
+
88
+ def self.uri_encode(params)
89
+ params.map { |k,v| "#{k}=#{URI.escape(v.to_s)}" }.join("&")
90
+ end
91
+
92
+ end
@@ -0,0 +1,20 @@
1
+ module Hyperwallet
2
+ class HyperwalletError < StandardError
3
+ def initialize(message=nil, http_status=nil, http_body=nil)
4
+ @message = message
5
+ @http_status = http_status
6
+ @http_body = http_body
7
+ end
8
+
9
+ def to_s
10
+ status_string = @http_status.nil? ? "" : "(Status #{@http_status}) "
11
+ "#{status_string}#{@message}"
12
+ end
13
+ end
14
+
15
+ class InvalidRequestError < HyperwalletError; end
16
+ class AuthenticationError < HyperwalletError; end
17
+ class APIError < HyperwalletError; end
18
+
19
+ end
20
+
@@ -0,0 +1,49 @@
1
+ module Hyperwallet
2
+ class HyperwalletObject
3
+ attr_reader :values
4
+
5
+ def initialize(values)
6
+ @values = {}
7
+ (self.class.attributes + values.keys).each do |k|
8
+ attr = Util.symbolize_attribute(k)
9
+ @values[attr] = HyperwalletObject.convert_to_hyperwallet_object(values[k], self.class, attr)
10
+ end
11
+ end
12
+
13
+ def self.convert_to_hyperwallet_object(resp, type = nil, relation = nil)
14
+ case resp
15
+ when Array
16
+ resp.map { |r| convert_to_hyperwallet_object(r, type, relation) }
17
+ when Hash
18
+ object_class = (relation.nil? ? type : type.relations[relation]) || HyperwalletObject
19
+ object_class.construct_from(resp)
20
+ else
21
+ resp
22
+ end
23
+ end
24
+
25
+ def self.attributes
26
+ []
27
+ end
28
+
29
+ def self.relations
30
+ {}
31
+ end
32
+
33
+ def self.construct_from(values)
34
+ object = self.new(values)
35
+ end
36
+
37
+ def method_missing(name, *args, &block)
38
+ if @values.has_key?(name)
39
+ @values[name]
40
+ else
41
+ super
42
+ end
43
+ end
44
+
45
+ def respond_to_missing?(name, *args)
46
+ @values.has_key?(name) || super
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,20 @@
1
+ module Hyperwallet
2
+ class Payment < HyperwalletObject
3
+
4
+ def self.all(params={})
5
+ res = Hyperwallet.request(:get, '/payments', params)
6
+ convert_to_hyperwallet_object(res, Payment)
7
+ end
8
+
9
+ def self.find(key)
10
+ res = Hyperwallet.request(:get, "/payments/#{key}")
11
+ convert_to_hyperwallet_object(res, Payment)
12
+ end
13
+
14
+ def self.create(params={})
15
+ res = Hyperwallet.request(:post, '/payments', params)
16
+ convert_to_hyperwallet_object(res, Payment)
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,23 @@
1
+ module Hyperwallet
2
+ class Program < HyperwalletObject
3
+
4
+ def self.find(program_key)
5
+ res = Hyperwallet.request(:get, "/programs/#{program_key}")
6
+ convert_to_hyperwallet_object(res, Program)
7
+ end
8
+
9
+ class Account < HyperwalletObject
10
+
11
+ def self.find(program_key, account_key)
12
+ res = Hyperwallet.request(:get, "/programs/#{program_key}/accounts/#{account_key}")
13
+ convert_to_hyperwallet_object(res, Account)
14
+ end
15
+
16
+ def self.balances(program_key, account_key)
17
+ res = Hyperwallet.request(:get, "/programs/#{program_key}/accounts/#{account_key}/balances")
18
+ convert_to_hyperwallet_object(res, Account)
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,54 @@
1
+ module Hyperwallet
2
+ class User < HyperwalletObject
3
+
4
+ def self.all(params={})
5
+ res = Hyperwallet.request(:get, '/users', params)
6
+ convert_to_hyperwallet_object(res, User)
7
+ end
8
+
9
+ def self.find(key)
10
+ res = Hyperwallet.request(:get, "/users/#{key}")
11
+ convert_to_hyperwallet_object(res, User)
12
+ end
13
+
14
+ def self.create(params={})
15
+ res = Hyperwallet.request(:post, '/users', params)
16
+ convert_to_hyperwallet_object(res, User)
17
+ end
18
+
19
+ def self.update(key, params)
20
+ res = Hyperwallet.request(:put, "/users/#{key}", params)
21
+ convert_to_hyperwallet_object(res, User)
22
+ end
23
+
24
+ def self.balances(key, params={})
25
+ res = Hyperwallet.request(:get, "/users/#{key}/balances", params)
26
+ convert_to_hyperwallet_object(res)
27
+ end
28
+
29
+ class PaypalAccount < HyperwalletObject
30
+
31
+ def self.all(user_token, params)
32
+ res = Hyperwallet.request(:get, "/users/#{user_token}/paypal-accounts", params)
33
+ convert_to_hyperwallet_object(res, PaypalAccount)
34
+ end
35
+
36
+ def self.find(user_token, account_token)
37
+ res = Hyperwallet.request(:get, "/users/#{user_token}/paypal-accounts/#{account_token}")
38
+ convert_to_hyperwallet_object(res, PaypalAccount)
39
+ end
40
+
41
+ def self.create(user_token, params)
42
+ res = Hyperwallet.request(:post, "/users/#{user_token}/paypal-accounts", params)
43
+ convert_to_hyperwallet_object(res, PaypalAccount)
44
+ end
45
+
46
+ def self.update(user_token, account_token, params)
47
+ res = Hyperwallet.request(:put, "/users/#{user_token}/paypal-accounts/#{account_token}", params)
48
+ convert_to_hyperwallet_object(res, PaypalAccount)
49
+ end
50
+
51
+ end
52
+
53
+ end
54
+ end
@@ -0,0 +1,14 @@
1
+ module Hyperwallet
2
+ module Util
3
+ # creatorKey => :creator_key
4
+ def self.symbolize_attribute(attr)
5
+ word = attr.to_s.dup
6
+ word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
7
+ word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
8
+ word.tr!("-", "_")
9
+ word.downcase!
10
+ word.to_sym
11
+ end
12
+ end
13
+ end
14
+
@@ -0,0 +1,3 @@
1
+ module Hyperwallet
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: superp-hyperwallet-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Troy Martin
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-07-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
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: multi_json
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.12'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.12'
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
+ - !ruby/object:Gem::Dependency
84
+ name: rspec-its
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Ruby bindings for the Hyperwallet REST API.
98
+ email:
99
+ - troy@devatotech.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - Gemfile
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - bin/console
112
+ - bin/setup
113
+ - hyperwallet-ruby.gemspec
114
+ - lib/hyperwallet-ruby.rb
115
+ - lib/hyperwallet.rb
116
+ - lib/hyperwallet/hyperwallet_error.rb
117
+ - lib/hyperwallet/hyperwallet_object.rb
118
+ - lib/hyperwallet/payment.rb
119
+ - lib/hyperwallet/program.rb
120
+ - lib/hyperwallet/user.rb
121
+ - lib/hyperwallet/util.rb
122
+ - lib/hyperwallet/version.rb
123
+ homepage: https://github.com/superp/hyperwallet-ruby
124
+ licenses:
125
+ - MIT
126
+ metadata: {}
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: 2.0.0
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubyforge_project:
143
+ rubygems_version: 2.5.2.3
144
+ signing_key:
145
+ specification_version: 4
146
+ summary: Ruby bindings for the Hyperwallet REST API.
147
+ test_files: []