cashila-api 0.1.0
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 +7 -0
- data/Gemfile +4 -0
- data/README.md +43 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/cashila-api.gemspec +30 -0
- data/lib/cashila-api.rb +7 -0
- data/lib/cashila-api/client.rb +162 -0
- data/lib/cashila-api/version.rb +3 -0
- metadata +151 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 1809b21228fcd6fbe722e59e28390407c8132f31
|
|
4
|
+
data.tar.gz: ad0739f137ae7578dfb61bb644850930b7193c3d
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 2f2a17152df4653040d260a0d9bf0ee5a4d045dd90700ef9d5f7f3767678acfcddc05d428857e2c43c0af7b1a5a4f2b9b508798a5cc18376b7696d4c096d6c09
|
|
7
|
+
data.tar.gz: 0c5cc904f3d523e6826cae2c0527c791aca854c3ce7ae054da7f90190966dcd1531e12a520558ded3328f630f73e629aa45c637348bd9c484062b1e68621bdb9
|
data/Gemfile
ADDED
data/README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# CashilaAPI
|
|
2
|
+
|
|
3
|
+
This gem is a wrapper for [Cashila](https://www.cashila.com/) API.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'cashila-api'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
$ bundle
|
|
16
|
+
|
|
17
|
+
Or install it yourself as:
|
|
18
|
+
|
|
19
|
+
$ gem install cashila-api
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
require 'cashila-api'
|
|
24
|
+
client = CashilaAPI::Client.new(
|
|
25
|
+
token: 'API-User',
|
|
26
|
+
secret: 'secret for API-Sign',
|
|
27
|
+
client_id: 'API-Client',
|
|
28
|
+
url: CashilaAPI::PRODUCTION_URL,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
## Development
|
|
32
|
+
|
|
33
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
34
|
+
|
|
35
|
+
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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
36
|
+
|
|
37
|
+
## Contributing
|
|
38
|
+
|
|
39
|
+
1. Fork it ( https://github.com/[my-github-username]/cashila-api/fork )
|
|
40
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
41
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
42
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
43
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "cashila-api"
|
|
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
data/cashila-api.gemspec
ADDED
|
@@ -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 'cashila-api/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = 'cashila-api'
|
|
8
|
+
spec.version = CashilaAPI::VERSION
|
|
9
|
+
spec.authors = ['AlexanderPavlenko']
|
|
10
|
+
spec.email = ['alerticus@gmail.com']
|
|
11
|
+
|
|
12
|
+
spec.summary = %q{Wrapper for Cashila API}
|
|
13
|
+
spec.description = %q{Wrapper for Cashila API}
|
|
14
|
+
spec.homepage = 'https://github.com/MyceliumGear/cashila-api'
|
|
15
|
+
spec.license = 'MIT'
|
|
16
|
+
|
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(\.|(test|spec|features)/)}) }
|
|
18
|
+
spec.bindir = 'exe'
|
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
20
|
+
spec.require_paths = ['lib']
|
|
21
|
+
|
|
22
|
+
spec.add_dependency 'multi_json', '~> 1.11'
|
|
23
|
+
spec.add_dependency 'faraday', '~> 0.9.1'
|
|
24
|
+
|
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.8'
|
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
|
27
|
+
spec.add_development_dependency 'rspec'
|
|
28
|
+
spec.add_development_dependency 'vcr'
|
|
29
|
+
spec.add_development_dependency 'webmock'
|
|
30
|
+
end
|
data/lib/cashila-api.rb
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
require 'base64'
|
|
2
|
+
require 'openssl'
|
|
3
|
+
require 'multi_json'
|
|
4
|
+
require 'faraday'
|
|
5
|
+
|
|
6
|
+
module CashilaAPI
|
|
7
|
+
class Client
|
|
8
|
+
|
|
9
|
+
InvalidCredentials = Class.new(ArgumentError)
|
|
10
|
+
|
|
11
|
+
class ApiError < StandardError
|
|
12
|
+
|
|
13
|
+
attr_reader :raw, :code
|
|
14
|
+
|
|
15
|
+
def initialize(error)
|
|
16
|
+
@raw = error
|
|
17
|
+
@code = error['code']
|
|
18
|
+
super error['user_message'] || error['message']
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
attr_accessor :client_id, :token, :secret, :url
|
|
23
|
+
|
|
24
|
+
def initialize(client_id:, token: nil, secret: nil, url: CashilaAPI::TEST_URL)
|
|
25
|
+
@url = url
|
|
26
|
+
@token = token
|
|
27
|
+
@secret = secret
|
|
28
|
+
@client_id = client_id
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def request_signup
|
|
32
|
+
response = connection.post('/api/v1/request-signup')
|
|
33
|
+
result = parse_response(response)
|
|
34
|
+
@token = result['token']
|
|
35
|
+
@secret = result['secret']
|
|
36
|
+
result
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# @param [String] email
|
|
40
|
+
# @param [Hash] details keys: first_name, last_name, address, postal_code, city, country_code
|
|
41
|
+
def sync_account(email:, details:)
|
|
42
|
+
response = connection(sign: true).put('/api/v1/account') do |req|
|
|
43
|
+
req.body = MultiJson.dump(
|
|
44
|
+
account: {
|
|
45
|
+
email: email,
|
|
46
|
+
},
|
|
47
|
+
verification: details,
|
|
48
|
+
)
|
|
49
|
+
end
|
|
50
|
+
parse_response(response)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# @param [Hash[Symbol => String]] docs
|
|
54
|
+
def upload_docs(docs)
|
|
55
|
+
%i{gov-id-front gov-id-back residence}.map do |key|
|
|
56
|
+
if (doc = docs[key])
|
|
57
|
+
response = connection(sign: true).put("/api/v1/verification/#{key}") do |req|
|
|
58
|
+
req.headers[:content_type] = 'application/octet-stream'
|
|
59
|
+
req.body = doc
|
|
60
|
+
end
|
|
61
|
+
parse_response(response)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# @param [Hash] details keys: id (optional), name, address, postal_code, city, country_code, iban, bic
|
|
67
|
+
def sync_recipient(details)
|
|
68
|
+
return if !details || details.empty?
|
|
69
|
+
details = details.dup
|
|
70
|
+
id = details.delete(:id)
|
|
71
|
+
response = connection(sign: true).put("/api/v1/recipients#{id.to_s.empty? ? '' : "/#{id}"}") do |req|
|
|
72
|
+
req.body = MultiJson.dump(details)
|
|
73
|
+
end
|
|
74
|
+
parse_response(response)['id']
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def get_recipient(id)
|
|
78
|
+
response = connection(sign: true).get("/api/v1/recipients/#{id}")
|
|
79
|
+
parse_response(response)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def verification_status
|
|
83
|
+
response = connection(sign: true).get('/api/v1/verification')
|
|
84
|
+
parse_response(response)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def create_billpay(recipient_id:, amount:, currency: 'EUR', reference: nil, refund: nil)
|
|
88
|
+
response = connection(sign: true).put('/api/v1/billpays/create') do |req|
|
|
89
|
+
params = {
|
|
90
|
+
amount: amount,
|
|
91
|
+
currency: currency,
|
|
92
|
+
based_on: recipient_id,
|
|
93
|
+
}
|
|
94
|
+
params[:reference] = reference if reference
|
|
95
|
+
params[:refund] = refund if refund
|
|
96
|
+
req.body = MultiJson.dump(params)
|
|
97
|
+
end
|
|
98
|
+
parse_response(response)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def parse_response(response)
|
|
103
|
+
result = MultiJson.load(response.body)
|
|
104
|
+
if (error = result['error'])
|
|
105
|
+
raise ApiError.new(error)
|
|
106
|
+
end
|
|
107
|
+
result['result'] || result
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def connection(sign: false)
|
|
111
|
+
Faraday.new(connection_options) do |faraday|
|
|
112
|
+
if sign
|
|
113
|
+
raise InvalidCredentials unless @token && @secret
|
|
114
|
+
faraday.use SigningMiddleware, @token, @secret
|
|
115
|
+
end
|
|
116
|
+
faraday.adapter :net_http
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
private def connection_options
|
|
121
|
+
{
|
|
122
|
+
url: @url,
|
|
123
|
+
ssl: {
|
|
124
|
+
ca_path: '/usr/lib/ssl/certs',
|
|
125
|
+
},
|
|
126
|
+
headers: {
|
|
127
|
+
content_type: 'application/json',
|
|
128
|
+
'API-Client' => @client_id,
|
|
129
|
+
},
|
|
130
|
+
}
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
class SigningMiddleware < Faraday::Middleware
|
|
135
|
+
|
|
136
|
+
def initialize(app, token, secret)
|
|
137
|
+
@app = app
|
|
138
|
+
@token = token
|
|
139
|
+
@secret = Base64.decode64(secret)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def call(env)
|
|
143
|
+
env[:request_headers]['API-User'] = @token
|
|
144
|
+
env[:request_headers]['API-Nonce'] = (Time.now.to_f * 1000000).to_i.to_s
|
|
145
|
+
env[:request_headers]['API-Sign'] = signature(env)
|
|
146
|
+
@app.call(env)
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
# Base64Encode(
|
|
150
|
+
# HMAC-SHA512(
|
|
151
|
+
# “PUT/v1/billpays” + SHA256(“1434363295”+”{“based_on”:123}”),
|
|
152
|
+
# Base64Decode(“secret”)
|
|
153
|
+
# )
|
|
154
|
+
# )
|
|
155
|
+
def signature(env)
|
|
156
|
+
request = "#{env[:request_headers]['API-Nonce']}#{env[:body]}"
|
|
157
|
+
request = "#{env[:method].to_s.upcase}#{URI(env[:url]).path.sub('/api', '')}#{OpenSSL::Digest::SHA256.new.digest(request)}"
|
|
158
|
+
Base64.strict_encode64 OpenSSL::HMAC.digest('sha512', @secret, request)
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: cashila-api
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- AlexanderPavlenko
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-06-19 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: multi_json
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.11'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.11'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: faraday
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: 0.9.1
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: 0.9.1
|
|
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.8'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '1.8'
|
|
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: '0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - ">="
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '0'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: vcr
|
|
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
|
+
- !ruby/object:Gem::Dependency
|
|
98
|
+
name: webmock
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - ">="
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: '0'
|
|
104
|
+
type: :development
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - ">="
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: '0'
|
|
111
|
+
description: Wrapper for Cashila API
|
|
112
|
+
email:
|
|
113
|
+
- alerticus@gmail.com
|
|
114
|
+
executables: []
|
|
115
|
+
extensions: []
|
|
116
|
+
extra_rdoc_files: []
|
|
117
|
+
files:
|
|
118
|
+
- Gemfile
|
|
119
|
+
- README.md
|
|
120
|
+
- Rakefile
|
|
121
|
+
- bin/console
|
|
122
|
+
- bin/setup
|
|
123
|
+
- cashila-api.gemspec
|
|
124
|
+
- lib/cashila-api.rb
|
|
125
|
+
- lib/cashila-api/client.rb
|
|
126
|
+
- lib/cashila-api/version.rb
|
|
127
|
+
homepage: https://github.com/MyceliumGear/cashila-api
|
|
128
|
+
licenses:
|
|
129
|
+
- MIT
|
|
130
|
+
metadata: {}
|
|
131
|
+
post_install_message:
|
|
132
|
+
rdoc_options: []
|
|
133
|
+
require_paths:
|
|
134
|
+
- lib
|
|
135
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
136
|
+
requirements:
|
|
137
|
+
- - ">="
|
|
138
|
+
- !ruby/object:Gem::Version
|
|
139
|
+
version: '0'
|
|
140
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
141
|
+
requirements:
|
|
142
|
+
- - ">="
|
|
143
|
+
- !ruby/object:Gem::Version
|
|
144
|
+
version: '0'
|
|
145
|
+
requirements: []
|
|
146
|
+
rubyforge_project:
|
|
147
|
+
rubygems_version: 2.4.6
|
|
148
|
+
signing_key:
|
|
149
|
+
specification_version: 4
|
|
150
|
+
summary: Wrapper for Cashila API
|
|
151
|
+
test_files: []
|