Class: Rst::Client
- Inherits:
-
Object
- Object
- Rst::Client
- Defined in:
- lib/rst/client.rb
Instance Attribute Summary collapse
-
#base_uri ⇒ Object
readonly
Returns the value of attribute base_uri.
Instance Method Summary collapse
-
#initialize(base_uri = "https://rstat.us") ⇒ Client
constructor
A new instance of Client.
- #messages_all(params = {:page => 1}) ⇒ Object
- #messages_user(params = {}) ⇒ Object
- #users_search(params = {}) ⇒ Object
Constructor Details
#initialize(base_uri = "https://rstat.us") ⇒ Client
Returns a new instance of Client.
8 9 10 |
# File 'lib/rst/client.rb', line 8 def initialize(base_uri = "https://rstat.us") @base_uri = base_uri end |
Instance Attribute Details
#base_uri ⇒ Object (readonly)
Returns the value of attribute base_uri.
6 7 8 |
# File 'lib/rst/client.rb', line 6 def base_uri @base_uri end |
Instance Method Details
#messages_all(params = {:page => 1}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rst/client.rb', line 12 def (params = {:page => 1}) = find_a_in(root_response, :rel => "messages-all") = resolve_relative_uri( :relative => , :base => base_uri ) all_response = get_body() current_uri = (params[:page] - 1).times do next_page_path = find_a_in(all_response, :rel => "next") current_uri = resolve_relative_uri( :relative => next_page_path, :base => current_uri ) all_response = get_body(current_uri) end = all_response.css("div#messages ul.all li").map { |li| Rst::Status.parse(li) } end |
#messages_user(params = {}) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/rst/client.rb', line 36 def (params = {}) search_results = users_search(:pattern => params[:username]) result = search_results.detect { |sr| sr.username.match(/^#{params[:username]}$/i) } user_uri = resolve_relative_uri( :relative => result.path, :base => base_uri ) user_response = get_body(user_uri) = user_response.css("div#messages ul.messages-user li") .map { |li| Rst::Status.parse(li) } end |
#users_search(params = {}) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/rst/client.rb', line 54 def users_search(params = {}) users_search_path = find_a_in(root_response, :rel => "users-search") users_search_uri = resolve_relative_uri( :relative => users_search_path, :base => base_uri ) users_search_response = get_body(users_search_uri) form = users_search_response.css("form.users-search").first search_uri = resolve_relative_uri( :relative => form["action"], :base => users_search_uri ) user_lookup_query = "#{search_uri}?search=#{params[:pattern]}" user_lookup_response = get_body(user_lookup_query) search_results = user_lookup_response.css("div#users ul.search li.user") search_results.map { |li| Rst::User.parse(li) } end |