hive_sql 1.0.0.pre.1 → 1.0.0.pre.2

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
  SHA256:
3
- metadata.gz: 46ad6e598c60e582ea5129bbb84c4f29a37fa452f7dc14ba3248b871288d47e5
4
- data.tar.gz: 9e99c26f8421a2aad2ac5f8ca9f8ac63d98e7348a5bfc81aaf92a258473e7cb1
3
+ metadata.gz: bd5bd8d219c1ad22da6b5d6b7abd76a65792d7d14f194990bda7e3e331e2ba76
4
+ data.tar.gz: 6fbcc61ef42e6f19dfcf423597b20bfd1bd656c7d055c1cab2980156a94c7ac5
5
5
  SHA512:
6
- metadata.gz: f9721dfcd1ec4d7d318c2847361d79b7446e7ae6d2053518de5cd47f62d9567bd5968293fccd5e1c642b18f24b8e6401e9eff844620860a6c6c6b567f66d45ec
7
- data.tar.gz: 492c17a5435644d5a1352ac39eb42f4c8e1339fcf8f9440559ed4d62279a98d0c65649e92a422a27b9b1e6826e8c2ddb5c62aaa18160787ec7da753c487581c6
6
+ metadata.gz: f83ac383174d7021b379fe82363342b2430db26e91714cae04402cc6fca90ac05990f705864d1cbef25c0078d193d3084b2ead582e350362173be96dfc8b7473
7
+ data.tar.gz: a2398930b03034f4702ade35af0961c10ff776d04f03eb61a8640e7ca64869001c52f8fddf8f64abe60f23ca5e4f3840e6afb878d6911dcd29e99bbc99943b09
@@ -0,0 +1,97 @@
1
+ # Hive SQL
2
+
3
+ Access [HiveSQL.io](https://hivesql.io) data from your ruby/rails application.
4
+
5
+ [![Gem Version](https://badge.fury.io/rb/hive_sql.svg)](https://badge.fury.io/rb/hive_sql)
6
+
7
+ ### How to Subscribe
8
+
9
+ **Note:** HiveSQL is a monthly subscription. To use this gem, you must subscribe to @hivesql and store the credentials as environment variables.
10
+
11
+ See: https://hivesql.io
12
+
13
+ ### Installation
14
+
15
+ First, install ruby. One way to do this is install [rvm](https://rvm.io/install). Once ruby is installed, install `hive_sql` with the `gem` command:
16
+
17
+ ```bash
18
+ gem install hive_sql
19
+ ```
20
+
21
+ Or, add it to your `Gemfile`:
22
+
23
+ ```ruby
24
+ gem 'hive_sql'
25
+ ```
26
+
27
+ ### How To Use (Standalone)
28
+
29
+ ```bash
30
+ gem install hive_sql
31
+ export HIVESQL_HOST=<your hivesql host>
32
+ export HIVESQL_USERNAME=<your hivesql username>
33
+ export HIVESQL_PASSWORD=<your hivesql password>
34
+ hive_sql top upvoted
35
+ ```
36
+
37
+ The above example will query the top upvoted content for the last 7 days.
38
+
39
+ ### Models
40
+ - Account
41
+ - Block
42
+ - Transaction
43
+ - *various operations*
44
+ - Comment
45
+ - Community
46
+ - Role
47
+ - Subscriber
48
+ - Follower
49
+ - Reblog
50
+ - Tag
51
+ - Token
52
+ - Witness
53
+
54
+ ### Followers
55
+
56
+ How to query today's followers:
57
+
58
+ ```ruby
59
+ followers = HiveSQL::Tx::Custom::Follow
60
+ followers.following(:alice).today.count
61
+ ```
62
+
63
+ ### Reblog
64
+
65
+ How to query today's reblogs:
66
+
67
+ ```ruby
68
+ reblogs = HiveSQL::Tx::Custom::Reblog
69
+ reblogs.author(:alice).today.count
70
+ ```
71
+
72
+ ### Account Witness Proxy
73
+
74
+ How to query current accounts that are actively using a proxy:
75
+
76
+ ```ruby
77
+ proxied = HiveSQL::Tx::AccountWitnessProxy.active('alice')
78
+ proxied.pluck(:account)
79
+ ```
80
+
81
+ ### Applications
82
+
83
+ How to query comments by application:
84
+
85
+ ```ruby
86
+ comments = HiveSQL::Comment.app('esteem').where(author: 'good-karma')
87
+ ```
88
+
89
+ ## Get in touch!
90
+
91
+ If you're using HiveSQL with ruby, I'd love to hear from you. Drop me a line and tell me what you think! I'm @inertia on Hive.
92
+
93
+ Please note that this gem just provides access to the HiveSQL data services are provided by @arcange.
94
+
95
+ ## License
96
+
97
+ 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 CHANGED
@@ -454,7 +454,10 @@ task :proxied, [:days_ago] do |t, args|
454
454
  ap proxied.count(:all)
455
455
  end
456
456
 
457
- desc 'Claimed Rewards'
457
+ desc <<~EOF
458
+ Claimed Rewards.
459
+ Use the "account_name" of a user or '%' to match on any user.
460
+ EOF
458
461
  task :claimed, [:account_name, :days_ago, :symbol] do |t, args|
459
462
  now = Time.now.utc
460
463
  account_name = args[:account_name] || '%'
@@ -473,7 +476,7 @@ task :claimed, [:account_name, :days_ago, :symbol] do |t, args|
473
476
  when :mvests then claims.where("reward_vests > 0")
474
477
  when :hive then claims.where("reward_steem > 0")
475
478
  when :hbd then claims.where("reward_sbd > 0")
476
- else; raise "Unknown symbol: #{symbol}"
479
+ else; raise "Unknown symbol: #{symbol.to_s.upcase} (allowed: VESTS, MVESTS, HIVE, HBD)"
477
480
  end
478
481
 
479
482
  claims = claims.group("FORMAT(timestamp, 'yyyy-MM')")
@@ -492,6 +495,10 @@ task :claimed, [:account_name, :days_ago, :symbol] do |t, args|
492
495
  puts "# Total claimed #{symbol}: #{claims.values.sum}"
493
496
  end
494
497
 
498
+ desc <<~EOF
499
+ Balance for given parties.
500
+ Where "party_a" is the first account, "party_b" is the second account and "symbol" is a valid native symbol.
501
+ EOF
495
502
  task :balance, [:party_a, :party_b, :symbol] do |t, args|
496
503
  party_a = args[:party_a]
497
504
  party_b = args[:party_b]
@@ -504,6 +511,40 @@ task :balance, [:party_a, :party_b, :symbol] do |t, args|
504
511
  puts "#{party_b}: %.3f #{symbol}, difference: %.3f #{symbol}" % [balance_b, (balance_b - balance_a)]
505
512
  end
506
513
 
514
+ desc <<~EOF
515
+ Top what ...
516
+ Allowed \"what\" options: upvoted downvoted
517
+ EOF
518
+ task :top, [:what, :limit] do |t, args|
519
+ what = args[:what].to_s.downcase.to_sym
520
+ limit = (args[:limit] || '10').to_i
521
+ since = 1.week.ago
522
+
523
+ case what
524
+ when :upvoted, :downvoted
525
+ comments = HiveSQL::Comment.after(since)
526
+ comments = if what == :upvoted
527
+ comments.where('net_rshares > 0')
528
+ comments = comments.order('sum_net_rshares DESC')
529
+ elsif what == :downvoted
530
+ comments.where('net_rshares < 0')
531
+ comments = comments.order('sum_net_rshares ASC')
532
+ end
533
+
534
+ comments = comments.group(:author, :permlink, :created)
535
+ comments = comments.limit(limit)
536
+
537
+ comments = comments.sum(:net_rshares)
538
+
539
+ comments.each do |k, v|
540
+ url = "https://hive.blog/@#{k[0]}/#{k[1]}"
541
+ created = (Time.now - k[2]) / 60 / 60 / 24
542
+
543
+ puts "#{v}; #{created.round(2)} days ago: #{url}"
544
+ end
545
+ end
546
+ end
547
+
507
548
  # Doesn't look like this table exists.
508
549
  # desc 'List conversion HBD conversion request sums grouped by day.'
509
550
  # task :convert, [:days_ago] do |t, args|
@@ -1,23 +1,78 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require 'rake'
4
+ require 'pp'
3
5
  require 'hive_sql'
4
6
 
5
- puts '#'*40
6
- puts '#'*40
7
- puts "Welcome to HiveSQL Version: #{HiveSQL::VERSION}"
8
- puts '#'*40
9
- puts '#'*40
10
- puts ''
7
+ gem_dir = File.expand_path("..", File.dirname(__FILE__))
8
+ $LOAD_PATH.unshift gem_dir
9
+
10
+ pwd = Dir.pwd
11
+ Dir.chdir(gem_dir)
12
+ Rake::TaskManager.record_task_metadata = true
13
+ Rake.application.init
14
+ Rake.application.load_rakefile
15
+ Dir.chdir(pwd)
16
+
17
+ EXCLUDED_TASKS = %w(build clean clobber default install install:local push
18
+ release release:guard_clean release:rubygem_push release:source_control_push
19
+ test)
20
+
21
+ def version
22
+ puts "HiveSQL Version: #{HiveSQL::VERSION}\n\n"
23
+ end
24
+
25
+ def help(task_name = ARGV[1])
26
+ if !!task_name && task_name != 'help'
27
+ task = Rake::Task[task_name]
28
+
29
+ help_text = if !!task.full_comment
30
+ task.full_comment.split("\n").map{|c| "\n #{c}"}.join("\n") + "\n\n"
31
+ else
32
+ "\n"
33
+ end
34
+
35
+ help_text += " hive_sql #{task.name} #{task.arg_names.map{|a| "[#{a}]"}.join(' ')}"
36
+
37
+ STDOUT.puts <<~EOF
38
+ Usage:
39
+ #{help_text}
40
+ EOF
41
+ else
42
+ tasks = Rake::Task.tasks.map do |task|
43
+ next if EXCLUDED_TASKS.include? task.name
44
+
45
+ help_text = if !!task.comment
46
+ "\n > #{task.comment}\n"
47
+ else
48
+ "\n"
49
+ end
50
+
51
+ help_text += " hive_sql #{task.name} #{task.arg_names.map{|a| "[#{a}]"}.join(' ')}"
52
+ end.compact
53
+
54
+ STDOUT.puts <<~EOF
55
+ Please provide command name
56
+
57
+ Usage:
58
+ #{tasks.join("\n")}
59
+
60
+ hive_sql help [command]
61
+
62
+ hive_sql version
63
+ EOF
64
+ end
65
+ end
11
66
 
12
67
  case ARGV[0]
13
- when 'todo'
14
- puts 'todo'
68
+ when 'version' then version
69
+ when 'help' then help
15
70
  else
16
- STDOUT.puts <<~EOF
17
- Please provide command name
18
-
19
- Usage:
20
- hive_sql todo
21
- hive_sql help
22
- EOF
71
+ begin
72
+ Rake::Task[ARGV[0]].invoke(*ARGV[1..-1])
73
+ rescue => e
74
+ puts e
75
+
76
+ help ARGV[0]
77
+ end
23
78
  end
@@ -1,3 +1,3 @@
1
1
  module HiveSQL
2
- VERSION = '1.0.0-1'
2
+ VERSION = '1.0.0-2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hive_sql
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre.1
4
+ version: 1.0.0.pre.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anthony Martin (inertia)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-21 00:00:00.000000000 Z
11
+ date: 2020-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -323,6 +323,7 @@ files:
323
323
  - ".gitignore"
324
324
  - Gemfile
325
325
  - LICENSE
326
+ - README.md
326
327
  - Rakefile
327
328
  - bin/hive_sql
328
329
  - hive_sql.gemspec