utopian_ruby_api 0.0.1 → 0.0.2.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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/utopian_ruby_api.rb +111 -0
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e343c5854a173aa24acb8c012e989911ec128d64e763e4b9a6a538873c59e1db
4
- data.tar.gz: b16f508c7f92873987535d080e9bbd031a1de3f4ffd7d7162ca9cb26631d137c
3
+ metadata.gz: e98b4817758b9a1b950bcf52ba8d514c72ce42c6a3f543d860c20f31ad964f8d
4
+ data.tar.gz: e5ec1ec36e189a5529016947fa7938053b58524f02af99c01feff15dfc4db7a0
5
5
  SHA512:
6
- metadata.gz: c9b370acd00f8b7847fbe31baed3b2b6f38df311f822be8a735d9bde4b95b7bf1158c3a0887cc2470531d62fee653684655f131d89b2a5667601093d399b60b7
7
- data.tar.gz: efa0ca7bb237cb8003a0bfb90f310014c1565116e9274d3a030b36e16ee1fbcbd6df2d7d2ed5b2e0f1bb3bad417e17fcf1bc900b33b117c44d5af691f6065fa2
6
+ metadata.gz: ad46a19a827b626b48133894f66d19d0c7977ebd945fc481b8133fa57b6e7f3d99eb6500970453afeb8eb61fa21abedeca3b882aa90450eafedbfad794e4ac48
7
+ data.tar.gz: a74e8296683628fbe8f2c53c07e17894a434ca50fef45dc0c2cf40c4b68dbcbbdd33d13ba24f62b00978126d3673a381ced93edb8298e9e3e13096efb33e5175
@@ -1,6 +1,8 @@
1
1
  require 'faraday'
2
2
  require 'addressable'
3
3
  require 'json'
4
+ require 'moderator'
5
+ require 'post'
4
6
 
5
7
  module UtopianRuby
6
8
  class UtopianRubyAPI
@@ -104,5 +106,114 @@ module UtopianRuby
104
106
  end
105
107
  get_posts(params)["total"]
106
108
  end
