mobius-client 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 01c4b81fee09290fed2e1935eabea312c6a18624
4
- data.tar.gz: 6e74efa3ed49a49c1e999729f116a764146f01ab
3
+ metadata.gz: '089ee5fff823168d94b6f2f1cd79dd9b6090e0a2'
4
+ data.tar.gz: 5ac58a65df84e1685a580d08606190ff043ec821
5
5
  SHA512:
6
- metadata.gz: cc4271c42a49e56503aae69b79d160e771031431d29d8680c4504a899540a4f28317d7d6dc5a8ef1680c80764c30559987b93069e71b936fc314761da47519a9
7
- data.tar.gz: ba78a18c7728a53f9df79c689d393638c7dd2460eae24f71f41659e20f5fd03317126d0e2ed4243e3c8163b647aaedb2f70a2166943e7bc4ee9019635711e21d
6
+ metadata.gz: 40edc08773d4849fb6d16a0c1c40311040df841b5e9d639c3960394c687a709294b6ac66bdabe69aea8f8a12ff55a763b32c3c57ef75bfaebe307dab4facd309
7
+ data.tar.gz: 75981e88dfe7a15ab203bc90e712364643ff96091abf35fedb1e249d075f9f844705a2aa37a60d9dc03c8a7fdf2df9769aca0cd9825ad0a5ada62cdc2e1c37bb
data/.rubocop.yml CHANGED
@@ -27,6 +27,9 @@ Metrics/LineLength:
27
27
  Naming/FileName:
28
28
  Exclude:
29
29
  - "*.*"
30
+ - "Rakefile"
31
+ - "Gemfile"
32
+ - examples/auth/Gemfile
30
33
 
31
34
  RSpec/FilePath:
32
35
  Enabled: false
@@ -82,3 +85,4 @@ Style/ClassAndModuleChildren:
82
85
  Metrics/BlockLength:
83
86
  Exclude:
84
87
  - "spec/**/*.*"
88
+ - "*.gemspec"
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
5
  # Specify your gem's dependencies in mobius-client.gemspec
6
6
  gemspec
