Class: UtopianRuby::UtopianRubyAPI
- Inherits:
-
Object
- Object
- UtopianRuby::UtopianRubyAPI
- Defined in:
- lib/utopian_ruby_api.rb
Constant Summary collapse
- @@host =
'https://api.utopian.io'
Class Method Summary collapse
- .get_categories ⇒ Object
- .get_connection ⇒ Object
-
.get_moderator(user) ⇒ Object
get a particular moderator’s metadata.
- .get_moderator_obj(user) ⇒ Object
-
.get_moderators ⇒ Object
list all Utopian moderators.
- .get_moderators_obj ⇒ Object
-
.get_post(author, permlink) ⇒ Object
return a particular post information.
- .get_post_obj(author, permlink) ⇒ Object
-
.get_posts(params = nil) ⇒ Object
return JSON containing all post information that satisfies params.
- .get_posts_obj(params = nil) ⇒ Object
- .get_request(endpoint) ⇒ Object
-
.get_sponsors ⇒ Object
return sponsor list.
- .get_url_parameters(params) ⇒ Object
-
.is_moderator(user) ⇒ Object
check if a user is a moderator.
-
.is_sponsor(user) ⇒ Object
check if a user is an utopian sponsor.
-
.is_supervisor(user) ⇒ Object
check if a user is an utopian supervisor.
-
.is_voting ⇒ Object
return if Utopian is currently voting.
- .j_to_m(m) ⇒ Object
- .j_to_p(p) ⇒ Object
-
.post_count(params) ⇒ Object
return total number of Utopian posts that satisfy params.
-
.stats ⇒ Object
return Utopian current stats.
Class Method Details
.get_categories ⇒ Object
219 220 221 |
# File 'lib/utopian_ruby_api.rb', line 219 def self.get_categories() self.stats()["stats"]["categories"].keys end |
.get_connection ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/utopian_ruby_api.rb', line 11 def self.get_connection() conn = Faraday.new(:url => @@host) do |c| c.use Faraday::Request::UrlEncoded #c.use Faraday::Response::Logger c.use Faraday::Adapter::NetHttp end end |
.get_moderator(user) ⇒ Object
get a particular moderator’s metadata
55 56 57 58 59 60 61 62 |
# File 'lib/utopian_ruby_api.rb', line 55 def self.get_moderator(user) get_moderators()["results"].each do |moderator| if moderator['account']==user return moderator end end nil end |
.get_moderator_obj(user) ⇒ Object
134 135 136 137 138 139 140 141 |
# File 'lib/utopian_ruby_api.rb', line 134 def self.get_moderator_obj(user) get_moderators()["results"].each do |m| if m["account"] == user return j_to_m(m) end end return nil end |
.get_moderators ⇒ Object
list all Utopian moderators
30 31 32 |
# File 'lib/utopian_ruby_api.rb', line 30 def self.get_moderators() JSON.parse(get_request('/api/moderators').body) end |
.get_moderators_obj ⇒ Object
126 127 128 129 130 131 132 |
# File 'lib/utopian_ruby_api.rb', line 126 def self.get_moderators_obj() moderators = Set.new get_moderators()["results"].each do |m| moderators << j_to_m(m) end moderators end |
.get_post(author, permlink) ⇒ Object
return a particular post information
98 99 100 |
# File 'lib/utopian_ruby_api.rb', line 98 def self.get_post(,permlink) JSON.parse(get_request('/api/posts/'++'/'+permlink).body) end |
.get_post_obj(author, permlink) ⇒ Object
211 212 213 214 215 216 217 |
# File 'lib/utopian_ruby_api.rb', line 211 def self.get_post_obj(,permlink) j = JSON.parse(get_request('/api/posts/'++'/'+permlink).body) unless j.nil? return j_to_p(j) end return nil end |
.get_posts(params = nil) ⇒ Object
return JSON containing all post information that satisfies params
90 91 92 93 94 95 |
# File 'lib/utopian_ruby_api.rb', line 90 def self.get_posts(params=nil) if params.nil? params = {} end JSON.parse(get_request('/api/posts?'+get_url_parameters(params)).body) end |
.get_posts_obj(params = nil) ⇒ Object
199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/utopian_ruby_api.rb', line 199 def self.get_posts_obj(params=nil) if params.nil? params = {} end posts = Set.new get_posts(params)["results"].each do |p| posts << j_to_p(p) end posts end |
.get_request(endpoint) ⇒ Object
19 20 21 |
# File 'lib/utopian_ruby_api.rb', line 19 def self.get_request(endpoint) get_connection().get endpoint end |
.get_sponsors ⇒ Object
return sponsor list
65 66 67 |
# File 'lib/utopian_ruby_api.rb', line 65 def self.get_sponsors() JSON.parse(get_request('/api/sponsors').body) end |
.get_url_parameters(params) ⇒ Object
23 24 25 26 27 |
# File 'lib/utopian_ruby_api.rb', line 23 def self.get_url_parameters(params) uri = Addressable::URI.new uri.query_values = params uri.query end |
.is_moderator(user) ⇒ Object
check if a user is a moderator
35 36 37 38 39 40 41 42 |
# File 'lib/utopian_ruby_api.rb', line 35 def self.is_moderator(user) get_moderators()["results"].each do |moderator| if moderator['account']==user return true end end false end |
.is_sponsor(user) ⇒ Object
check if a user is an utopian sponsor
70 71 72 73 74 75 76 77 |
# File 'lib/utopian_ruby_api.rb', line 70 def self.is_sponsor(user) get_sponsors()["results"].each do |sponsor| if sponsor['account']==user return true end end false end |
.is_supervisor(user) ⇒ Object
check if a user is an utopian supervisor
45 46 47 48 49 50 51 52 |
# File 'lib/utopian_ruby_api.rb', line 45 def self.is_supervisor(user) get_moderators()["results"].each do |moderator| if moderator['account']==user and moderator['supermoderator'] return true end end false end |
.is_voting ⇒ Object
return if Utopian is currently voting
85 86 87 |
# File 'lib/utopian_ruby_api.rb', line 85 def self.is_voting() self.stats()["stats"]["bot_is_voting"] end |
.j_to_m(m) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/utopian_ruby_api.rb', line 110 def self.j_to_m(m) moderator = Moderator.new moderator._id = m["_id"] moderator.account = m["account"] unless m["account"].nil? moderator.referrer = m["referrer"] unless m["referrer"].nil? moderator.supermoderator = m["supermoderator"] unless m["supermoderator"].nil? moderator.reviewed = m["reviewed"] unless m["reviewed"].nil? moderator.banned = m["banned"] unless m["banned"].nil? moderator.total_moderated = m["total_moderated"] unless m["total_moderated"].nil? moderator.total_paid_rewards = m["total_paid_rewards"] unless m["total_paid_rewards"].nil? moderator.total_paid_rewards_steem = m["total_paid_rewards_steem"] unless m["total_paid_rewards_steem"].nil? moderator.should_receive_rewards = m["should_receive_rewards"] unless m["should_receive_rewards"].nil? moderator.percentage_total_rewards_moderators = m["percentage_total_rewards_moderators"] unless m["percentage_total_rewards_moderators"].nil? moderator end |
.j_to_p(p) ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/utopian_ruby_api.rb', line 143 def self.j_to_p(p) post = Post.new post._id = p["_id"] unless p["_id"].nil? post.id = p["id"] unless p["id"].nil? post. = p["author"] unless p["author"].nil? post.flagged = p["flagged"] unless p["flagged"].nil? post.reviewed = p["reviewed"] unless p["reviewed"].nil? post.pending = p["pending"] unless p["pending"].nil? post.moderator = p["moderator"] unless p["moderator"].nil? post.permlink = p["permlink"] unless p["permlink"].nil? post.category = p["category"] unless p["category"].nil? post. = p["parent_author"] unless p["parent_author"].nil? post.parent_permlink = p["parent_permlink"] unless p["parent_permlink"].nil? post.title = p["title"] unless p["title"].nil? post.body = p["body"] unless p["body"].nil? post.created = p["created"] unless p["created"].nil? post.last_update = p[""] unless p["last_update"].nil? post.active = p["active"] unless p["active"].nil? post.last_payout = p["last_payout"] unless p["last_payout"].nil? post.depth = p["depth"] unless p["depth"].nil? post.children = p["children"] unless p["children"].nil? post.net_rshares = p["net_rshares"] unless p["net_rshares"].nil? post.abs_rshares = p["abs_rshares"] unless p["abs_rshares"].nil? post.vote_rshares = p["vote_rshares"] unless p["vote_rshares"].nil? post.children_abs_rshares = p["children_abs_rshares"] unless p["children_abs_rshares"].nil? post.cashout_time = p["cashout_time"] unless p["cashout_time"].nil? post.max_cashout_time = p["max_cashout_time"] unless p["max_cashout_time"].nil? post.total_vote_weight = p["total_vote_weight"] unless p["total_vote_weight"].nil? post.reward_weight = p["reward_weight"] unless p["reward_weight"].nil? post.total_payout_value = p["total_payout_value"] unless p["total_payout_value"].nil? post.curator_payout_value = p["curator_payout_value"] unless p["curator_payout_value"].nil? post. = p["author_rewards"] unless p["author_rewards"].nil? post.net_votes = p["net_votes"] unless p["net_votes"].nil? post.root_comment = p["root_comment"] unless p["root_comment"].nil? post.max_accepted_payout = p["max_accepted_payout"] unless p["max_accepted_payout"].nil? post.percent_steem_dollars = p["percent_steem_dollars"] unless p["percent_steem_dollars"].nil? post.allow_replies = p["allow_replies"] unless p["allow_replies"].nil? post.allow_votes = p["allow_votes"] unless p["allow_votes"].nil? post.allow_curation_rewards = p["allow_curation_rewards"] unless p["allow_curation_rewards"].nil? post.url = p["url"] unless p["url"].nil? post.root_title = p["root_title"] unless p["root_title"].nil? post.pending_payout_value = p["pending_payout_value"] unless p["pending_payout_value"].nil? post.total_pending_payout_value = p["total_pending_payout_value"] unless p["total_pending_payout_value"].nil? post. = p["author_reputation"] unless p["author_reputation"].nil? post.promoted = p["promoted"] unless p["promoted"].nil? post.body_length = p["body_length"] unless p["body_length"].nil? post.__v = p["__v"] unless p["__v"].nil? post.reserved = p["reserved"] unless p["reserved"].nil? post. = p["json_metadata"] unless p["json_metadata"].nil? post.replies = p["replies"] unless p["replies"].nil? post.reblogged_by = p["reblogged_by"] unless p["reblogged_by"].nil? post.beneficiaries = p["beneficiaries"] unless p["beneficiaries"].nil? post.active_votes = p["active_votes"] unless p["active_votes"].nil? post end |
.post_count(params) ⇒ Object
return total number of Utopian posts that satisfy params
103 104 105 106 107 108 |
# File 'lib/utopian_ruby_api.rb', line 103 def self.post_count(params) if params.nil? params = {"limit":1} end get_posts(params)["total"] end |
.stats ⇒ Object
return Utopian current stats
80 81 82 |
# File 'lib/utopian_ruby_api.rb', line 80 def self.stats() JSON.parse(get_request('/api/stats').body) end |