109
+
110
+ def self.j_to_m(m)
111
+ moderator = Moderator.new
112
+ moderator._id = m["_id"]
113
+ moderator.account = m["account"] unless m["account"].nil?
114
+ moderator.referrer = m["referrer"] unless m["referrer"].nil?
115
+ moderator.supermoderator = m["supermoderator"] unless m["supermoderator"].nil?
116
+ moderator.reviewed = m["reviewed"] unless m["reviewed"].nil?
117
+ moderator.banned = m["banned"] unless m["banned"].nil?
118
+ moderator.total_moderated = m["total_moderated"] unless m["total_moderated"].nil?
119
+ moderator.total_paid_rewards = m["total_paid_rewards"] unless m["total_paid_rewards"].nil?
120
+ moderator.total_paid_rewards_steem = m["total_paid_rewards_steem"] unless m["total_paid_rewards_steem"].nil?
121
+ moderator.should_receive_rewards = m["should_receive_rewards"] unless m["should_receive_rewards"].nil?
122
+ moderator.percentage_total_rewards_moderators = m["percentage_total_rewards_moderators"] unless m["percentage_total_rewards_moderators"].nil?
123
+ moderator
124
+ end
125
+
126
+ def self.get_moderators_obj()
127
+ moderators = Set.new
128
+ get_moderators()["results"].each do |m|
129
+ moderators << j_to_m(m)
130
+ end
131
+ moderators
132
+ end
133
+
134
+ def self.get_moderator_obj(user)
135
+ get_moderators()["results"].each do |m|
136
+ if m["account"] == user
137
+ return j_to_m(m)
138
+ end
139
+ end
140
+ return nil
141
+ end
142
+
143
+ def self.j_to_p(p)
144
+ post = Post.new
145
+ post._id = p["_id"] unless p["_id"].nil?
146
+ post.id = p["id"] unless p["id"].nil?
147
+ post.author = p["author"] unless p["author"].nil?
148
+ post.flagged = p["flagged"] unless p["flagged"].nil?
149
+ post.reviewed = p["reviewed"] unless p["reviewed"].nil?
150
+ post.pending = p["pending"] unless p["pending"].nil?
151
+ post.moderator = p["moderator"] unless p["moderator"].nil?
152
+ post.permlink = p["permlink"] unless p["permlink"].nil?
153
+ post.category = p["category"] unless p["category"].nil?
154
+ post.parent_author = p["parent_author"] unless p["parent_author"].nil?
155
+ post.parent_permlink = p["parent_permlink"] unless p["parent_permlink"].nil?
156
+ post.title = p["title"] unless p["title"].nil?
157
+ post.body = p["body"] unless p["body"].nil?
158
+ post.created = p["created"] unless p["created"].nil?
159
+ post.last_update = p[""] unless p["last_update"].nil?
160
+ post.active = p["active"] unless p["active"].nil?
161
+ post.last_payout = p["last_payout"] unless p["last_payout"].nil?
162
+ post.depth = p["depth"] unless p["depth"].nil?
163
+ post.children = p["children"] unless p["children"].nil?
164
+ post.net_rshares = p["net_rshares"] unless p["net_rshares"].nil?
165
+ post.abs_rshares = p["abs_rshares"] unless p["abs_rshares"].nil?
166
+ post.vote_rshares = p["vote_rshares"] unless p["vote_rshares"].nil?
167
+ post.children_abs_rshares = p["children_abs_rshares"] unless p["children_abs_rshares"].nil?
168
+ post.cashout_time = p["cashout_time"] unless p["cashout_time"].nil?
169
+ post.max_cashout_time = p["max_cashout_time"] unless p["max_cashout_time"].nil?
170
+ post.total_vote_weight = p["total_vote_weight"] unless p["total_vote_weight"].nil?
171
+ post.reward_weight = p["reward_weight"] unless p["reward_weight"].nil?
172
+ post.total_payout_value = p["total_payout_value"] unless p["total_payout_value"].nil?
173
+ post.curator_payout_value = p["curator_payout_value"] unless p["curator_payout_value"].nil?
174
+ post.author_rewards = p["author_rewards"] unless p["author_rewards"].nil?
175
+ post.net_votes = p["net_votes"] unless p["net_votes"].nil?
176
+ post.root_comment = p["root_comment"] unless p["root_comment"].nil?
177
+ post.max_accepted_payout = p["max_accepted_payout"] unless p["max_accepted_payout"].nil?
178
+ post.percent_steem_dollars = p["percent_steem_dollars"] unless p["percent_steem_dollars"].nil?
179
+ post.allow_replies = p["allow_replies"] unless p["allow_replies"].nil?
180
+ post.allow_votes = p["allow_votes"] unless p["allow_votes"].nil?
181
+ post.allow_curation_rewards = p["allow_curation_rewards"] unless p["allow_curation_rewards"].nil?
182
+ post.url = p["url"] unless p["url"].nil?
183
+ post.root_title = p["root_title"] unless p["root_title"].nil?
184
+ post.pending_payout_value = p["pending_payout_value"] unless p["pending_payout_value"].nil?
185
+ post.total_pending_payout_value = p["total_pending_payout_value"] unless p["total_pending_payout_value"].nil?
186
+ post.author_reputation = p["author_reputation"] unless p["author_reputation"].nil?
187
+ post.promoted = p["promoted"] unless p["promoted"].nil?
188
+ post.body_length = p["body_length"] unless p["body_length"].nil?
189
+ post.__v = p["__v"] unless p["__v"].nil?
190
+ post.reserved = p["reserved"] unless p["reserved"].nil?
191
+ post.json_metadata = p["json_metadata"] unless p["json_metadata"].nil?
192
+ post.replies = p["replies"] unless p["replies"].nil?
193
+ post.reblogged_by = p["reblogged_by"] unless p["reblogged_by"].nil?
194
+ post.beneficiaries = p["beneficiaries"] unless p["beneficiaries"].nil?
195
+ post.active_votes = p["active_votes"] unless p["active_votes"].nil?
196
+ post
197
+ end
198
+
199
+ def self.get_posts_obj(params=nil)
200
+ if params.nil?
201
+ params = {}
202
+ end
203
+
204
+ posts = Set.new
205
+ get_posts(params)["results"].each do |p|
206
+ posts << j_to_p(p)
207
+ end
208
+ posts
209
+ end
210
+
211
+ def self.get_post_obj(author,permlink)
212
+ j = JSON.parse(get_request('/api/posts/'+author+'/'+permlink).body)
213
+ unless j.nil?
214
+ return j_to_p(j)
215
+ end
216
+ return nil
217
+ end
107
218
  end
108
219
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: utopian_ruby_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuxi