bluepan_client 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +6 -0
  5. data/CHANGELOG.md +9 -0
  6. data/CODE_OF_CONDUCT.md +74 -0
  7. data/Gemfile +7 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +43 -0
  10. data/Rakefile +6 -0
  11. data/bin/console +14 -0
  12. data/bin/setup +8 -0
  13. data/bluepan_client.gemspec +45 -0
  14. data/lib/bluepan_client.rb +46 -0
  15. data/lib/bluepan_client/client.rb +51 -0
  16. data/lib/bluepan_client/factories.rb +16 -0
  17. data/lib/bluepan_client/indifferent_hash.rb +7 -0
  18. data/lib/bluepan_client/models/city.rb +11 -0
  19. data/lib/bluepan_client/models/province.rb +10 -0
  20. data/lib/bluepan_client/models/recipient.rb +18 -0
  21. data/lib/bluepan_client/models/remittance.rb +21 -0
  22. data/lib/bluepan_client/models/strategy.rb +14 -0
  23. data/lib/bluepan_client/requests/base_request.rb +24 -0
  24. data/lib/bluepan_client/requests/create_recipient_request.rb +24 -0
  25. data/lib/bluepan_client/requests/create_remittance_request.rb +48 -0
  26. data/lib/bluepan_client/requests/get_cities_request.rb +13 -0
  27. data/lib/bluepan_client/requests/get_provinces_request.rb +11 -0
  28. data/lib/bluepan_client/requests/get_recipient_request.rb +13 -0
  29. data/lib/bluepan_client/requests/get_strategies_request.rb +11 -0
  30. data/lib/bluepan_client/responses/base_response.rb +30 -0
  31. data/lib/bluepan_client/responses/create_recipient_response.rb +5 -0
  32. data/lib/bluepan_client/responses/create_remittance_response.rb +18 -0
  33. data/lib/bluepan_client/responses/get_cities_response.rb +13 -0
  34. data/lib/bluepan_client/responses/get_provinces_response.rb +13 -0
  35. data/lib/bluepan_client/responses/get_recipient_response.rb +5 -0
  36. data/lib/bluepan_client/responses/get_strategies_response.rb +13 -0
  37. data/lib/bluepan_client/responses/recipient_response.rb +13 -0
  38. data/lib/bluepan_client/schemas/base_schema.rb +10 -0
  39. data/lib/bluepan_client/schemas/client_schema.rb +5 -0
  40. data/lib/bluepan_client/schemas/create_recipient_schema.rb +11 -0
  41. data/lib/bluepan_client/schemas/create_remittance_schema.rb +25 -0
  42. data/lib/bluepan_client/schemas/get_recipient_schema.rb +7 -0
  43. data/lib/bluepan_client/services/apply_vars.rb +22 -0
  44. data/lib/bluepan_client/services/guard_null.rb +9 -0
  45. data/lib/bluepan_client/version.rb +3 -0
  46. metadata +243 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7223afb8f3d3013e7933a26f1331a44037f8ae8d
