cryptoprocessing 0.6.1

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.
Files changed (67) hide show
  1. checksums.yaml +7 -0
  2. data/.codeclimate.yml +35 -0
  3. data/.coveralls.yml +1 -0
  4. data/.document +5 -0
  5. data/.editorconfig +12 -0
  6. data/.gemtest +0 -0
  7. data/.gitattributes +1 -0
  8. data/.gitignore +129 -0
  9. data/.hound.yml +5 -0
  10. data/.rspec +3 -0
  11. data/.rubocop.yml +65 -0
  12. data/.rubocop_todo.yml +0 -0
  13. data/.ruby-version +1 -0
  14. data/.simplecov +8 -0
  15. data/.travis.yml +11 -0
  16. data/.yardopts +10 -0
  17. data/CHANGELOG.md +12 -0
  18. data/CODE_OF_CONDUCT.md +74 -0
  19. data/Gemfile +6 -0
  20. data/Gemfile.lock +94 -0
  21. data/LICENSE.txt +21 -0
  22. data/NOTICE.txt +2 -0
  23. data/README.md +86 -0
  24. data/Rakefile +21 -0
  25. data/VERSION +1 -0
  26. data/bin/console +14 -0
  27. data/bin/setup +8 -0
  28. data/cryptoprocessing.gemspec +39 -0
  29. data/exe/cryptoprocessing +5 -0
  30. data/lib/cryptoprocessing.rb +37 -0
  31. data/lib/cryptoprocessing/adapters/em_http.rb +71 -0
  32. data/lib/cryptoprocessing/adapters/net_http.rb +6 -0
  33. data/lib/cryptoprocessing/authentication.rb +67 -0
  34. data/lib/cryptoprocessing/authentication/storages/file_token_store.rb +0 -0
  35. data/lib/cryptoprocessing/authentication/storages/redis_token_store.rb +0 -0
  36. data/lib/cryptoprocessing/authentication/token_store.rb +57 -0
  37. data/lib/cryptoprocessing/cli.rb +203 -0
  38. data/lib/cryptoprocessing/client.rb +108 -0
  39. data/lib/cryptoprocessing/client/accounts.rb +43 -0
  40. data/lib/cryptoprocessing/client/addresses.rb +56 -0
  41. data/lib/cryptoprocessing/client/api_errors.rb +7 -0
  42. data/lib/cryptoprocessing/client/api_response.rb +39 -0
  43. data/lib/cryptoprocessing/client/callbacks.rb +39 -0
  44. data/lib/cryptoprocessing/client/coinbase_wallet.rb +45 -0
  45. data/lib/cryptoprocessing/client/net_response.rb +100 -0
  46. data/lib/cryptoprocessing/client/trackers.rb +37 -0
  47. data/lib/cryptoprocessing/client/transactions.rb +90 -0
  48. data/lib/cryptoprocessing/configurable.rb +73 -0
  49. data/lib/cryptoprocessing/connection.rb +140 -0
  50. data/lib/cryptoprocessing/default.rb +78 -0
  51. data/lib/cryptoprocessing/error.rb +3 -0
  52. data/lib/cryptoprocessing/models/account.rb +39 -0
  53. data/lib/cryptoprocessing/models/address.rb +17 -0
  54. data/lib/cryptoprocessing/models/api_object.rb +14 -0
  55. data/lib/cryptoprocessing/models/callback.rb +4 -0
  56. data/lib/cryptoprocessing/models/tracker.rb +4 -0
  57. data/lib/cryptoprocessing/models/transaction.rb +6 -0
  58. data/lib/cryptoprocessing/models/user.rb +6 -0
  59. data/lib/cryptoprocessing/rails.rb +13 -0
  60. data/lib/cryptoprocessing/version.rb +17 -0
  61. data/script/bootstrap +5 -0
  62. data/script/cibuild +5 -0
  63. data/script/console +11 -0
  64. data/script/package +7 -0
  65. data/script/release +16 -0
  66. data/script/test +17 -0
  67. metadata +236 -0
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 OOM.AG
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/NOTICE.txt ADDED
@@ -0,0 +1,2 @@
1
+ Cryptoprocessing API Client for Ruby
2
+ Copyright 2018 OOM.ag. All Rights Reserved.
data/README.md ADDED
@@ -0,0 +1,86 @@
1
+ # Cryptoprocessing
2
+
3
+ Ruby Gem to access and interact with [Cryptoprocessing API](https://api.cryptoprocessing.io).
4
+
5
+ To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ [![Build Status](https://travis-ci.org/oomag/cryptoprocessing.rb.svg?branch=master)](https://travis-ci.org/oomag/cryptoprocessing.rb)
8
+ [![Coverage Status](https://coveralls.io/repos/github/oomag/cryptoprocessing.rb/badge.svg?branch=master)](https://coveralls.io/github/oomag/cryptoprocessing.rb?branch=master)
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'cryptoprocessing'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it manually as:
23
+
24
+ $ gem install cryptoprocessing
25
+
26
+ ## Usage
27
+
28
+ ### Basic usage
29
+
30
+ ```ruby
31
+ require 'cryptoprocessing'
32
+
33
+ # Authenticate using email and password
34
+ client = Cryptoprocessing::Client.new(email: '<EMAIL>', password: '<PASSWORD>')
35
+
36
+ # or
37
+
38
+ # Using block
39
+ Cryptoprocessing.configure do |c|
40
+ c.email = '<EMAIL>'
41
+ c.password = '<PASSWORD>'
42
+ end
43
+
44
+ # or
45
+
46
+ client = Cryptoprocessing::Client.new(access_token: '<TOKEN>')
47
+ client.account '<ACCOUNT_ID>'
48
+
49
+ ```
50
+
51
+ ### Paging
52
+
53
+
54
+ ## Authorization
55
+
56
+ ### Authorization using API keys
57
+
58
+
59
+ ## Logging
60
+
61
+ ## Development
62
+
63
+ 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.
64
+
65
+ 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).
66
+
67
+ ## Contributing
68
+
69
+ Bug reports and pull requests are welcome on GitHub at https://github.com/oomag/cryptoprocessing-api-client. 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.
70
+
71
+ ## TODO
72
+
73
+
74
+
75
+ ## License
76
+
77
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
78
+
79
+ ## Code of Conduct
80
+
81
+ Everyone interacting in the Cryptoprocessing project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/oomag/cryptoprocessing-api-client/blob/master/CODE_OF_CONDUCT.md).
82
+
83
+ # Credits
84
+
85
+ Arthur Chafonov <actuosus@gmail.com>
86
+
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ require 'rake'
2
+
3
+ require 'bundler/gem_tasks'
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ require 'rspec/core/rake_task'
7
+ RSpec::Core::RakeTask.new(:spec)
8
+
9
+ task :test => :spec
10
+ task :default => :spec
11
+
12
+ namespace :doc do
13
+ begin
14
+ require 'yard'
15
+ YARD::Rake::YardocTask.new do |task|
16
+ task.files = %w(README.md LICENSE.txt lib/**/*.rb)
17
+ task.options = %w(--output-dir doc/yard --markup markdown)
18
+ end
19
+ rescue LoadError
20
+ end
21
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.6.1
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'cryptoprocessing'
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(__FILE__)
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,39 @@
1
+ # frozen_string_literal: true
2
+ # -*- ruby -*-
3
+ # encoding: utf-8
4
+ # coding: utf-8
5
+
6
+ lib = File.expand_path('../lib', __FILE__)
7
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
8
+ require 'cryptoprocessing/version'
9
+
10
+ Gem::Specification.new do |spec|
11
+ spec.name = 'cryptoprocessing'
12
+ spec.version = Cryptoprocessing::VERSION.dup
13
+ spec.authors = ['Arthur Chafonov']
14
+ spec.email = ['actuosus@gmail.com']
15
+
16
+ spec.summary = 'Client for accessing Cryptoprocessing API'
17
+ spec.description = 'Gem to access Blockchain Cryptoprocessing Platform API'
18
+ spec.homepage = 'https://github.com/oomag/cryptoprocessing-api-client'
19
+ spec.license = 'MIT'
20
+
21
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
22
+ f.match(%r{^(\.idea|test|spec|features)/})
23
+ end
24
+ spec.bindir = 'exe'
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ['lib']
27
+ spec.platform = Gem::Platform::RUBY
28
+
29
+ spec.add_dependency 'logging', '~> 2.0'
30
+ spec.add_dependency 'thor', '~> 0.19'
31
+
32
+ spec.add_development_dependency 'bundler', '~> 1.16'
33
+ spec.add_development_dependency 'coveralls'
34
+ spec.add_development_dependency 'faker'
35
+ spec.add_development_dependency 'rake', '~> 10.0'
36
+ spec.add_development_dependency 'rspec', '~> 3.0'
37
+ spec.add_development_dependency 'simplecov'
38
+ spec.add_development_dependency 'webmock'
39
+ end
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'cryptoprocessing/cli'
4
+
5
+ Cryptoprocessing::CLI.start(ARGV)
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+ require 'cryptoprocessing/client'
4
+ require 'cryptoprocessing/default'
5
+
6
+ # Ruby module for to access Cryptoprocessing API
7
+ module Cryptoprocessing
8
+ class << self
9
+ include Cryptoprocessing::Configurable
10
+
11
+ # API client based on configured options {Configurable}
12
+ #
13
+ # @return [Cryptoprocessing::Client] API wrapper
14
+ def client
15
+ return @client if defined?(@client) && @client.same_options?(options)
16
+ @client = Cryptoprocessing::Client.new(options)
17
+ end
18
+
19
+ private
20
+
21
+ def respond_to_missing?(method_name, include_private=false)
22
+ client.respond_to?(method_name, include_private)
23
+ end
24
+
25
+ def method_missing(method_name, *args, &block)
26
+ if client.respond_to?(method_name)
27
+ return client.send(method_name, *args, &block)
28
+ end
29
+
30
+ super
31
+ end
32
+ end
33
+ end
34
+
35
+ Cryptoprocessing.setup
36
+
37
+ require 'cryptoprocessing/rails' if defined?(::Rails::Engine)
@@ -0,0 +1,71 @@
1
+ module Cryptoprocessing
2
+ # Event Machine
3
+ class EmHTTPClient < APIClient
4
+ private
5
+
6
+ def http_verb(method, path, body = nil, headers = {})
7
+ if !EventMachine.reactor_running?
8
+ EM.run do
9
+ request(method, path, body) do |resp|
10
+ yield(resp)
11
+ EM.stop
12
+ end
13
+ end
14
+ else
15
+ headers['Content-Type'] = 'application/json'
16
+ headers['User-Agent'] = "cryptoprocessing/ruby-em/#{Cryptoprocessing::VERSION}"
17
+ auth_headers(method, path, body).each do |key, val|
18
+ headers[key] = val
19
+ end
20
+
21
+ ssl_opts = { cert_chain_file: File.expand_path(File.join(File.dirname(__FILE__), 'ca-cryptoprocessing.crt')),
22
+ verify_peer: true }
23
+
24
+ case method
25
+ when 'GET'
26
+ req = EM::HttpRequest.new(@api_uri).get(path: path, head: headers, body: body, ssl: ssl_opts)
27
+ when 'POST'
28
+ req = EM::HttpRequest.new(@api_uri).put(path: path, head: headers, body: body, ssl: ssl_opts)
29
+ when 'POST'
30
+ req = EM::HttpRequest.new(@api_uri).post(path: path, head: headers, body: body, ssl: ssl_opts)
31
+ when 'DELETE'
32
+ req = EM::HttpRequest.new(@api_uri).delete(path: path, head: headers, ssl: ssl_opts)
33
+ else raise
34
+ end
35
+ req.callback do |resp|
36
+ out = EMHTTPResponse.new(resp)
37
+ Cryptoprocessing::check_response_status(out)
38
+ yield(out)
39
+ end
40
+ req.errback do |resp|
41
+ raise APIError, "#{method} #{@api_uri}#{path}: #{resp.error}"
42
+ end
43
+ end
44
+ end
45
+
46
+ # EM-Http response object
47
+ class EMHTTPResponse < APIResponse
48
+ def body
49
+ JSON.parse(@response.response)
50
+ end
51
+
52
+ def data
53
+ body['data']
54
+ end
55
+
56
+ def body=(body)
57
+ @response.response = body.to_json
58
+ end
59
+
60
+ def headers
61
+ out = @response.response_header.map do |key, val|
62
+ [key.upcase.gsub('_', '-'), val]
63
+ end
64
+ out.to_h
65
+ end
66
+
67
+ def status
68
+ @response.response_header.status
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,6 @@
1
+ module Cryptoprocessing
2
+ # Net-HTTP adapter
3
+ class NetHTTPClient < APIClient
4
+
5
+ end
6
+ end
@@ -0,0 +1,67 @@
1
+ require 'cryptoprocessing/models/user'
2
+
3
+ module Cryptoprocessing
4
+
5
+ # Authentication methods for {Cryptoprocessing::Client}
6
+ #
7
+ # Для аутентификации используется токен
8
+ #
9
+ # @see https://api.cryptoprocessing.io/#152a3087-a02e-de76-f156-2015c2ccefef
10
+ module Authentication
11
+ # Indicates if the client was supplied a bearer token
12
+ #
13
+ # @return [Boolean]
14
+ def token_authenticated?
15
+ !!@access_token
16
+ end
17
+
18
+ def login_from_netrc
19
+ return unless netrc?
20
+
21
+ require 'netrc'
22
+ info = Netrc.read netrc_file
23
+ netrc_host = URI.parse(api_endpoint).host
24
+ creds = info[netrc_host]
25
+ if creds.nil?
26
+ # creds will be nil if there is no netrc for this end point
27
+ puts "Error loading credentials from netrc file for #{api_endpoint}"
28
+ else
29
+ creds = creds.to_a
30
+ self.login = creds.shift
31
+ self.password = creds.shift
32
+ end
33
+ rescue LoadError
34
+ puts "Please install netrc gem for .netrc support"
35
+ end
36
+
37
+ # Login user
38
+ #
39
+ # Логин пользователя
40
+ #
41
+ # @see https://api.cryptoprocessing.io/#e88a61dc-bb8f-e9cf-0e56-2729f200be9d
42
+ def login(options)
43
+ out = nil
44
+ post('/auth/login', options) do |resp|
45
+ @access_token = resp.body['auth_token']
46
+ out = Cryptoprocessing::User.new self, resp.data
47
+ yield(resp) if block_given?
48
+ end
49
+ out
50
+ end
51
+
52
+ # Register user
53
+ #
54
+ # Регистрация пользователя
55
+ #
56
+ # @see https://api.cryptoprocessing.io/#b0ec8c86-4c57-de45-5aea-e1cb6483e591
57
+ def register(options)
58
+ out = nil
59
+ post('/auth/register', options) do |resp|
60
+ @access_token = resp.body['auth_token']
61
+ out = Cryptoprocessing::User.new self, resp.data
62
+ yield(resp) if block_given?
63
+ end
64
+ out
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,57 @@
1
+ # Copyright 2018 OOM.AG.
2
+ #
3
+ #
4
+
5
+ module Cryptoprocessing
6
+ module Api
7
+ module Auth
8
+ class TokenStore
9
+ AUTHORIZATION_URI = 'https://accounts.google.com/o/oauth2/auth'
10
+ TOKEN_CREDENTIAL_URI = 'https://accounts.google.com/o/oauth2/token'
11
+
12
+ # @return [Object] Storage object.
13
+ attr_accessor :store
14
+
15
+ ##
16
+ # Initializes the Storage object.
17
+ #
18
+ # @param [Object] store
19
+ # Storage object
20
+ def initialize(store)
21
+ @store = store
22
+ end
23
+
24
+ ##
25
+ # Write the credentials to the specified store.
26
+ #
27
+ def write_credentials
28
+ store.write_credentials(credentials_hash)
29
+ end
30
+
31
+ ##
32
+ # refresh credentials and save them to store
33
+ def refresh_authorization
34
+ self.write_credentials
35
+ end
36
+
37
+ ##
38
+ # Attempt to read in credentials from the specified store.
39
+ def load_credentials
40
+ store.load_credentials
41
+ end
42
+
43
+ ##
44
+ # @return [Hash] with credentials
45
+ def credentials_hash
46
+ {
47
+ :authorization_uri => AUTHORIZATION_URI,
48
+ :token_credential_uri => TOKEN_CREDENTIAL_URI,
49
+ :issued_at => authorization.issued_at.to_i,
50
+ :auth_token => '',
51
+ :user_id => '',
52
+ }
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end