hyperwallet-ruby 0.1.5

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: f0ee54354b626a6a9fd23acdf482468bef1c7de1
4
+ data.tar.gz: 3a63b81452481d46943fe5bacd746ab4c4e7c51c
5
+ SHA512:
6
+ metadata.gz: bc1c00b3a9fc5906318c7997cadaedc2d7763f91054a1f5197a93a605db6c16146302fd28ea1f3037440fdf02912b4a2166401ca3ffcd4dbeae0ac24eeed6b52
7
+ data.tar.gz: 715ec4adb491a957bf8b460c3facf125ceb4ad779d870e614d486efc9a646c9ea61df7a1e9dd4be3b2ff11ee67824a523936a33133a23d1bd8c0a506b8e24e48
data/.gitignore ADDED
@@ -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
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.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
data/LICENSE.txt ADDED
@@ -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.
data/README.md ADDED
@@ -0,0 +1,67 @@
1
+ [![Build Status](https://travis-ci.org/Devato/hyperwallet-ruby.svg?branch=master)](https://travis-ci.org/Devato/hyperwallet-ruby)
2
+
3
+
4
+ ## Installation
5
+
6
+ Add this line to your application's Gemfile:
7
+
8
+ ```ruby
9
+ gem 'hyperwallet-ruby'
10
+ ```
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install hyperwallet-ruby
19
+
20
+ ## Configuration
21
+
22
+ To configure the gem using your credentials:
23
+
24
+ ```
25
+ Hyperwallet.api_user = ENV['HYPERWALLERT_API_USER']
26
+ Hyperwallet.api_password = ENV['HYPERWALLERT_API_PASS']
27
+ Hyperwallet.api_base = ENV['HYPERWALLET_API_BASE']
28
+ ```
29
+
30
+ ## Users API
31
+
32
+ To create a user:
33
+
34
+ ```
35
+ Hyperwallet::User.create({valid: user_data})
36
+ ```
37
+
38
+ To find a user:
39
+
40
+ ```
41
+ Hyperwallet::User.find(user_key_id)
42
+ ```
43
+
44
+ ## Payments API
45
+
46
+ To create a payment:
47
+
48
+ ```
49
+ Hyperwallet::Payment.create({valid: payment_data})
50
+ ```
51
+
52
+
53
+ ## Development
54
+
55
+ 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.
56
+
57
+ 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).
58
+
59
+ ## Contributing
60
+
61
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Devato/hyperwallet-rails.
62
+
63
+
64
+ ## License
65
+
66
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
67
+
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 "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
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
@@ -0,0 +1,37 @@
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 = "hyperwallet-ruby"
8
+ spec.version = Hyperwallet::VERSION
9
+ spec.authors = ["Troy Martin"]
10
+ spec.email = ["troy@devatotech.com"]
11
+
12
+ spec.summary = %q{Rails bindings for the Hyperwallet REST API.}
13
+ spec.description = %q{Rails bindings for the Hyperwallet REST API.}
14
+ spec.homepage = "https://github.com/Devato/hyperwallet-ruby"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ # end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+ spec.add_dependency('rest-client')
30
+ spec.add_dependency('multi_json')
31
+
32
+ spec.add_development_dependency "bundler", "~> 1.12"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "rspec", "~> 3.0"
35
+ spec.add_development_dependency "rspec-its"
36
+
37
+ 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,45 @@
1
+ module Hyperwallet
2
+ class HyperwalletObject
3
+
4
+ def initialize(values)
5
+ @values = {}
6
+ (self.class.attributes + values.keys).each do |k|
7
+ attr = Util.symbolize_attribute(k)
8
+ @values[attr] = HyperwalletObject.convert_to_hyperwallet_object(values[k], self.class, attr)
9
+ end
10
+ end
11
+
12
+ def self.convert_to_hyperwallet_object(resp, type = nil, relation = nil)
13
+ case resp
14
+ when Array
15
+ resp.map { |r| convert_to_hyperwallet_object(r, type, relation) }
16
+ when Hash
17
+ object_class = (relation.nil? ? type : type.relations[relation]) || HyperwalletObject
18
+ object_class.construct_from(resp)
19
+ else
20
+ resp
21
+ end
22
+ end
23
+
24
+ def self.attributes
25
+ []
26
+ end
27
+
28
+ def self.relations
29
+ {}
30
+ end
31
+
32
+ def self.construct_from(values)
33
+ object = self.new(values)
34
+ end
35
+
36
+ def method_missing(name, *args)
37
+ if @values.has_key?(name)
38
+ @values[name]
39
+ else
40
+ super
41
+ end
42
+ end
43
+ end
44
+ end
45
+
@@ -0,0 +1,10 @@
1
+ module Hyperwallet
2
+ class Payment < HyperwalletObject
3
+
4
+ def self.create(params={})
5
+ res = Hyperwallet.request(:post, '/payments', params)
6
+ convert_to_hyperwallet_object(res, Payment)
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,25 @@
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}", MultiJson.dump(params))
21
+ convert_to_hyperwallet_object(res, User)
22
+ end
23
+
24
+ end
25
+ 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.5"
3
+ end
@@ -0,0 +1 @@
1
+ require 'hyperwallet'
@@ -0,0 +1,90 @@
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
+
13
+ module Hyperwallet
14
+
15
+ class << self
16
+ attr_accessor :api_user, :api_password, :api_base
17
+ end
18
+
19
+ def self.api_url(operation='', api_version = 3)
20
+ "#{api_base}/rest/v#{api_version}#{operation}"
21
+ end
22
+
23
+ def self.request(method, url, params = {}, headers = {}, api_version = 3)
24
+ http_method = method.to_s.downcase.to_sym
25
+ case http_method
26
+ when :get, :head, :delete
27
+ # Make params into GET parameters
28
+ url += "#{URI.parse(url).query ? '&' : '?'}#{uri_encode(params)}" if params && params.any?
29
+ payload = nil
30
+ else
31
+ payload = params.is_a?(String) ? params : uri_encode(params)
32
+ if http_method == :post
33
+ payload = params.to_json
34
+ headers[:content_type] ||= "application/json"
35
+ end
36
+ end
37
+
38
+ request_opts = {
39
+ :headers => headers,
40
+ :method => method,
41
+ :verify_ssl => false,
42
+ :url => api_url(url, api_version),
43
+ :user => api_user,
44
+ :password => api_password,
45
+ :payload => payload
46
+ }
47
+ begin
48
+ response = execute_request(request_opts)
49
+ handle_api_error(response.code, response.body) unless [200, 201].include?(response.code.to_i)
50
+ rescue RestClient::ExceptionWithResponse => e
51
+ if rcode = e.http_code and rbody = e.http_body
52
+ handle_api_error(rcode, rbody)
53
+ else
54
+ raise
55
+ end
56
+ end
57
+
58
+ parse(response)
59
+ end
60
+
61
+ def self.execute_request(opts)
62
+ RestClient::Request.execute(opts)
63
+ end
64
+
65
+ def self.handle_api_error(rcode, rbody)
66
+ case rcode
67
+ when 400, 404
68
+ raise InvalidRequestError.new("Your request is invalid: #{rbody.inspect}", rcode, rbody)
69
+ when 401
70
+ raise AuthenticationError.new("Your API user or password is invalid: #{rbody.inspect}", rcode, rbody)
71
+ else
72
+ raise APIError.new("API Error: #{rbody.inspect}", rcode, rbody)
73
+ end
74
+ end
75
+
76
+ def self.parse(response)
77
+ begin
78
+ response = MultiJson.load(response.body)
79
+ rescue MultiJson::DecodeError
80
+ raise APIError.new("Invalid response from the API: #{response.body.inspect}")
81
+ end
82
+ end
83
+
84
+ private
85
+
86
+ def self.uri_encode(params)
87
+ params.map { |k,v| "#{k}=#{URI.escape(v)}" }.join("&")
88
+ end
89
+
90
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hyperwallet-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.5
5
+ platform: ruby
6
+ authors:
7
+ - Troy Martin
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-07-30 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: Rails 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-rails.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/user.rb
120
+ - lib/hyperwallet/util.rb
121
+ - lib/hyperwallet/version.rb
122
+ homepage: https://github.com/Devato/hyperwallet-ruby
123
+ licenses:
124
+ - MIT
125
+ metadata: {}
126
+ post_install_message:
127
+ rdoc_options: []
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ requirements: []
141
+ rubyforge_project:
142
+ rubygems_version: 2.5.1
143
+ signing_key:
144
+ specification_version: 4
145
+ summary: Rails bindings for the Hyperwallet REST API.
146
+ test_files: []