data/README.md CHANGED
@@ -1,3 +1,4 @@
1
+ [![Gem Version](https://badge.fury.io/rb/mobius-client.svg)](https://badge.fury.io/rb/mobius-client)
1
2
  [![Build Status](https://travis-ci.org/mobius-network/mobius-client-ruby.svg?branch=master)](https://travis-ci.org/mobius-network/mobius-client-ruby)
2
3
  [![Maintainability](https://api.codeclimate.com/v1/badges/a99a88d28ad37a79dbf6/maintainability)](https://codeclimate.com/github/codeclimate/codeclimate/maintainability)
3
4
 
data/Rakefile CHANGED
@@ -3,4 +3,4 @@ require "rspec/core/rake_task"
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
6
+ task default: :spec
@@ -1,5 +1,5 @@
1
1
  source "https://rubygems.org"
2
2
 
3
+ gem "mobius-client", path: "../.."
3
4
  gem "sinatra"
4
5
  gem "slim"
5
- gem "mobius-client", path: "../.."
@@ -1,18 +1,25 @@
1
1
  # Generates challenge transaction on developer's side.
2
2
  class Mobius::Client::Auth::Challenge
3
3
  extend Dry::Initializer
4
+ extend ConstructorShortcut[:call]
4
5
 
5
- # @!method initialize(seed)
6
+ # @!method initialize(seed, expire_in = Mobius::Client.challenge_expires_in)
6
7
  # @param seed [String] Developers private key
8
+ # @param expire_in [Integer] Session expiration time (seconds from now). 0 means "never".
7
9
  # @!scope instance
8
10
  param :seed
11
+ param :expire_in, default: -> { Mobius::Client.challenge_expires_in }
9
12
 
13
+ # @!method call(seed, expire_in = Mobius::Client.challenge_expires_in)
10
14
  # Generates challenge transaction signed by developers private key. Minimum valid time bound is set to current time.
11
15
  # Maximum valid time bound is set to `expire_in` seconds from now.
12
- #
16
+ # @param seed [String] Developers private key
13
17
  # @param expire_in [Integer] Session expiration time (seconds from now). 0 means "never".
14
18
  # @return [String] base64-encoded transaction envelope
15
- def call(expire_in = Mobius::Client.challenge_expires_in)
19
+ # @!scope class
20
+
21
+ # @return [String] base64-encoded transaction envelope
22
+ def call
16
23
  payment = Stellar::Transaction.payment(
17
24
  source_account: keypair,
18
25
  account: Stellar::KeyPair.random,
@@ -27,16 +34,6 @@ class Mobius::Client::Auth::Challenge
27
34
  payment.to_envelope(keypair).to_xdr(:base64)
28
35
  end
29
36
 
30
- class << self
31
- # Shortcut to challenge generation method.
32
- #
33
- # @param seed [String] Developers private key
34
- # @return [String] base64-encoded transaction envelope
35
- def call(*args)
36
- new(*args).call
37
- end
38
- end
39
-
40
37
  private
41
38
 
42
39
  # @return [Stellar::Keypair] Stellar::Keypair object for given seed.
@@ -1,6 +1,7 @@
1
1
  # Signs challenge transaction on user's side.
2
2
  class Mobius::Client::Auth::Sign
3
3
  extend Dry::Initializer
4
+ extend ConstructorShortcut[:call]
4
5
 
5
6
  # @!method initialize(seed, xdr)
6
7
  # @param seed [String] Users private key
@@ -11,6 +12,14 @@ class Mobius::Client::Auth::Sign
11
12
  param :xdr
12
13
  param :address
13
14
 
15
+ # @!method call(seed, xdr, address)
16
+ # Adds signature to given transaction.
17
+ # @param seed [String] Users private key
18
+ # @param xdr [String] Challenge transaction xdr
19
+ # @param address [String] Developers public key
20
+ # @return [String] base64-encoded transaction envelope
21
+ # @!scope class
22
+
14
23
  # Adds signature to given transaction.
15
24
  #
16
25
  # @return [String] base64-encoded transaction envelope
@@ -19,12 +28,6 @@ class Mobius::Client::Auth::Sign
19
28
  envelope.dup.tap { |e| e.signatures << e.tx.sign_decorated(keypair) }.to_xdr(:base64)
20
29
  end
21
30
 
22
- class << self
23
- def call(*args)
24
- new(*args).call
25
- end
26
- end
27
-
28
31
  private
29
32
 
30
33
  # @return [Stellar::Keypair] Stellar::Keypair object for given seed.
@@ -1,8 +1,9 @@
1
1
  # Adds account as cosigner to other account.
2
2
  class Mobius::Client::Blockchain::AddCosigner
3
3
  extend Dry::Initializer
4
+ extend ConstructorShortcut[:call]
4
5
 
5
- # @!method initialize(keypair)
6
+ # @!method initialize(keypair, cosigner, weight)
6
7
  # @param keypair [Stellar::Keypair] Account keypair
7
8
  # @param cosigner_keypair [Stellar::Keypair] Cosigner account keypair
8
9
  # @param weight [Integer] Cosigner weight, default: 1
@@ -11,6 +12,13 @@ class Mobius::Client::Blockchain::AddCosigner
11
12
  param :cosigner_keypair
12
13
  param :weight, default: -> { 1 }
13
14
 
15
+ # @!method call(keypair, cosigner, weight)
16
+ # Executes an operation.
17
+ # @param keypair [Stellar::Keypair] Account keypair
18
+ # @param cosigner_keypair [Stellar::Keypair] Cosigner account keypair
19
+ # @param weight [Integer] Cosigner weight, default: 1
20
+ # @!scope class
21
+
14
22
  # Executes an operation
15
23
  def call
16
24
  client.horizon.transactions._post(
@@ -20,13 +28,6 @@ class Mobius::Client::Blockchain::AddCosigner
20
28
  raise Mobius::Client::Error::AccountMissing
21
29
  end
22
30
 
23
- # Executes an operation
24
- class << self
25
- def call(*args)
26
- new(*args).call
27
- end
28
- end
29
-
30
31
  private
31
32
 
32
33
  # TODO: weight must be params
@@ -1,6 +1,7 @@
1
1
  # Creates unlimited trustline for given asset.
2
2
  class Mobius::Client::Blockchain::CreateTrustline
3
3
  extend Dry::Initializer
4
+ extend ConstructorShortcut[:call]
4
5
 
5
6
  # ruby-stellar-base needs to be fixed, it does not accept unlimited now
6
7
  LIMIT = 922337203685
@@ -14,13 +15,6 @@ class Mobius::Client::Blockchain::CreateTrustline
14
15
  raise Mobius::Client::Error::AccountMissing
15
16
  end
16
17
 
17
- # TODO: DRY
18
- class << self
19
- def call(*args)
20
- new(*args).call
21
- end
22
- end
23
-
24
18
  private
25
19
 
26
20
  def tx
@@ -1,16 +1,11 @@
1
1
  # Calls Stellar FriendBot
2
2
  class Mobius::Client::Blockchain::FriendBot
3
3
  extend Dry::Initializer
4
+ extend ConstructorShortcut[:call]
4
5
 
5
6
  param :keypair
6
7
 
7
8
  def call
8
9
  Mobius::Client.horizon_client.horizon.friendbot._post(addr: keypair.address)
9
10
  end
10
-
11
- class << self
12
- def call(*args)
13
- new(*args).call
14
- end
15
- end
16
11
  end
@@ -1,6 +1,7 @@
1
1
  # Calls Mobius FriendBot for given account.
2
2
  class Mobius::Client::FriendBot
3
3
  extend Dry::Initializer
4
+ extend ConstructorShortcut[:call]
4
5
 
5
6
  param :seed
6
7
  param :amount, default: -> { 1000 }
@@ -11,12 +12,6 @@ class Mobius::Client::FriendBot
11
12
  raise "FriendBot failed to respond: #{response.body}"
12
13
  end
13
14
 
14
- class << self
15
- def call(*args)
16
- new(*args).call
17
- end
18
- end
19
-
20
15
  private
21
16
 
22
17
  def http
@@ -1,5 +1,5 @@
1
1
  module Mobius
2
2
  module Client
3
- VERSION = "0.1.0".freeze
3
+ VERSION = "0.2.0".freeze
4
4
  end
5
5
  end
data/lib/mobius/client.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require "constructor_shortcut"
1
2
  require "dry-initializer"
2
3
  require "stellar-sdk"
3
4
  require "faraday"
@@ -1,4 +1,4 @@
1
- lib = File.expand_path("../lib", __FILE__)
1
+ lib = File.expand_path("lib", __dir__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
  require "mobius/client/version"
4
4
 
@@ -15,11 +15,8 @@ Gem::Specification.new do |spec|
15
15
 
16
16
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
17
  # to allow pushing to a single host or delete this section to allow pushing to any host.
18
- if spec.respond_to?(:metadata)
19
- spec.metadata["allowed_push_host"] = "https://rubygems.org"
20
- else
21
- raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
- end
18
+ spec.respond_to?(:metadata) || raise("RubyGems 2.0 or newer is required to protect against public gem pushes.")
19
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
23
20
 
24
21
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
25
22
  f.match(%r{^(test|spec|features)/})
@@ -42,6 +39,7 @@ Gem::Specification.new do |spec|
42
39
  spec.add_development_dependency "webmock", "~> 3.3"
43
40
  spec.add_development_dependency "yard", "~> 0.9", ">= 0.9.12"
44
41
 
42
+ spec.add_dependency "constructor_shortcut", "~> 0.2.0"
45
43
  spec.add_dependency "dry-initializer", "~> 2.4"
46
44
  spec.add_dependency "faraday", "~> 0.14"
47
45
  spec.add_dependency "faraday_middleware", "~> 0.12", ">= 0.12.2"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mobius-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Viktor Sokolov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-04-17 00:00:00.000000000 Z
11
+ date: 2018-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -216,6 +216,20 @@ dependencies:
216
216
  - - ">="
217
217
  - !ruby/object:Gem::Version
218
218
  version: 0.9.12
219
+ - !ruby/object:Gem::Dependency
220
+ name: constructor_shortcut
221
+ requirement: !ruby/object:Gem::Requirement
222
+ requirements:
223
+ - - "~>"
224
+ - !ruby/object:Gem::Version
225
+ version: 0.2.0
226
+ type: :runtime
227
+ prerelease: false
228
+ version_requirements: !ruby/object:Gem::Requirement
229
+ requirements:
230
+ - - "~>"
231
+ - !ruby/object:Gem::Version
232
+ version: 0.2.0
219
233
  - !ruby/object:Gem::Dependency
220
234
  name: dry-initializer
221
235
  requirement: !ruby/object:Gem::Requirement