stellar_ruby_explorer 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0a6e1086fc8860b75f67b5c48f5fab8a71f31b978784e4241984ac4b24597f02
4
+ data.tar.gz: 171cbb804869cfa082a03ebf688fdf5f6c6c78afa59f5551411ec5b372a6a65e
5
+ SHA512:
6
+ metadata.gz: 98f3bd31d29894cd421410cec77e823d8467d98e742f7b2a905dd756e7d45b4c24be97380056f8a1fbbdf24288fe021c9c656f4dc2f45f94edd8b75164c2b3e4
7
+ data.tar.gz: 62671f70f2538497dd36721a5ebe6df9b89efda38a7e54e5e367ad630c9359220c99c93ffd6197134279fe2d315d1f9a5116f4d8e6fb1bb0c1fa463045021a1f
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.0
7
+ before_install: gem install bundler -v 2.0.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in stellar_ruby_explorer.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,41 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ stellar_ruby_explorer (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ coderay (1.1.2)
10
+ diff-lcs (1.3)
11
+ method_source (0.9.2)
12
+ pry (0.12.2)
13
+ coderay (~> 1.1.0)
14
+ method_source (~> 0.9.0)
15
+ rake (10.5.0)
16
+ rspec (3.8.0)
17
+ rspec-core (~> 3.8.0)
18
+ rspec-expectations (~> 3.8.0)
19
+ rspec-mocks (~> 3.8.0)
20
+ rspec-core (3.8.0)
21
+ rspec-support (~> 3.8.0)
22
+ rspec-expectations (3.8.2)
23
+ diff-lcs (>= 1.2.0, < 2.0)
24
+ rspec-support (~> 3.8.0)
25
+ rspec-mocks (3.8.0)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.8.0)
28
+ rspec-support (3.8.0)
29
+
30
+ PLATFORMS
31
+ ruby
32
+
33
+ DEPENDENCIES
34
+ bundler (~> 2.0.1)
35
+ pry (~> 0.12.2)
36
+ rake (~> 10.0)
37
+ rspec (~> 3.0)
38
+ stellar_ruby_explorer!
39
+
40
+ BUNDLED WITH
41
+ 2.0.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Rodrigo Alves Vieira
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/README.md ADDED
@@ -0,0 +1,68 @@
1
+ # Stellar Ruby Explorer
2
+ Ruby wrapper for the [Stellar] Horizon [blockchain query API service]. Enables queries by address and transactions.
3
+
4
+ ## INSTALLATION
5
+
6
+ Add this line to your application's Gemfile:
7
+
8
+ ```ruby
9
+ gem 'stellar_ruby_explorer'
10
+ ```
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install stellar_ruby_explorer
19
+
20
+ ## USAGE
21
+ Here's how to perform queries by block, address and transactions.
22
+
23
+ ```ruby
24
+ explorer = StellarRubyExplorer::Api.new
25
+
26
+ # Get all transactions involving a given address
27
+ explorer.address_full_txs 'GDQCM5PLJYM37JJBP3ZHZ4H25I7EUK4SF36CEPVC4MLCYGEXPO5FV5C5'
28
+
29
+ # Get information about a specific transaction
30
+ explorer.tx_info '71c4b26b47a3fcd566a4b784a9130ff87ca4fc0bbb280ac8d43002d5a39e5526'
31
+ ```
32
+
33
+ ## DEVELOPMENT
34
+
35
+ 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.
36
+
37
+ 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].
38
+
39
+ ### CODE QUALITY
40
+
41
+ I prefer good code whenever possible, just like you. The [rubocop] tool is used in this project to ensure the code is well written:
42
+
43
+ ```shell
44
+ $ rubocop lib/
45
+ ```
46
+
47
+ ### CONTRIBUTING
48
+
49
+ Bug reports and pull requests are welcome on GitHub at https://github.com/rodrigoalvesvieira/stellar_ruby_explorer.
50
+
51
+ ## AUTHORS
52
+
53
+ * Rodrigo Alves Vieira <rodrigo@bitja.com.br>
54
+
55
+ This project is based on BlockCypher's [ruby client] and Stellar's [Horizon project].
56
+
57
+ ## LICENSE
58
+
59
+ The gem is available as open source under the terms of the [MIT License].
60
+
61
+ [Stellar]: https://www.stellar.org/
62
+ [blockchain query API service]: https://www.stellar.org/developers/reference/
63
+ [BitJá]: https://www.bitja.com.br/
64
+ [rubygems.org]: https://rubygems.org
65
+ [rubocop]: https://github.com/rubocop-hq/rubocop
66
+ [ruby client]: https://github.com/blockcypher/ruby-client
67
+ [MIT License]: https://opensource.org/licenses/MIT
68
+ [Horizon project]: https://github.com/stellar/horizon
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "stellar_ruby_explorer"
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,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require 'uri'
5
+ require 'net/http'
6
+
7
+ require 'stellar_ruby_explorer/version'
8
+ require 'stellar_ruby_explorer/api'
9
+
10
+ module StellarRubyExplorer
11
+ class Error < StandardError; end
12
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ module StellarRubyExplorer
4
+ # Main class of this library, contains the following public methods:
5
+ # address_full_txs and tx_info
6
+ class Api
7
+ def address_full_txs(address)
8
+ query = { limit: 20, order: 'desc' }
9
+ api_http_get("accounts/#{address}/transactions", query)
10
+ end
11
+
12
+ def tx_info(hash)
13
+ api_http_get("transactions/#{hash}")
14
+ end
15
+
16
+ private
17
+
18
+ def api_http_call(http_method, api_path, query, json_payload: nil)
19
+ uri = endpoint_uri(api_path, query)
20
+
21
+ # Build the connection
22
+ http = Net::HTTP.new(uri.host, uri.port)
23
+ http.use_ssl = true
24
+
25
+ # Build the Request
26
+ if http_method == :post
27
+ request = Net::HTTP::Post.new(uri.request_uri)
28
+ elsif http_method == :get
29
+ request = Net::HTTP::Get.new(uri.request_uri)
30
+ elsif http_method == :delete
31
+ request = Net::HTTP::Delete.new(uri.request_uri)
32
+ else
33
+ raise 'Invalid HTTP method'
34
+ end
35
+
36
+ unless json_payload.nil?
37
+ request.content_type = 'application/json'
38
+ request.body = json_payload.to_json
39
+ end
40
+
41
+ response = http.request(request)
42
+ response_code = response.code.to_i
43
+
44
+ # Detect errors/return 204 empty body
45
+ if response_code >= 400
46
+ raise Error.new(uri.to_s + ' Response:' + response.body)
47
+ elsif response_code == 204
48
+ return nil
49
+ end
50
+
51
+ # Process the response
52
+ begin
53
+ json_response = JSON.parse(response.body)
54
+ return json_response
55
+ rescue => e
56
+ raise "Unable to parse JSON response #{e.inspect}, #{response.body}"
57
+ end
58
+ end
59
+
60
+ def api_http_get(api_path, query = {})
61
+ api_http_call(:get, api_path, query)
62
+ end
63
+
64
+ def endpoint_uri(api_path, query)
65
+ uri = URI("https://horizon.stellar.org/#{api_path}")
66
+ uri.query = URI.encode_www_form(query) unless query.empty?
67
+ uri
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module StellarRubyExplorer
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,40 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "stellar_ruby_explorer/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "stellar_ruby_explorer"
7
+ spec.version = StellarRubyExplorer::VERSION
8
+ spec.authors = ["Rodrigo Alves Vieira"]
9
+ spec.email = ["rodrigoalvesvieira@protonmail.com", "rodrigo@bitja.com.br"]
10
+
11
+ spec.summary = %q{Ruby wrapper for the Stellar Horizon blockchain query API service}
12
+ spec.description = %q{Ruby wrapper for the Stellar Horizon blockchain query API service. Enables queries by address and transactions.}
13
+ spec.homepage = "https://github.com/rodrigoalvesvieira/stellar_ruby_explorer"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
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["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = "https://github.com/rodrigoalvesvieira/stellar_ruby_explorer"
21
+ spec.metadata["changelog_uri"] = "https://github.com/rodrigoalvesvieira/stellar_ruby_explorer"
22
+ else
23
+ raise "RubyGems 2.0 or newer is required to protect against " \
24
+ "public gem pushes."
25
+ end
26
+
27
+ # Specify which files should be added to the gem when it is released.
28
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
29
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
30
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
31
+ end
32
+ spec.bindir = "exe"
33
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
34
+ spec.require_paths = ["lib"]
35
+
36
+ spec.add_development_dependency "bundler", "~> 2.0.1"
37
+ spec.add_development_dependency "rake", "~> 10.0"
38
+ spec.add_development_dependency "rspec", "~> 3.0"
39
+ spec.add_development_dependency 'pry', '~> 0.12.2'
40
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stellar_ruby_explorer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Rodrigo Alves Vieira
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-01-30 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: 2.0.1
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.0.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.12.2
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.12.2
69
+ description: Ruby wrapper for the Stellar Horizon blockchain query API service. Enables
70
+ queries by address and transactions.
71
+ email:
72
+ - rodrigoalvesvieira@protonmail.com
73
+ - rodrigo@bitja.com.br
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - ".travis.yml"
81
+ - Gemfile
82
+ - Gemfile.lock
83
+ - LICENSE.txt
84
+ - README.md
85
+ - Rakefile
86
+ - bin/console
87
+ - bin/setup
88
+ - lib/stellar_ruby_explorer.rb
89
+ - lib/stellar_ruby_explorer/api.rb
90
+ - lib/stellar_ruby_explorer/version.rb
91
+ - stellar_ruby_explorer.gemspec
92
+ homepage: https://github.com/rodrigoalvesvieira/stellar_ruby_explorer
93
+ licenses:
94
+ - MIT
95
+ metadata:
96
+ homepage_uri: https://github.com/rodrigoalvesvieira/stellar_ruby_explorer
97
+ source_code_uri: https://github.com/rodrigoalvesvieira/stellar_ruby_explorer
98
+ changelog_uri: https://github.com/rodrigoalvesvieira/stellar_ruby_explorer
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubygems_version: 3.0.2
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Ruby wrapper for the Stellar Horizon blockchain query API service
118
+ test_files: []