4
+ data.tar.gz: f7292af957992511e51802e64ab69f0951301e6c
5
+ SHA512:
6
+ metadata.gz: e5a0d4e4549306e5439abe1d2c2d234ea63c38f9355296cdccecffb7f6661c1a3226b0ade5465c466decf87c637a83ecf4581296d3e82477fcd6794601d8b0b5
7
+ data.tar.gz: 49c507aa3ee2aa485c2b9b27d91640eafa400e7e94cd922525ad2bca603d64935763d69b0fa9e48df6a754e6a5b9f0c187365e1ef8ce6b7a586c0f834116e7de
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /spec/config.yml
10
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,6 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.0
5
+ before_install: gem install bundler -v 1.13.1
6
+ before_script: cp spec/config.yml{.sample,}
@@ -0,0 +1,9 @@
1
+ # Change Log
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](http://keepachangelog.com/)
5
+ and this project adheres to [Semantic Versioning](http://semver.org/).
6
+
7
+ ## [0.1.0] - 2016-11-11
8
+ ### Added
9
+ - Initial working version
@@ -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 ramon.tayag@gmail.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,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bluepan_client.gemspec
4
+ gemspec
5
+
6
+ gem "pry"
7
+ gem "pry-byebug"
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Ramon Tayag
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,43 @@
1
+ # BluepanClient
2
+
3
+ [![Build Status](https://travis-ci.org/imacchiato/bluepan_client-ruby.svg?branch=master)](https://travis-ci.org/imacchiato/bluepan_client-ruby)
4
+
5
+ Ruby wrapper for Bluepan API.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'bluepan_client'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install bluepan_client
22
+
23
+ ## Usage
24
+
25
+ See `spec/acceptance` for examples.
26
+
27
+ ## Development
28
+
29
+ - Copy `spec/config.yml.sample` to `spec/config.yml` and fill in with your test credentials. **NOTE**: there is no staging server, so the gem connects to the production server. Tests will write into your production data. We have taken and taking steps to write things that are inconsequential (i.e. do not use up your credit).
30
+
31
+ ### On Your App
32
+
33
+ You may use FactoryGirl factories that were added for your convenience by calling `require "bluepan_client/factories"`
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/imacchiato/bluepan_client-ruby. 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.
38
+
39
+
40
+ ## License
41
+
42
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
43
+
@@ -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 "bluepan_client"
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,45 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bluepan_client/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bluepan_client"
8
+ spec.version = BluepanClient::VERSION
9
+ spec.authors = ["Ramon Tayag"]
10
+ spec.email = ["ramon.tayag@gmail.com"]
11
+
12
+ spec.summary = %q{Ruby wrapper for Bluepan's API}
13
+ spec.description = %q{Ruby wrapper for Bluepan's API - access to Pay86 and payments to Korea}
14
+ spec.homepage = "https://github.com/imacchiato/bluepan_client-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'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_dependency "virtus", "~> 1.0"
34
+ spec.add_dependency "dry-validation"
35
+ spec.add_dependency "activesupport"
36
+ spec.add_dependency "httparty"
37
+
38
+ spec.add_development_dependency "bundler", "~> 1.13"
39
+ spec.add_development_dependency "rake", "~> 10.0"
40
+ spec.add_development_dependency "rspec", "~> 3.0"
41
+ spec.add_development_dependency "virtus-matchers"
42
+ spec.add_development_dependency "vcr"
43
+ spec.add_development_dependency "webmock"
44
+ spec.add_development_dependency "dry-validation-matchers"
45
+ end
@@ -0,0 +1,46 @@
1
+ require "virtus"
2
+ require "httparty"
3
+ require "dry-validation"
4
+ require "active_support/core_ext/hash/indifferent_access"
5
+ require "bluepan_client/version"
6
+ require "bluepan_client/indifferent_hash"
7
+ require "bluepan_client/services/guard_null"
8
+ require "bluepan_client/services/apply_vars"
9
+ require "bluepan_client/schemas/base_schema"
10
+ require "bluepan_client/schemas/client_schema"
11
+ require "bluepan_client/schemas/create_recipient_schema"
12
+ require "bluepan_client/schemas/get_recipient_schema"
13
+ require "bluepan_client/schemas/create_remittance_schema"
14
+ require "bluepan_client/models/city"
15
+ require "bluepan_client/models/province"
16
+ require "bluepan_client/models/recipient"
17
+ require "bluepan_client/models/remittance"
18
+ require "bluepan_client/models/strategy"
19
+ require "bluepan_client/client"
20
+ require "bluepan_client/requests/base_request"
21
+ require "bluepan_client/requests/get_cities_request"
22
+ require "bluepan_client/requests/get_provinces_request"
23
+ require "bluepan_client/requests/get_strategies_request"
24
+ require "bluepan_client/requests/create_recipient_request"
25
+ require "bluepan_client/requests/create_remittance_request"
26
+ require "bluepan_client/requests/get_recipient_request"
27
+ require "bluepan_client/responses/base_response"
28
+ require "bluepan_client/responses/get_cities_response"
29
+ require "bluepan_client/responses/get_provinces_response"
30
+ require "bluepan_client/responses/get_strategies_response"
31
+ require "bluepan_client/responses/recipient_response"
32
+ require "bluepan_client/responses/create_recipient_response"
33
+ require "bluepan_client/responses/create_remittance_response"
34
+ require "bluepan_client/responses/get_recipient_response"
35
+
36
+ module BluepanClient
37
+
38
+ def self.new(opts={})
39
+ client = Client.new(opts)
40
+ error_messages = ClientSchema.(client.attributes).
41
+ messages(full: true).values
42
+ fail ArgumentError, error_messages if error_messages.any?
43
+ client
44
+ end
45
+
46
+ end
@@ -0,0 +1,51 @@
1
+ module BluepanClient
2
+ class Client
3
+
4
+ HOSTS = {
5
+ production: "https://api.bluepan.net",
6
+ staging: "https://api.bluepan.net", # There is no staging server, yet
7
+ }
8
+
9
+ include Virtus.model
10
+ attribute :host, String, default: HOSTS.fetch(:staging)
11
+ attribute :api_token, String
12
+ attribute :api_secret, String
13
+
14
+ def get_cities(provinceseq)
15
+ request = GetCitiesRequest.new(attributes.merge(provinceseq: provinceseq))
16
+ raw_response = request.()
17
+ GetCitiesResponse.new(raw_response: raw_response)
18
+ end
19
+
20
+ def get_provinces
21
+ request = GetProvincesRequest.new(attributes)
22
+ raw_response = request.()
23
+ GetProvincesResponse.new(raw_response: raw_response)
24
+ end
25
+
26
+ def get_strategies
27
+ request = GetStrategiesRequest.new(attributes)
28
+ raw_response = request.()
29
+ GetStrategiesResponse.new(raw_response: raw_response)
30
+ end
31
+
32
+ def create_recipient(args)
33
+ request = CreateRecipientRequest.new(attributes.merge(args))
34
+ raw_response = request.()
35
+ CreateRecipientResponse.new(raw_response: raw_response)
36
+ end
37
+
38
+ def get_recipient(id)
39
+ request = GetRecipientRequest.new(attributes.merge(recipientseq: id))
40
+ raw_response = request.()
41
+ GetRecipientResponse.new(raw_response: raw_response)
42
+ end
43
+
44
+ def create_remittance(args)
45
+ request = CreateRemittanceRequest.new(attributes.merge(args))
46
+ raw_response = request.()
47
+ CreateRemittanceResponse.new(raw_response: raw_response)
48
+ end
49
+
50
+ end
51
+ end
@@ -0,0 +1,16 @@
1
+ FactoryGirl.define do
2
+
3
+ factory :bluepan_client_province, class: "BluepanClient::Province" do
4
+ sequence(:provinceseq) { |n| n }
5
+ provincename_en "English Name"
6
+ provincename_cn "Chinese Name"
7
+ end
8
+
9
+ factory :bluepan_client_city, class: "BluepanClient::City" do
10
+ sequence(:provinceseq) { |n| n }
11
+ sequence(:cityseq) { |n| n+50 }
12
+ cityname_en "English Name"
13
+ cityname_cn "Chinese Name"
14
+ end
15
+
16
+ end
@@ -0,0 +1,7 @@
1
+ module BluepanClient
2
+ class IndifferentHash < Virtus::Attribute
3
+ def coerce(value)
4
+ value.is_a?(::Hash) ? value.with_indifferent_access : value
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ module BluepanClient
2
+ class City
3
+
4
+ include Virtus.model
5
+ attribute :cityseq, Integer
6
+ attribute :provinceseq, Integer
7
+ attribute :cityname_en, String
8
+ attribute :cityname_cn, String
9
+
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ module BluepanClient
2
+ class Province
3
+
4
+ include Virtus.model
5
+ attribute :provinceseq, Integer
6
+ attribute :provincename_en, String
7
+ attribute :provincename_cn, String
8
+
9
+ end
10
+ end
@@ -0,0 +1,18 @@
1
+ module BluepanClient
2
+ class Recipient
3
+
4
+ include Virtus.model
5
+ attribute :recipientseq, Integer
6
+ attribute :firstname, String
7
+ attribute :lastname, String
8
+ attribute :mobile, String
9
+ attribute :email, String
10
+ attribute :created_at, DateTime
11
+ attribute :updated_at, DateTime
12
+
13
+ def updated_at=(v)
14
+ super GuardNull.(v)
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,21 @@
1
+ module BluepanClient
2
+ class Remittance
3
+
4
+ include Virtus.model
5
+ attribute :remittanceseq, Integer
6
+ attribute :recipientseq, Integer
7
+ attribute :strategyseq, Integer
8
+ attribute :dest_currency, String
9
+ attribute :invoice_address, String
10
+ attribute :amount, Float
11
+ attribute :service_fee, Float
12
+ attribute :status, String
13
+ attribute :created_at, DateTime
14
+ attribute :completed_at, DateTime
15
+
16
+ def completed_at=(v)
17
+ super GuardNull.(v)
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,14 @@
1
+ module BluepanClient
2
+ class Strategy
3
+
4
+ include Virtus.model
5
+ attribute :strategyseq, Integer
6
+ attribute :currency, String
7
+ attribute :name_en, String
8
+ attribute :name, String
9
+ attribute :payoutmethod, String
10
+ attribute :strategy, String
11
+ attribute :maximum, Float
12
+
13
+ end
14
+ end
@@ -0,0 +1,24 @@
1
+ module BluepanClient
2
+ class BaseRequest
3
+
4
+ include Virtus.model
5
+ attribute :host, String
6
+ attribute :api_token, String
7
+ attribute :api_secret, String
8
+ attribute :path, String, lazy: true, default: :default_path
9
+ attribute :uri, String, lazy: true, default: :default_uri
10
+
11
+ private
12
+
13
+ def default_path
14
+ ApplyVars.(self.class::PATH, self)
15
+ end
16
+
17
+ def default_uri
18
+ u = URI.parse(host)
19
+ u.path = path
20
+ u.to_s
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ module BluepanClient
2
+ class CreateRecipientRequest < BaseRequest
3
+
4
+ PATH = "/v1/:api_token/recipients"
5
+
6
+ attribute :recipient_firstname, String
7
+ attribute :recipient_lastname, String
8
+ attribute :recipient_mobile, String
9
+ attribute :recipient_email, String
10
+
11
+ def call
12
+ HTTParty.post(uri, {
13
+ body: attributes.slice(*%i[
14
+ api_secret
15
+ recipient_firstname
16
+ recipient_lastname
17
+ recipient_mobile
18
+ recipient_email
19
+ ])
20
+ })
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,48 @@
1
+ module BluepanClient
2
+ class CreateRemittanceRequest < BaseRequest
3
+
4
+ PATH = "/v1/:api_token/remittances"
5
+
6
+ attribute :paymethod, String
7
+ attribute :dest_currency, String
8
+ attribute :amount, Float
9
+ attribute :recipientseq, Integer
10
+ attribute :strategyseq, Integer
11
+ attribute :provinceseq, Integer
12
+ attribute :cityseq, Integer
13
+ attribute :accountname, String
14
+ attribute :accountnumber, String
15
+ attribute :branch, String
16
+ attribute :alipayid, String
17
+ attribute :wechatid, String
18
+ attribute :nick, String
19
+ attribute :payment_url, String
20
+ attribute :payment_account, String
21
+ attribute :payment_password, String
22
+
23
+ def call
24
+ HTTParty.post(uri, {
25
+ body: attributes.slice(*%i[
26
+ api_secret
27
+ paymethod
28
+ dest_currency
29
+ amount
30
+ recipientseq
31
+ strategyseq
32
+ provinceseq
33
+ cityseq
34
+ accountname
35
+ accountnumber
36
+ branch
37
+ alipayid
38
+ wechatid
39
+ nick
40
+ payment_url
41
+ payment_account
42
+ payment_password
43
+ ])
44
+ })
45
+ end
46
+
47
+ end
48
+ end
@@ -0,0 +1,13 @@
1
+ module BluepanClient
2
+ class GetCitiesRequest < BaseRequest
3
+
4
+ PATH = "/v1/:api_token/cities/:provinceseq"
5
+
6
+ attribute :provinceseq, Integer
7
+
8
+ def call
9
+ HTTParty.get(uri)
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ module BluepanClient
2
+ class GetProvincesRequest < BaseRequest
3
+
4
+ PATH = "/v1/:api_token/provinces"
5
+
6
+ def call
7
+ HTTParty.get(uri)
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ module BluepanClient
2
+ class GetRecipientRequest < BaseRequest
3
+
4
+ PATH = "/v1/:api_token/recipients/:recipientseq"
5
+
6
+ attribute :recipientseq, Integer
7
+
8
+ def call
9
+ HTTParty.get(uri)
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ module BluepanClient
2
+ class GetStrategiesRequest < BaseRequest
3
+
4
+ PATH = "/v1/:api_token/strategies"
5
+
6
+ def call
7
+ HTTParty.get(uri)
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,30 @@
1
+ module BluepanClient
2
+ class BaseResponse
3
+
4
+ include Virtus.model
5
+ attribute :raw_response, Object
6
+ attribute :body, String, lazy: true, default: :default_body
7
+ attribute(:parsed_body, IndifferentHash, {
8
+ lazy: true,
9
+ default: :default_parsed_body,
10
+ })
11
+ attribute :success, Boolean, lazy: true, default: :default_success
12
+
13
+ private
14
+
15
+ def default_success
16
+ return false if !raw_response.success?
17
+ return true if !parsed_body.respond_to?(:keys)
18
+ parsed_body[:error].nil?
19
+ end
20
+
21
+ def default_body
22
+ raw_response.body
23
+ end
24
+
25
+ def default_parsed_body
26
+ JSON.parse(body)
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,5 @@
1
+ module BluepanClient
2
+ class CreateRecipientResponse < RecipientResponse
3
+
4
+ end
5
+ end
@@ -0,0 +1,18 @@
1
+ module BluepanClient
2
+ class CreateRemittanceResponse < BaseResponse
3
+
4
+ attribute :remittance, Object, default: :default_remittance
5
+ attribute :recipient, Object, default: :default_recipient
6
+
7
+ private
8
+
9
+ def default_remittance
10
+ Remittance.new(parsed_body[:remittance])
11
+ end
12
+
13
+ def default_recipient
14
+ Recipient.new(parsed_body[:recipient])
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,13 @@
1
+ module BluepanClient
2
+ class GetCitiesResponse < BaseResponse
3
+
4
+ attribute :cities, Array, lazy: true, default: :default_cities
5
+
6
+ private
7
+
8
+ def default_cities
9
+ parsed_body.map { |city_hash| City.new(city_hash) }
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module BluepanClient
2
+ class GetProvincesResponse < BaseResponse
3
+
4
+ attribute :provinces, Array, lazy: true, default: :default_provinces
5
+
6
+ private
7
+
8
+ def default_provinces
9
+ parsed_body.map { |province_hash| Province.new(province_hash) }
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ module BluepanClient
2
+ class GetRecipientResponse < RecipientResponse
3
+
4
+ end
5
+ end
@@ -0,0 +1,13 @@
1
+ module BluepanClient
2
+ class GetStrategiesResponse < BaseResponse
3
+
4
+ attribute :strategies, Array, lazy: true, default: :default_strategies
5
+
6
+ private
7
+
8
+ def default_strategies
9
+ parsed_body.map { |strategy_hash| Strategy.new(strategy_hash) }
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module BluepanClient
2
+ class RecipientResponse < BaseResponse
3
+
4
+ attribute :recipient, Object, lazy: true, default: :default_recipient
5
+
6
+ private
7
+
8
+ def default_recipient
9
+ Recipient.new(parsed_body)
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,10 @@
1
+ module BluepanClient
2
+ class BaseSchema < Dry::Validation::Schema
3
+
4
+ define! do
5
+ required(:api_token).filled
6
+ required(:api_secret).filled
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ module BluepanClient
2
+ ClientSchema = Dry::Validation.Schema(BaseSchema) do
3
+
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ module BluepanClient
2
+ CreateRecipientSchema = Dry::Validation.Schema(BaseSchema) do
3
+
4
+ required(:api_secret).filled(:str?)
5
+ required(:recipient_firstname).filled(:str?)
6
+ required(:recipient_lastname).filled(:str?)
7
+ required(:recipient_mobile).filled(:str?)
8
+ optional(:recipient_email).filled(:str?)
9
+
10
+ end
11
+ end
@@ -0,0 +1,25 @@
1
+ module BluepanClient
2
+ CreateRemittanceSchema = Dry::Validation.Schema(BaseSchema) do
3
+
4
+ PAYMETHODS = %w(CREDIT BTC)
5
+ DEST_CURRENCIES = %w(KRW CNY)
6
+
7
+ optional(:paymethod).filled(:str?, included_in?: PAYMETHODS)
8
+ optional(:dest_currency).filled(:str?, included_in?: DEST_CURRENCIES)
9
+ required(:amount).filled(:float?)
10
+ required(:recipientseq).filled(:int?)
11
+ required(:strategyseq).filled(:int?)
12
+ optional(:provinceseq).filled(:int?)
13
+ optional(:cityseq).filled(:int?)
14
+ optional(:accountname).filled(:str?)
15
+ optional(:accountnumber).filled(:str?)
16
+ optional(:branch).filled(:str?)
17
+ optional(:alipayid).filled(:str?)
18
+ optional(:wechatid).filled(:str?)
19
+ optional(:nick).filled(:str?)
20
+ optional(:payment_url).filled(:str?)
21
+ optional(:payment_account).filled(:str?)
22
+ optional(:payment_password).filled(:str?)
23
+
24
+ end
25
+ end
@@ -0,0 +1,7 @@
1
+ module BluepanClient
2
+ GetRecipientSchema = Dry::Validation.Schema(BaseSchema) do
3
+
4
+ required(:recipientseq).filled
5
+
6
+ end
7
+ end
@@ -0,0 +1,22 @@
1
+ module BluepanClient
2
+ class ApplyVars
3
+
4
+ include Virtus.model
5
+ attribute :string, String
6
+ attribute :object, Object
7
+
8
+ def self.call(string, object)
9
+ self.new(string: string, object: object).()
10
+ end
11
+
12
+ def call
13
+ matches = string.scan(/:\w+/)
14
+ matches.reduce(string) do |str, var|
15
+ method_name = var.gsub(":", "")
16
+ value = object.send(method_name)
17
+ str.gsub(var, value.to_s)
18
+ end
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,9 @@
1
+ module BluepanClient
2
+ class GuardNull
3
+
4
+ def self.call(value)
5
+ value == "null" ? nil : value
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module BluepanClient
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,243 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bluepan_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ramon Tayag
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-11-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: virtus
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: dry-validation
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: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: httparty
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.13'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.13'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: virtus-matchers
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
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: vcr
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
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: webmock
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: dry-validation-matchers
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ description: Ruby wrapper for Bluepan's API - access to Pay86 and payments to Korea
168
+ email:
169
+ - ramon.tayag@gmail.com
170
+ executables: []
171
+ extensions: []
172
+ extra_rdoc_files: []
173
+ files:
174
+ - ".gitignore"
175
+ - ".rspec"
176
+ - ".travis.yml"
177
+ - CHANGELOG.md
178
+ - CODE_OF_CONDUCT.md
179
+ - Gemfile
180
+ - LICENSE.txt
181
+ - README.md
182
+ - Rakefile
183
+ - bin/console
184
+ - bin/setup
185
+ - bluepan_client.gemspec
186
+ - lib/bluepan_client.rb
187
+ - lib/bluepan_client/client.rb
188
+ - lib/bluepan_client/factories.rb
189
+ - lib/bluepan_client/indifferent_hash.rb
190
+ - lib/bluepan_client/models/city.rb
191
+ - lib/bluepan_client/models/province.rb
192
+ - lib/bluepan_client/models/recipient.rb
193
+ - lib/bluepan_client/models/remittance.rb
194
+ - lib/bluepan_client/models/strategy.rb
195
+ - lib/bluepan_client/requests/base_request.rb
196
+ - lib/bluepan_client/requests/create_recipient_request.rb
197
+ - lib/bluepan_client/requests/create_remittance_request.rb
198
+ - lib/bluepan_client/requests/get_cities_request.rb
199
+ - lib/bluepan_client/requests/get_provinces_request.rb
200
+ - lib/bluepan_client/requests/get_recipient_request.rb
201
+ - lib/bluepan_client/requests/get_strategies_request.rb
202
+ - lib/bluepan_client/responses/base_response.rb
203
+ - lib/bluepan_client/responses/create_recipient_response.rb
204
+ - lib/bluepan_client/responses/create_remittance_response.rb
205
+ - lib/bluepan_client/responses/get_cities_response.rb
206
+ - lib/bluepan_client/responses/get_provinces_response.rb
207
+ - lib/bluepan_client/responses/get_recipient_response.rb
208
+ - lib/bluepan_client/responses/get_strategies_response.rb
209
+ - lib/bluepan_client/responses/recipient_response.rb
210
+ - lib/bluepan_client/schemas/base_schema.rb
211
+ - lib/bluepan_client/schemas/client_schema.rb
212
+ - lib/bluepan_client/schemas/create_recipient_schema.rb
213
+ - lib/bluepan_client/schemas/create_remittance_schema.rb
214
+ - lib/bluepan_client/schemas/get_recipient_schema.rb
215
+ - lib/bluepan_client/services/apply_vars.rb
216
+ - lib/bluepan_client/services/guard_null.rb
217
+ - lib/bluepan_client/version.rb
218
+ homepage: https://github.com/imacchiato/bluepan_client-ruby
219
+ licenses:
220
+ - MIT
221
+ metadata:
222
+ allowed_push_host: https://rubygems.org
223
+ post_install_message:
224
+ rdoc_options: []
225
+ require_paths:
226
+ - lib
227
+ required_ruby_version: !ruby/object:Gem::Requirement
228
+ requirements:
229
+ - - ">="
230
+ - !ruby/object:Gem::Version
231
+ version: '0'
232
+ required_rubygems_version: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - ">="
235
+ - !ruby/object:Gem::Version
236
+ version: '0'
237
+ requirements: []
238
+ rubyforge_project:
239
+ rubygems_version: 2.5.1
240
+ signing_key:
241
+ specification_version: 4
242
+ summary: Ruby wrapper for Bluepan's API
243
+ test_files: []