inertia186 / radiator

Hive Ruby API Client
https://hive.blog/hive-139531/@inertia/radiator-v0-4-8-hive-ruby-api-client-eclipse-update
Other
50 stars 22 forks source link

How can I get the permalink of the last post from an Author? #15

Closed devopsjourney1 closed 6 years ago

devopsjourney1 commented 6 years ago

Hello,

I've been playing around with your API in a rails application I'm having fun it... Was able to get a lot of things working like pulling Steem power, posting, voting... but I can't seem to figure out how to pull the last post from a specific author.

Is there a method for this type of operation?

Thank you for any help!

Nerossoul commented 6 years ago
  def get_lust_post_data(user_name)
    lust_post_data = []
    max_number = get_account_history_max_number(user_name)
    limit_response = 1999
    api = Radiator::Api.new
    while max_number > 0 do
      limit_response = max_number - 1 if limit_response > max_number
      response = api.get_account_history(user_name, max_number, limit_response)
      response['result'].reverse_each do |result|
        if result[1]['op'][0] == 'comment' then
          if (result[1]['op'][1]['author'] == user_name && result[1]['op'][1]['parent_author'] == '') then
            lust_post_data = result[1]
            max_number = 0
            break
          end
        end
      end
      max_number = max_number - 1999
    end
    return lust_post_data
  end

  def get_account_history_max_number(user_name)
    api = Radiator::Api.new
    response = api.get_account_history(user_name, 800_000_000_000, 0)
    max_number = response['result'][0][0]   
    return max_number
  end
devopsjourney1 commented 6 years ago

thank you, that worked.