steem_data 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +50 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +62 -0
- data/LICENSE +24 -0
- data/README.md +112 -0
- data/Rakefile +39 -0
- data/config/mongoid.yml +143 -0
- data/lib/steem_data.rb +21 -0
- data/lib/steem_data/account.rb +78 -0
- data/lib/steem_data/account_operation.rb +12 -0
- data/lib/steem_data/acts_as_mathematical.rb +9 -0
- data/lib/steem_data/acts_as_operation.rb +25 -0
- data/lib/steem_data/acts_as_temporal.rb +31 -0
- data/lib/steem_data/operation.rb +10 -0
- data/lib/steem_data/post.rb +62 -0
- data/lib/steem_data/price_history.rb +9 -0
- data/lib/steem_data/setting.rb +9 -0
- data/lib/steem_data/stat.rb +9 -0
- data/lib/steem_data/version.rb +3 -0
- data/lib/steem_data/virtual_operation.rb +9 -0
- data/steem_data.gemspec +30 -0
- metadata +23 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 383d3caf1946151a0883aff248e59827fb7eb293
|
4
|
+
data.tar.gz: b113840863bfdca933e48bf93f6e23ace9188c05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d72bf693f2ef41ccd3dad13284c3ab3b8d5f5237372f8868154921db354e780146521f80a11bdfc554708fbd2b3bcd9ccc01913ea235b761646c4fefe3faf81d
|
7
|
+
data.tar.gz: 6212288bd85141aa03fc6ed0307e27019e96d43a781ae36ae149306f6edf404203b962384bfd4821be8889f32f288d692fec8325e9819eb06d267d78ebef3c19
|
data/.gitignore
ADDED
@@ -0,0 +1,50 @@
|
|
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
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
steem_data (0.0.3)
|
5
|
+
mongoid (~> 6.1, >= 6.1.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activemodel (5.1.4)
|
11
|
+
activesupport (= 5.1.4)
|
12
|
+
activesupport (5.1.4)
|
13
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
|
+
i18n (~> 0.7)
|
15
|
+
minitest (~> 5.1)
|
16
|
+
tzinfo (~> 1.1)
|
17
|
+
awesome_print (1.8.0)
|
18
|
+
bson (4.2.2)
|
19
|
+
coderay (1.1.2)
|
20
|
+
concurrent-ruby (1.0.5)
|
21
|
+
docile (1.1.5)
|
22
|
+
i18n (0.8.6)
|
23
|
+
json (2.1.0)
|
24
|
+
method_source (0.9.0)
|
25
|
+
minitest (5.10.3)
|
26
|
+
minitest-line (0.6.4)
|
27
|
+
minitest (~> 5.0)
|
28
|
+
mongo (2.4.3)
|
29
|
+
bson (>= 4.2.1, < 5.0.0)
|
30
|
+
mongoid (6.2.1)
|
31
|
+
activemodel (~> 5.1)
|
32
|
+
mongo (>= 2.4.1, < 3.0.0)
|
33
|
+
pry (0.11.1)
|
34
|
+
coderay (~> 1.1.0)
|
35
|
+
method_source (~> 0.9.0)
|
36
|
+
rake (12.1.0)
|
37
|
+
simplecov (0.15.1)
|
38
|
+
docile (~> 1.1.0)
|
39
|
+
json (>= 1.8, < 3)
|
40
|
+
simplecov-html (~> 0.10.0)
|
41
|
+
simplecov-html (0.10.2)
|
42
|
+
thread_safe (0.3.6)
|
43
|
+
tzinfo (1.2.3)
|
44
|
+
thread_safe (~> 0.1)
|
45
|
+
yard (0.9.9)
|
46
|
+
|
47
|
+
PLATFORMS
|
48
|
+
ruby
|
49
|
+
|
50
|
+
DEPENDENCIES
|
51
|
+
awesome_print (~> 1.8, >= 1.8.0)
|
52
|
+
bundler (~> 1.15, >= 1.15.4)
|
53
|
+
minitest (~> 5.10, >= 5.10.3)
|
54
|
+
minitest-line (~> 0.6, >= 0.6.4)
|
55
|
+
pry (~> 0.11, >= 0.11.1)
|
56
|
+
rake (~> 12.1, >= 12.1.0)
|
57
|
+
simplecov (~> 0.15, >= 0.15.1)
|
58
|
+
steem_data!
|
59
|
+
yard (~> 0.9, >= 0.9.9)
|
60
|
+
|
61
|
+
BUNDLED WITH
|
62
|
+
1.15.4
|
data/LICENSE
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
This is free and unencumbered software released into the public domain.
|
2
|
+
|
3
|
+
Anyone is free to copy, modify, publish, use, compile, sell, or
|
4
|
+
distribute this software, either in source code form or as a compiled
|
5
|
+
binary, for any purpose, commercial or non-commercial, and by any
|
6
|
+
means.
|
7
|
+
|
8
|
+
In jurisdictions that recognize copyright laws, the author or authors
|
9
|
+
of this software dedicate any and all copyright interest in the
|
10
|
+
software to the public domain. We make this dedication for the benefit
|
11
|
+
of the public at large and to the detriment of our heirs and
|
12
|
+
successors. We intend this dedication to be an overt act of
|
13
|
+
relinquishment in perpetuity of all present and future rights to this
|
14
|
+
software under copyright law.
|
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 NONINFRINGEMENT.
|
19
|
+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
20
|
+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
21
|
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
23
|
+
|
24
|
+
For more information, please refer to <http://unlicense.org>
|
data/README.md
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
[steem_data](https://github.com/steem-third-party/steem_data)
|
2
|
+
============
|
3
|
+
|
4
|
+
Wrapper for accessing [steemdata.com](https://steemdata.com/) in a ruby application. It uses MongoID and ActiveModel to leverage all of the tools provided by those libraries.
|
5
|
+
|
6
|
+
<center>
|
7
|
+
[![](https://cl.ly/0l3G3g1V4618/Image%202017-03-02%20at%2010.32.13%20AM.png)](https://github.com/steem-third-party/steem_data)
|
8
|
+
</center>
|
9
|
+
|
10
|
+
> SteemData helps developers and researchers build better STEEM applications. We parse the STEEM blockchain for you, and provide the data as a fast and convenient MongoDB service.
|
11
|
+
|
12
|
+
**Note: This wrapper gem is built by @inertia. SteemData is built by @furion. Any questions about using this gem should be directed to @inertia.**
|
13
|
+
|
14
|
+
### Quick Start
|
15
|
+
|
16
|
+
Add the gem to your Gemfile:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
gem 'steem_data'
|
20
|
+
```
|
21
|
+
|
22
|
+
Then:
|
23
|
+
|
24
|
+
```bash
|
25
|
+
$ bundle install
|
26
|
+
```
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
Look for a specific post using `author` and `permlink`.
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
require 'steem_data'
|
34
|
+
|
35
|
+
SteemData.load
|
36
|
+
|
37
|
+
post = SteemData::Post.find_by(author: 'inertia', permlink: 'macintosh-plus')
|
38
|
+
|
39
|
+
puts post.to_json
|
40
|
+
```
|
41
|
+
|
42
|
+
Which returns:
|
43
|
+
|
44
|
+
```json
|
45
|
+
{
|
46
|
+
"_id":{
|
47
|
+
"$oid":"58992d230fbc46e3066fa9b1"
|
48
|
+
},
|
49
|
+
"abs_rshares":0,
|
50
|
+
"active":"2017-01-24T21:28:27.000Z",
|
51
|
+
"active_votes":[
|
52
|
+
|
53
|
+
],
|
54
|
+
"allow_curation_rewards":true,
|
55
|
+
"allow_replies":true,
|
56
|
+
"allow_votes":true,
|
57
|
+
"author":"inertia",
|
58
|
+
"author_reputation":"66832013171970",
|
59
|
+
"author_rewards":41294,
|
60
|
+
"body": ...
|
61
|
+
}
|
62
|
+
```
|
63
|
+
|
64
|
+
You can find posts with a high number of `active_votes`.
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
post = SteemData::Post.where('active_votes.1700' => {'$exists' => true}).last
|
68
|
+
|
69
|
+
puts "https://steemit.com/#{post.parent_permlink}/@#{post.author}/#{post.permlink}"
|
70
|
+
```
|
71
|
+
|
72
|
+
Which returns:
|
73
|
+
|
74
|
+
```
|
75
|
+
https://steemit.com/votu/@sirlunchthehost/take-the-vote-negation-poll-now-brought-to-you-by-sirlunchthehost-aka-the-saru-pirate-king
|
76
|
+
```
|
77
|
+
|
78
|
+
Or do the same with `net_votes`.
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
post = SteemData::Post.where(:net_votes.gte => 1700).last
|
82
|
+
|
83
|
+
puts "https://steemit.com/#{post.parent_permlink}/@#{post.author}/#{post.permlink}"
|
84
|
+
```
|
85
|
+
|
86
|
+
Which returns:
|
87
|
+
|
88
|
+
```
|
89
|
+
https://steemit.com/votu/@sirlunchthehost/take-the-vote-negation-poll-now-brought-to-you-by-sirlunchthehost-aka-the-saru-pirate-king
|
90
|
+
```
|
91
|
+
|
92
|
+
You can count the number of posts created in the last 24 hours.
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
> SteemData::Post.where(:created.gte => 24.hours.ago.utc).count
|
96
|
+
=> 1366
|
97
|
+
```
|
98
|
+
|
99
|
+
Or do the same for a particular topic.
|
100
|
+
|
101
|
+
```ruby
|
102
|
+
> SteemData::Post.where(parent_permlink: 'life', :created.gte => 24.hours.ago.utc).count
|
103
|
+
=> 86
|
104
|
+
```
|
105
|
+
|
106
|
+
## Get in touch!
|
107
|
+
|
108
|
+
If you're using steem_data, I'd love to hear from you. Drop me a line and tell me what you think! I'm @inertia on STEEM.
|
109
|
+
|
110
|
+
## License
|
111
|
+
|
112
|
+
I don't believe in intellectual "property". If you do, consider Radiator as licensed under a Creative Commons [![CC0](http://i.creativecommons.org/p/zero/1.0/80x15.png)](http://creativecommons.org/publicdomain/zero/1.0/) License.
|
data/Rakefile
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rake/testtask'
|
3
|
+
# require 'yard'
|
4
|
+
|
5
|
+
Rake::TestTask.new(:test) do |t|
|
6
|
+
t.libs << 'test'
|
7
|
+
t.libs << 'lib'
|
8
|
+
t.test_files = FileList['test/**/*_test.rb']
|
9
|
+
t.ruby_opts << if ENV['HELL_ENABLED']
|
10
|
+
'-W2'
|
11
|
+
else
|
12
|
+
'-W1'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# YARD::Rake::YardocTask.new do |t|
|
17
|
+
# t.files = ['lib/**/*.rb']
|
18
|
+
# end
|
19
|
+
|
20
|
+
task default: :test
|
21
|
+
|
22
|
+
task :console do
|
23
|
+
exec "irb -r steem_data -I ./lib"
|
24
|
+
end
|
25
|
+
|
26
|
+
task :build do
|
27
|
+
exec 'gem build steem_data.gemspec'
|
28
|
+
end
|
29
|
+
|
30
|
+
task :push do
|
31
|
+
exec "gem push steem_data-#{SteemData::VERSION}.gem"
|
32
|
+
end
|
33
|
+
|
34
|
+
# We're not going to yank on a regular basis, but this is how it's done if you
|
35
|
+
# really want a task for that for some reason.
|
36
|
+
|
37
|
+
# task :yank do
|
38
|
+
# exec "gem yank steem_data -v #{SteemData::VERSION}"
|
39
|
+
# end
|
data/config/mongoid.yml
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
production:
|
2
|
+
# Configure available database clients. (required)
|
3
|
+
clients:
|
4
|
+
# Defines the default client. (required)
|
5
|
+
default:
|
6
|
+
# Defines the name of the default database that Mongoid can connect to.
|
7
|
+
# (required).
|
8
|
+
database: SteemData
|
9
|
+
# Provides the hosts the default client can connect to. Must be an array
|
10
|
+
# of host:port pairs. (required)
|
11
|
+
hosts:
|
12
|
+
- mongo1.steemdata.com:27017
|
13
|
+
options:
|
14
|
+
# Change the default write concern. (default = { w: 1 })
|
15
|
+
# write:
|
16
|
+
# w: 1
|
17
|
+
|
18
|
+
# Change the default read preference. Valid options for mode are: :secondary,
|
19
|
+
# :secondary_preferred, :primary, :primary_preferred, :nearest
|
20
|
+
# (default: primary)
|
21
|
+
# read:
|
22
|
+
# mode: :secondary_preferred
|
23
|
+
# tag_sets:
|
24
|
+
# - use: web
|
25
|
+
|
26
|
+
# The name of the user for authentication.
|
27
|
+
user: 'steemit'
|
28
|
+
|
29
|
+
# The password of the user for authentication.
|
30
|
+
password: 'steemit'
|
31
|
+
|
32
|
+
# The user's database roles.
|
33
|
+
# roles:
|
34
|
+
# - 'dbOwner'
|
35
|
+
|
36
|
+
# Change the default authentication mechanism. Valid options are: :scram,
|
37
|
+
# :mongodb_cr, :mongodb_x509, and :plain. (default on 3.0 is :scram, default
|
38
|
+
# on 2.4 and 2.6 is :plain)
|
39
|
+
# auth_mech: :scram
|
40
|
+
|
41
|
+
# The database or source to authenticate the user against.
|
42
|
+
# (default: the database specified above or admin)
|
43
|
+
# auth_source: admin
|
44
|
+
|
45
|
+
# Force a the driver cluster to behave in a certain manner instead of auto-
|
46
|
+
# discovering. Can be one of: :direct, :replica_set, :sharded. Set to :direct
|
47
|
+
# when connecting to hidden members of a replica set.
|
48
|
+
# connect: :direct
|
49
|
+
|
50
|
+
# Changes the default time in seconds the server monitors refresh their status
|
51
|
+
# via ismaster commands. (default: 10)
|
52
|
+
# heartbeat_frequency: 10
|
53
|
+
|
54
|
+
# The time in seconds for selecting servers for a near read preference. (default: 5)
|
55
|
+
# local_threshold: 5
|
56
|
+
|
57
|
+
# The timeout in seconds for selecting a server for an operation. (default: 30)
|
58
|
+
# server_selection_timeout: 30
|
59
|
+
|
60
|
+
# The maximum number of connections in the connection pool. (default: 5)
|
61
|
+
# max_pool_size: 5
|
62
|
+
|
63
|
+
# The minimum number of connections in the connection pool. (default: 1)
|
64
|
+
# min_pool_size: 1
|
65
|
+
|
66
|
+
# The time to wait, in seconds, in the connection pool for a connection
|
67
|
+
# to be checked in before timing out. (default: 5)
|
68
|
+
# wait_queue_timeout: 5
|
69
|
+
|
70
|
+
# The time to wait to establish a connection before timing out, in seconds.
|
71
|
+
# (default: 5)
|
72
|
+
# connect_timeout: 5
|
73
|
+
|
74
|
+
# The timeout to wait to execute operations on a socket before raising an error.
|
75
|
+
# (default: 5)
|
76
|
+
# socket_timeout: 5
|
77
|
+
|
78
|
+
# The name of the replica set to connect to. Servers provided as seeds that do
|
79
|
+
# not belong to this replica set will be ignored.
|
80
|
+
# replica_set: name
|
81
|
+
|
82
|
+
# Whether to connect to the servers via ssl. (default: false)
|
83
|
+
# ssl: true
|
84
|
+
|
85
|
+
# The certificate file used to identify the connection against MongoDB.
|
86
|
+
# ssl_cert: /path/to/my.cert
|
87
|
+
|
88
|
+
# The private keyfile used to identify the connection against MongoDB.
|
89
|
+
# Note that even if the key is stored in the same file as the certificate,
|
90
|
+
# both need to be explicitly specified.
|
91
|
+
# ssl_key: /path/to/my.key
|
92
|
+
|
93
|
+
# A passphrase for the private key.
|
94
|
+
# ssl_key_pass_phrase: password
|
95
|
+
|
96
|
+
# Whether or not to do peer certification validation. (default: true)
|
97
|
+
# ssl_verify: true
|
98
|
+
|
99
|
+
# The file containing a set of concatenated certification authority certifications
|
100
|
+
# used to validate certs passed from the other end of the connection.
|
101
|
+
# ssl_ca_cert: /path/to/ca.cert
|
102
|
+
|
103
|
+
|
104
|
+
# Configure Mongoid specific options. (optional)
|
105
|
+
options:
|
106
|
+
# Includes the root model name in json serialization. (default: false)
|
107
|
+
# include_root_in_json: false
|
108
|
+
|
109
|
+
# Include the _type field in serialization. (default: false)
|
110
|
+
# include_type_for_serialization: false
|
111
|
+
|
112
|
+
# Preload all models in development, needed when models use
|
113
|
+
# inheritance. (default: false)
|
114
|
+
# preload_models: false
|
115
|
+
|
116
|
+
# Raise an error when performing a #find and the document is not found.
|
117
|
+
# (default: true)
|
118
|
+
# raise_not_found_error: true
|
119
|
+
|
120
|
+
# Raise an error when defining a scope with the same name as an
|
121
|
+
# existing method. (default: false)
|
122
|
+
# scope_overwrite_exception: false
|
123
|
+
|
124
|
+
# Use Active Support's time zone in conversions. (default: true)
|
125
|
+
# use_activesupport_time_zone: true
|
126
|
+
|
127
|
+
# Ensure all times are UTC in the app side. (default: false)
|
128
|
+
# use_utc: false
|
129
|
+
|
130
|
+
# Set the Mongoid and Ruby driver log levels when not in a Rails
|
131
|
+
# environment. The Mongoid logger will be set to the Rails logger
|
132
|
+
# otherwise.(default: :info)
|
133
|
+
# log_level: :info
|
134
|
+
test:
|
135
|
+
clients:
|
136
|
+
default:
|
137
|
+
database: steemdata_test
|
138
|
+
hosts:
|
139
|
+
- localhost:27017
|
140
|
+
options:
|
141
|
+
read:
|
142
|
+
mode: :primary
|
143
|
+
max_pool_size: 1
|
data/lib/steem_data.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'mongoid'
|
2
|
+
|
3
|
+
module SteemData
|
4
|
+
require 'steem_data/acts_as_mathematical'
|
5
|
+
require 'steem_data/acts_as_operation'
|
6
|
+
require 'steem_data/acts_as_temporal'
|
7
|
+
require 'steem_data/account_operation'
|
8
|
+
require 'steem_data/account'
|
9
|
+
require 'steem_data/operation'
|
10
|
+
require 'steem_data/post'
|
11
|
+
require 'steem_data/price_history'
|
12
|
+
require 'steem_data/setting'
|
13
|
+
require 'steem_data/stat'
|
14
|
+
require 'steem_data/virtual_operation'
|
15
|
+
require 'steem_data/version'
|
16
|
+
extend self
|
17
|
+
|
18
|
+
def load(path = "#{File.dirname(__FILE__)}/../config/mongoid.yml", run_level = :production)
|
19
|
+
Mongoid.load!(path, run_level)
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module SteemData
|
2
|
+
class Account
|
3
|
+
include Mongoid::Document
|
4
|
+
include Mongoid::Attributes::Dynamic
|
5
|
+
include ActsAsMathematical
|
6
|
+
include ActsAsTemporal
|
7
|
+
store_in collection: 'Accounts'
|
8
|
+
|
9
|
+
scope :mined, lambda { |mined = true| where(mined: mined) }
|
10
|
+
scope :search, lambda { |search|
|
11
|
+
case search
|
12
|
+
when Regexp then where(name: search)
|
13
|
+
else; where(name: {'$regex' => ".*#{search.to_s.downcase}.*"})
|
14
|
+
end
|
15
|
+
}
|
16
|
+
|
17
|
+
def following_accounts; Account.where(:name.in => following); end
|
18
|
+
def follower_accounts; Account.where(:name.in => followers); end
|
19
|
+
def posts; Post.where(author: name); end
|
20
|
+
def proxied_accounts; Account.where(:name.in => proxied); end
|
21
|
+
def routed_accounts; Account.where(:name.in => routed); end
|
22
|
+
|
23
|
+
def proxied
|
24
|
+
proxied = []
|
25
|
+
|
26
|
+
# List of accounts that have used this account as a proxy.
|
27
|
+
accounts = AccountOperation.type('account_witness_proxy').where(proxy: name).
|
28
|
+
distinct(:account) - [name]
|
29
|
+
|
30
|
+
# Related operations (either voting for this account or resetting).
|
31
|
+
account_witness_proxies = AccountOperation.type('account_witness_proxy').
|
32
|
+
where(:account.in => accounts, :proxy.in => ['', name]).
|
33
|
+
order_by(timestamp: :asc)
|
34
|
+
|
35
|
+
# Replay the proxy selection related to this account. Note, this
|
36
|
+
# iteration will even work if the full proxy history is replayed, because
|
37
|
+
# we are only looking for "this account" or "not this account" in the
|
38
|
+
# order that those operations appear on the blockchain.
|
39
|
+
account_witness_proxies.each do |b|
|
40
|
+
if b.proxy == name
|
41
|
+
proxied += [b.account]
|
42
|
+
else
|
43
|
+
proxied -= [b.account]
|
44
|
+
end
|
45
|
+
|
46
|
+
proxied = proxied.uniq
|
47
|
+
end
|
48
|
+
|
49
|
+
proxied
|
50
|
+
end
|
51
|
+
|
52
|
+
def routed
|
53
|
+
routed = []
|
54
|
+
|
55
|
+
# List of accounts that have used this account to route withrdrawn vests.
|
56
|
+
accounts = AccountOperation.type('set_withdraw_vesting_route').where(to_account: name).
|
57
|
+
distinct(:account) - [name]
|
58
|
+
|
59
|
+
# Related operations (either setting this account or resetting).
|
60
|
+
routes = AccountOperation.type('set_withdraw_vesting_route').
|
61
|
+
where(:account.in => accounts, to_account: name).
|
62
|
+
order_by(timestamp: :asc)
|
63
|
+
|
64
|
+
# Like proxied, we replay the proxy selection related to this account.
|
65
|
+
routes.each do |b|
|
66
|
+
if b.to_account == name && b.percent > 0
|
67
|
+
routed += [b.account]
|
68
|
+
else
|
69
|
+
routed -= [b.account]
|
70
|
+
end
|
71
|
+
|
72
|
+
routed = routed.uniq
|
73
|
+
end
|
74
|
+
|
75
|
+
routed
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module SteemData
|
2
|
+
class AccountOperation
|
3
|
+
include Mongoid::Document
|
4
|
+
include Mongoid::Attributes::Dynamic
|
5
|
+
include ActsAsOperation
|
6
|
+
include ActsAsMathematical
|
7
|
+
include ActsAsTemporal
|
8
|
+
store_in collection: 'AccountOperations'
|
9
|
+
|
10
|
+
scope :account, lambda { |account| where(account: account) }
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module SteemData
|
2
|
+
module ActsAsOperation
|
3
|
+
def self.included(base)
|
4
|
+
base.scope :type, lambda { |type, invert = false|
|
5
|
+
where((invert ? :type.nin : :type.in) => [type].flatten)
|
6
|
+
}
|
7
|
+
base.scope :block_num, lambda { |block_num| where(block_num: block_num) }
|
8
|
+
base.scope :author, lambda { |author| where(author: author) }
|
9
|
+
|
10
|
+
base.scope :vote, -> { type 'vote' }
|
11
|
+
base.scope :upvote, lambda { |min_vote = 0| vote.where(:weight.gt => min_vote) }
|
12
|
+
base.scope :downvote, lambda { |max_vote = 0| vote.where(:weight.lt => max_vote) }
|
13
|
+
base.scope :unvote, lambda { vote.where(weight: 0) }
|
14
|
+
base.scope :voter, lambda { |voter| vote.where(voter: voter) }
|
15
|
+
|
16
|
+
# base.scope :comment, -> { type 'comment' }
|
17
|
+
base.scope :parent_permlink, lambda { |parent_permlink| where(parent_permlink: parent_permlink) }
|
18
|
+
base.scope :parent_author, lambda { |parent_author| where(parent_author: parent_author) }
|
19
|
+
base.scope :permlink, lambda { |permlink| where(permlink: permlink) }
|
20
|
+
base.scope :tag, lambda { |tag| where('json_metadata.tags' => tag) }
|
21
|
+
|
22
|
+
base.scope :transfer, -> { type 'transfer' }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module SteemData
|
2
|
+
module ActsAsTemporal
|
3
|
+
def self.included(base)
|
4
|
+
base.scope :starting, lambda { |with, field = :timestamp, not_inverted = true|
|
5
|
+
r = where(field.gt => with, field.lt => Time.now.utc)
|
6
|
+
|
7
|
+
not_inverted ? r : where(:_id.nin => r.distinct(:_id))
|
8
|
+
}
|
9
|
+
|
10
|
+
base.scope :ending, lambda { |with, field = :timestamp, not_inverted = true|
|
11
|
+
r = where(field.gt => Time.at(0), field.lt => with)
|
12
|
+
|
13
|
+
not_inverted ? r : where(:_id.nin => r.distinct(:_id))
|
14
|
+
}
|
15
|
+
|
16
|
+
base.scope :betwixt, lambda { |starting, ending, field = :timestamp, not_inverted = true|
|
17
|
+
r = where(field.gt => starting, field.lt => ending)
|
18
|
+
|
19
|
+
not_inverted ? r : where(:_id.nin => r.distinct(:_id))
|
20
|
+
}
|
21
|
+
|
22
|
+
base.scope :today, lambda { |field = :timestamp|
|
23
|
+
starting(1.day.ago.utc, field)
|
24
|
+
}
|
25
|
+
|
26
|
+
base.scope :yesterday, lambda { |field = :timestamp|
|
27
|
+
betwixt(2.days.ago.utc, 1.day.ago.utc, field)
|
28
|
+
}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module SteemData
|
2
|
+
class Post
|
3
|
+
include Mongoid::Document
|
4
|
+
include Mongoid::Attributes::Dynamic
|
5
|
+
include ActsAsMathematical
|
6
|
+
include ActsAsTemporal
|
7
|
+
store_in collection: 'Posts'
|
8
|
+
|
9
|
+
scope :root_posts, -> { where(depth: 0) }
|
10
|
+
scope :comments, -> { where(:depth.ne => 0) }
|
11
|
+
scope :mode, lambda { |mode| where(mode: mode) }
|
12
|
+
scope :first_payout, -> { mode 'first_payout' }
|
13
|
+
scope :second_payout, -> { mode 'second_payout' }
|
14
|
+
scope :pending_payout, lambda { |pending_payout|
|
15
|
+
if pending_payout
|
16
|
+
where(:cashout_time.gt => Time.now.utc)
|
17
|
+
else
|
18
|
+
where(:cashout_time.lt => Time.now.utc)
|
19
|
+
end
|
20
|
+
}
|
21
|
+
scope :archived, -> { mode 'archived '}
|
22
|
+
scope :has_zero_pending_payout, -> { where('pending_payout_value.amount' => 0) }
|
23
|
+
scope :has_non_zero_pending_payout, -> { where('pending_payout_value.amount' => {'$ne' => 0 }) }
|
24
|
+
scope :has_active_votes, -> { where(:"active_votes.0".exists => true) }
|
25
|
+
scope :has_upvotes, lambda { |min_percent = 1| where('active_votes.percent' => {'$gte' => [min_percent, 10000].max}) }
|
26
|
+
scope :has_downvotes, lambda { |max_percent = -1| where('active_votes.percent' => {'$lte' => [max_percent, -1].min}) }
|
27
|
+
scope :has_unvotes, lambda { where('active_votes.percent' => 0) }
|
28
|
+
scope :has_children, -> { where(:children.ne => 0) }
|
29
|
+
scope :permlink, lambda { |permlink| where(permlink: permlink) }
|
30
|
+
scope :tag, lambda { |tag| where('json_metadata.tags' => tag) }
|
31
|
+
scope :payout_declined, -> { where('max_accepted_payout.amount' => 0)}
|
32
|
+
scope :not_payout_declined, -> { where('max_accepted_payout.amount' => {'$ne' => 0}) }
|
33
|
+
scope :author, lambda { |author| where(author: author) }
|
34
|
+
|
35
|
+
scope :by_cashout, -> {
|
36
|
+
order(cashout_time: :desc)
|
37
|
+
}
|
38
|
+
|
39
|
+
def self.find_flag_war
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.voters(options = {})
|
43
|
+
options[:author.in] ||= distinct(:author)
|
44
|
+
options[:permlink.in] ||= distinct(:permlink)
|
45
|
+
options[:voter.in] ||= distinct('active_votes.voter')
|
46
|
+
|
47
|
+
AccountOperation.type('vote').where(options).distinct(:voter)
|
48
|
+
end
|
49
|
+
|
50
|
+
def commented_on?(name, options = {})
|
51
|
+
replies.map do |reply|
|
52
|
+
false if !!options[:min_reputation] && reply['author_reputation'].to_i < options[:min_reputation]
|
53
|
+
|
54
|
+
reply['author'] == name
|
55
|
+
end.uniq.include? true
|
56
|
+
end
|
57
|
+
|
58
|
+
def pending_payout?
|
59
|
+
cashout_time > Time.now.utc
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/steem_data.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'steem_data/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'steem_data'
|
8
|
+
spec.version = SteemData::VERSION
|
9
|
+
spec.authors = ['Anthony Martin']
|
10
|
+
spec.email = ['steemdata@martin-studio.com']
|
11
|
+
|
12
|
+
spec.summary = %q{SteemData Ruby}
|
13
|
+
spec.description = %q{Wrapper for accessing steemdata.com in a ruby application.}
|
14
|
+
spec.homepage = 'https://github.com/steem-third-party/steem_data'
|
15
|
+
spec.license = 'CC0 1.0'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test)/}) }
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.add_development_dependency 'bundler', '~> 1.15', '>= 1.15.4'
|
21
|
+
spec.add_development_dependency 'rake', '~> 12.1', '>= 12.1.0'
|
22
|
+
spec.add_development_dependency 'minitest', '~> 5.10', '>= 5.10.3'
|
23
|
+
spec.add_development_dependency 'minitest-line', '~> 0.6', '>= 0.6.4'
|
24
|
+
spec.add_development_dependency 'simplecov', '~> 0.15', '>= 0.15.1'
|
25
|
+
spec.add_development_dependency 'yard', '~> 0.9', '>= 0.9.9'
|
26
|
+
spec.add_development_dependency 'pry', '~> 0.11', '>= 0.11.1'
|
27
|
+
spec.add_development_dependency 'awesome_print', '~> 1.8', '>= 1.8.0'
|
28
|
+
|
29
|
+
spec.add_dependency 'mongoid', '~> 6.1', '>= 6.1.0'
|
30
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: steem_data
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anthony Martin
|
@@ -196,7 +196,28 @@ email:
|
|
196
196
|
executables: []
|
197
197
|
extensions: []
|
198
198
|
extra_rdoc_files: []
|
199
|
-
files:
|
199
|
+
files:
|
200
|
+
- ".gitignore"
|
201
|
+
- Gemfile
|
202
|
+
- Gemfile.lock
|
203
|
+
- LICENSE
|
204
|
+
- README.md
|
205
|
+
- Rakefile
|
206
|
+
- config/mongoid.yml
|
207
|
+
- lib/steem_data.rb
|
208
|
+
- lib/steem_data/account.rb
|
209
|
+
- lib/steem_data/account_operation.rb
|
210
|
+
- lib/steem_data/acts_as_mathematical.rb
|
211
|
+
- lib/steem_data/acts_as_operation.rb
|
212
|
+
- lib/steem_data/acts_as_temporal.rb
|
213
|
+
- lib/steem_data/operation.rb
|
214
|
+
- lib/steem_data/post.rb
|
215
|
+
- lib/steem_data/price_history.rb
|
216
|
+
- lib/steem_data/setting.rb
|
217
|
+
- lib/steem_data/stat.rb
|
218
|
+
- lib/steem_data/version.rb
|
219
|
+
- lib/steem_data/virtual_operation.rb
|
220
|
+
- steem_data.gemspec
|
200
221
|
homepage: https://github.com/steem-third-party/steem_data
|
201
222
|
licenses:
|
202
223
|
- CC0 1.0
|