cryptopay 0.0.2
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/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +66 -0
- data/Rakefile +1 -0
- data/cryptopay.gemspec +25 -0
- data/lib/cryptopay.rb +31 -0
- data/lib/cryptopay/net.rb +37 -0
- data/lib/cryptopay/version.rb +3 -0
- metadata +95 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ea9dfc945b82a35e2b9fc821f8149aed82ff6883
|
4
|
+
data.tar.gz: cb4b01d2c783acf17b22e848bdc8d8f7308d6e7c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b51257dc276b500ef850696f0936a9ce8bd34703761b3528b5cca92b67d030ae5f8812657dbd227caffd850808343ab6a01b2984a2c72cdcbe6624a492d215fe
|
7
|
+
data.tar.gz: 620ed0ff4127cff7eb4a3eab8564598e05478fc3c51090d9c6ce004c98d2e14bcba11de83106542aa29aa9bb7615d998009f4ba5bfd08897b0cde5ac2afc7ceb
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 vadim
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# Installation
|
2
|
+
|
3
|
+
```ruby
|
4
|
+
gem install cryptopay
|
5
|
+
```
|
6
|
+
|
7
|
+
|
8
|
+
or your Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'cryptopay'`
|
12
|
+
```
|
13
|
+
|
14
|
+
And set your api key.
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
Cryptopay.key = '38a193829970502311698ce3f9cd5abb'
|
18
|
+
```
|
19
|
+
|
20
|
+
# Basic Usage
|
21
|
+
|
22
|
+
To create an invoice:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
invoice = Cryptopay.new_invoice id: 'test',
|
26
|
+
price: 2.32,
|
27
|
+
currency: 'GBP',
|
28
|
+
description: 'test description',
|
29
|
+
success_redirect_url: 'https://cryptopay.me',
|
30
|
+
callback_url: 'https://cryptopay.me'
|
31
|
+
```
|
32
|
+
now invoice object is hash with next attributes
|
33
|
+
```ruby
|
34
|
+
uuid: 'cf47603e-8e86-413d-86f2-0cf94fe05683',
|
35
|
+
description: 'test description',
|
36
|
+
status: 'pending',
|
37
|
+
btc_price: 0.0055,
|
38
|
+
btc_address: '16KcaBuNbHXhTweJspFkSku2nmvvyV8NoL',
|
39
|
+
short_id: 'CF47603E',
|
40
|
+
callback_params: nil,
|
41
|
+
id: 'test',
|
42
|
+
price: 2.32,
|
43
|
+
currency: 'GBP',
|
44
|
+
created_at: 1387305401,
|
45
|
+
valid_till: 1387306001
|
46
|
+
```
|
47
|
+
|
48
|
+
You can save `uuid` and use this later for update invoice status:
|
49
|
+
```ruby
|
50
|
+
Cryptopay.invoice invoice['uuid']
|
51
|
+
```
|
52
|
+
|
53
|
+
|
54
|
+
# Errors handle
|
55
|
+
classic ruby-way
|
56
|
+
```ruby
|
57
|
+
begin
|
58
|
+
params = Cryptopay.new_invoice id: 'test',
|
59
|
+
price: 0
|
60
|
+
|
61
|
+
rescue Cryptopay::Error => e
|
62
|
+
e.errors['price']
|
63
|
+
#["must be greater than 0"]
|
64
|
+
end
|
65
|
+
|
66
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/cryptopay.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'cryptopay/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "cryptopay"
|
8
|
+
spec.version = Cryptopay::VERSION
|
9
|
+
spec.authors = ["vadim"]
|
10
|
+
spec.email = ["just.zimer@gmail.com"]
|
11
|
+
spec.description = 'Gem for cryptopay.me API'
|
12
|
+
spec.summary = ''
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
|
24
|
+
spec.add_runtime_dependency 'rest-client'
|
25
|
+
end
|
data/lib/cryptopay.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require "cryptopay/version"
|
2
|
+
require 'rest_client'
|
3
|
+
require 'net/http'
|
4
|
+
require 'cryptopay/net'
|
5
|
+
|
6
|
+
module Cryptopay
|
7
|
+
class Error < Exception; attr_accessor :errors; end
|
8
|
+
# API Key
|
9
|
+
mattr_accessor :key
|
10
|
+
|
11
|
+
def self.new_invoice(params = {})
|
12
|
+
sanity_check!
|
13
|
+
|
14
|
+
Cryptopay::Request.post 'invoices', params
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.invoice uuid
|
18
|
+
Cryptopay::Request.get "invoices/#{uuid}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.configured?
|
22
|
+
self.key
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.sanity_check!
|
26
|
+
unless configured?
|
27
|
+
raise Exception.new("Cryptopay Gem not properly configured")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Cryptopay
|
2
|
+
module Request
|
3
|
+
def self.to_uri(path)
|
4
|
+
"https://cryptopay.me/api/v1/#{path}"
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.request(verb, path, options={})
|
8
|
+
verb = verb.upcase.to_sym
|
9
|
+
|
10
|
+
options[:api_key] = Cryptopay.key
|
11
|
+
|
12
|
+
resource = RestClient::Resource.new to_uri(path), content_type: 'application/json'
|
13
|
+
begin
|
14
|
+
if verb == :GET
|
15
|
+
response = RestClient.get "#{to_uri(path)}?".concat(options.collect { |k,v| "#{k}=#{CGI::escape(v.to_s)}" }.join('&'))
|
16
|
+
elsif verb == :POST
|
17
|
+
response = resource.post options
|
18
|
+
end
|
19
|
+
|
20
|
+
return JSON.parse response
|
21
|
+
|
22
|
+
rescue => e
|
23
|
+
error = Cryptopay::Error.new "#{e.message} (#{e.class})"
|
24
|
+
error.errors = JSON.parse(e.response)
|
25
|
+
raise error
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.get(path, options={})
|
30
|
+
self.request(:GET, path, options)
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.post(path, options={})
|
34
|
+
self.request(:POST, path, options)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cryptopay
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- vadim
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
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: rest-client
|
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
|
+
description: Gem for cryptopay.me API
|
56
|
+
email:
|
57
|
+
- just.zimer@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- cryptopay.gemspec
|
68
|
+
- lib/cryptopay.rb
|
69
|
+
- lib/cryptopay/net.rb
|
70
|
+
- lib/cryptopay/version.rb
|
71
|
+
homepage: ''
|
72
|
+
licenses:
|
73
|
+
- MIT
|
74
|
+
metadata: {}
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 2.1.11
|
92
|
+
signing_key:
|
93
|
+
specification_version: 4
|
94
|
+
summary: ''
|
95
|
+
test_files: []
|