mobiusrb 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 44a9c196382ab4dc0ea8efd125ec1de4a290de44
4
+ data.tar.gz: '099ec43a8b4131b519867c74b06b18fd58a6a4f7'
5
+ SHA512:
6
+ metadata.gz: a2999fe676508ecf3563582fedbb7de9c0c92888e3b070adaacdafe5898cf88864d157f47693c44f3ae25c6b143622dd5b62412541d0d5368c630e7226e32346
7
+ data.tar.gz: 4d149292c8c4dfbca0c56d031fb766beb30d837e4cebbde6427b8c1ada6cf8d5ed922c9197a0a9142e61ecda6f6fe2c377bfdf3ce4c79dfe6ab6669735e01607
@@ -0,0 +1,52 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ # Gemfile.lock
46
+ # .ruby-version
47
+ # .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
51
+
52
+ test.rb
@@ -0,0 +1,21 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'test.rb'
4
+ TargetRubyVersion: 2.2
5
+
6
+ Metrics/AbcSize:
7
+ Enabled: false
8
+
9
+ Metrics/CyclomaticComplexity:
10
+ Max: 8
11
+
12
+ Metrics/MethodLength:
13
+ CountComments: false
14
+ Max: 30
15
+
16
+ Style/Documentation:
17
+ Enabled: false
18
+
19
+ # TODO: Switch on
20
+ Style/IfUnlessModifier:
21
+ Enabled: false
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'http'
6
+
7
+ group :test do
8
+ gem 'rubocop'
9
+ end
@@ -0,0 +1,45 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ addressable (2.5.2)
5
+ public_suffix (>= 2.0.2, < 4.0)
6
+ ast (2.3.0)
7
+ domain_name (0.5.20170404)
8
+ unf (>= 0.0.5, < 1.0.0)
9
+ http (3.0.0)
10
+ addressable (~> 2.3)
11
+ http-cookie (~> 1.0)
12
+ http-form_data (>= 2.0.0.pre.pre2, < 3)
13
+ http_parser.rb (~> 0.6.0)
14
+ http-cookie (1.0.3)
15
+ domain_name (~> 0.5)
16
+ http-form_data (2.0.0)
17
+ http_parser.rb (0.6.0)
18
+ parallel (1.12.1)
19
+ parser (2.4.0.2)
20
+ ast (~> 2.3)
21
+ powerpack (0.1.1)
22
+ public_suffix (3.0.1)
23
+ rainbow (3.0.0)
24
+ rubocop (0.52.0)
25
+ parallel (~> 1.10)
26
+ parser (>= 2.4.0.2, < 3.0)
27
+ powerpack (~> 0.1)
28
+ rainbow (>= 2.2.2, < 4.0)
29
+ ruby-progressbar (~> 1.7)
30
+ unicode-display_width (~> 1.0, >= 1.0.1)
31
+ ruby-progressbar (1.9.0)
32
+ unf (0.1.4)
33
+ unf_ext
34
+ unf_ext (0.0.7.4)
35
+ unicode-display_width (1.3.0)
36
+
37
+ PLATFORMS
38
+ ruby
39
+
40
+ DEPENDENCIES
41
+ http
42
+ rubocop
43
+
44
+ BUNDLED WITH
45
+ 1.16.0
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 mobius-network
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 all
13
+ 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 THE
21
+ SOFTWARE.
@@ -0,0 +1,73 @@
1
+ # Mobius Ruby API Client
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/mobiusrb.svg)](https://rubygems.org/gems/mobiusrb)
4
+ [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/mobius-network/mobius-ruby/blob/master/LICENSE)
5
+
6
+ The Mobius Ruby Client provides simple access to the Mobius API for applications written on Ruby
7
+
8
+ ## Installation
9
+
10
+ Install it yourself as:
11
+ ```
12
+ $ gem install mobiusrb
13
+ ```
14
+
15
+ Or add this line to your application's Gemfile:
16
+ ```
17
+ gem 'mobiusrb'
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ For importing library use:
23
+ ```ruby
24
+ require 'mobiusrb'
25
+ ```
26
+
27
+ The library need to be configured with your API secret key which you can create in [Mobius DApp Store](https://mobius.network/store/developer)
28
+ ```ruby
29
+ mobius = Mobius.new(api_key: 'your_api_key')
30
+ ```
31
+
32
+ ### Examples
33
+
34
+ Every method returns a chainable promise which can be used like this:
35
+
36
+ ```ruby
37
+ data = mobius.app_store.balance(app_uid: 'f9e5e943', email: 'mail@example.com')
38
+
39
+ if data['num_credits'] > 0
40
+ mobius.app_store.use(app_uid: 'f9e5e943', email: 'mail@example.com', num_credits: 1)
41
+ end
42
+ ```
43
+
44
+ ## Methods
45
+
46
+ - ##### `mobius.app_store.balance(app_uid:, email:)`
47
+ Get balance of credits for email.
48
+
49
+ - ##### `mobius.app_store.use(app_uid:, email:, num_credits:)`
50
+ Use numCredits from user with email.
51
+
52
+ - ##### `mobius.tokens.register(token_type:, name:, symbol:, address:)`
53
+ Register a token.
54
+
55
+ - ##### `mobius.tokens.balance(token_uid:, address:)`
56
+ Query the number of tokens specified by the token.
57
+
58
+ - ##### `mobius.tokens.create_address(token_uid:, managed:)`
59
+ Create an address for the token.
60
+
61
+ - ##### `mobius.tokens.register_address(token_uid:, address:)`
62
+ Register an address for the token.
63
+
64
+ - ##### `mobius.tokens.transfer_managed(token_address_uid:, address_to:, num_tokens:)`
65
+ Transfer tokens from a Mobius managed address to a specified address.
66
+
67
+ - ##### `mobius.tokens.transfer_info(token_address_transfer_uid:)`
68
+ Get the status and transaction hash of a Mobius managed token transfer.
69
+
70
+
71
+ ## More information
72
+
73
+ See the [REST API docs](https://mobius.network/docs/)
@@ -0,0 +1,18 @@
1
+ class Resource
2
+ def initialize(requestor, resource)
3
+ @requestor = requestor
4
+ @resource = resource
5
+ end
6
+
7
+ def get(action, payload)
8
+ @requestor.get(@resource, action, payload)
9
+ end
10
+
11
+ def post(action, payload)
12
+ @requestor.post(@resource, action, payload)
13
+ end
14
+
15
+ def post_json(action, payload)
16
+ @requestor.post_json(@resource, action, payload)
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ require './lib/requestor'
2
+ require './lib/resources/app_store'
3
+ require './lib/resources/tokens'
4
+ require './lib/resources/data_marketplace'
5
+
6
+ class Mobius
7
+ attr_reader :app_store, :tokens, :data_marketplace
8
+
9
+ def initialize(api_key:, host: nil, version: nil, auth: nil)
10
+ requestor = Requestor.new(
11
+ api_key: api_key, host: host, version: version, auth: auth
12
+ )
13
+
14
+ @app_store = AppStore.new(requestor)
15
+ @tokens = Tokens.new(requestor)
16
+ @data_marketplace = DataMarketplace.new(requestor)
17
+ end
18
+ end
@@ -0,0 +1,64 @@
1
+ require 'http'
2
+
3
+ class ApiError < StandardError
4
+ end
5
+
6
+ class Requestor
7
+ def initialize(api_key:, host: nil, version: nil, auth: nil)
8
+ @api_key = api_key
9
+ @host = host || 'https://mobius.network/api'
10
+ @version = version || 'v1'
11
+ @auth = auth
12
+ end
13
+
14
+ def get(resource, action, payload)
15
+ request('GET', resource, action, payload)
16
+ end
17
+
18
+ def post(resource, action, payload)
19
+ request('POST', resource, action, payload)
20
+ end
21
+
22
+ def post_json(resource, action, payload)
23
+ request('POST_JSON', resource, action, payload)
24
+ end
25
+
26
+ private
27
+
28
+ def request(method, resource, action, payload)
29
+ url = "#{@host}/#{@version}/#{resource}/#{action}"
30
+
31
+ headers = { 'x-api-key': @api_key }
32
+
33
+ if @auth
34
+ headers['Authorization'] = @auth
35
+ end
36
+
37
+ http = HTTP.headers(headers)
38
+
39
+ response =
40
+ case method
41
+ when 'GET'
42
+ http.get(url, params: payload)
43
+ when 'POST'
44
+ http.post(url, form: payload)
45
+ when 'POST_JSON'
46
+ http.post(url, json: payload)
47
+ end
48
+
49
+ if response.code >= 400
50
+ message = ''
51
+
52
+ begin
53
+ error = response.parse
54
+ message = error['error']['message']
55
+ rescue StandardError
56
+ message = 'Something wrong'
57
+ end
58
+
59
+ raise ApiError.new, message
60
+ end
61
+
62
+ response.parse
63
+ end
64
+ end
@@ -0,0 +1,15 @@
1
+ require './lib/abstract/resource'
2
+
3
+ class AppStore < Resource
4
+ def initialize(requestor)
5
+ super(requestor, 'app_store')
6
+ end
7
+
8
+ def balance(app_uid:, email:)
9
+ get('balance', app_uid: app_uid, email: email)
10
+ end
11
+
12
+ def use(app_uid:, email:, num_credits:)
13
+ post('use', app_uid: app_uid, email: email, num_credits: num_credits)
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ require './lib/abstract/resource'
2
+
3
+ class DataMarketplace < Resource
4
+ def initialize(requestor)
5
+ super(requestor, 'data_marketplace')
6
+ end
7
+
8
+ def data_feed(data_feed_uid:)
9
+ get('data_feed', data_feed_uid: data_feed_uid)
10
+ end
11
+
12
+ def create_data_point(data_feed_uid:, values:)
13
+ post_json('data_feed', data_feed_uid: data_feed_uid, values: values)
14
+ end
15
+
16
+ def buy(data_feed_uid:, address:)
17
+ post('buy', data_feed_uid: data_feed_uid, address: address)
18
+ end
19
+ end
@@ -0,0 +1,42 @@
1
+ require './lib/abstract/resource'
2
+
3
+ class Tokens < Resource
4
+ def initialize(requestor)
5
+ super(requestor, 'tokens')
6
+ end
7
+
8
+ def register(token_type:, name:, symbol:, issuer:)
9
+ post(
10
+ 'register',
11
+ token_type: token_type,
12
+ name: name,
13
+ symbol: symbol,
14
+ issuer: issuer
15
+ )
16
+ end
17
+
18
+ def create_address(token_uid:)
19
+ post('create_address', token_uid: token_uid)
20
+ end
21
+
22
+ def register_address(token_uid:, address:)
23
+ post('register_address', token_uid: token_uid, address: address)
24
+ end
25
+
26
+ def balance(token_uid:, address:)
27
+ get('balance', token_uid: token_uid, address: address)
28
+ end
29
+
30
+ def transfer_managed(token_address_uid:, address_to:, num_tokens:)
31
+ post(
32
+ 'transfer/managed',
33
+ token_address_uid: token_address_uid,
34
+ address_to: address_to,
35
+ num_tokens: num_tokens
36
+ )
37
+ end
38
+
39
+ def transfer_info(token_address_transfer_uid:)
40
+ get('transfer/info', token_address_transfer_uid: token_address_transfer_uid)
41
+ end
42
+ end
@@ -0,0 +1,16 @@
1
+ Gem::Specification.new do |gem|
2
+ gem.name = 'mobiusrb'
3
+ gem.version = '0.1.1'
4
+ gem.date = '2017-12-21'
5
+ gem.authors = ['Gleb Pospelov']
6
+ gem.summary = 'Mobius Ruby API Client'
7
+ gem.description = 'Mobius Ruby API Client'
8
+ gem.email = 'support@mobius.network'
9
+ gem.files = `git ls-files`.split("\n")
10
+ gem.homepage = 'https://github.com/mobius-network/mobius-ruby'
11
+ gem.license = 'MIT'
12
+ gem.required_ruby_version = '>= 2.2'
13
+ gem.require_paths = ['lib']
14
+
15
+ gem.add_dependency 'http', '~> 3.0.0'
16
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mobiusrb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Gleb Pospelov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-12-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: http
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 3.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 3.0.0
27
+ description: Mobius Ruby API Client
28
+ email: support@mobius.network
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - ".gitignore"
34
+ - ".rubocop.yml"
35
+ - Gemfile
36
+ - Gemfile.lock
37
+ - LICENSE
38
+ - README.md
39
+ - lib/abstract/resource.rb
40
+ - lib/mobius.rb
41
+ - lib/requestor.rb
42
+ - lib/resources/app_store.rb
43
+ - lib/resources/data_marketplace.rb
44
+ - lib/resources/tokens.rb
45
+ - mobiusrb.gemspec
46
+ homepage: https://github.com/mobius-network/mobius-ruby
47
+ licenses:
48
+ - MIT
49
+ metadata: {}
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '2.2'
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubyforge_project:
66
+ rubygems_version: 2.6.13
67
+ signing_key:
68
+ specification_version: 4
69
+ summary: Mobius Ruby API Client
70
+ test_files: []