Module: T::RequestableAPI::AccountEndpoints
- Included in:
- T::RequestableAPI
- Defined in:
- lib/t/requestable_api/account_endpoints.rb
Instance Method Summary collapse
- #x_before_request(&block) ⇒ Object
- #x_filter(follow: nil, track: nil) ⇒ Object
- #x_sample(language: nil) ⇒ Object
- #x_settings(lang:) ⇒ Object
- #x_trend_locations ⇒ Object
- #x_trends(woe_id, opts = {}) ⇒ Object
- #x_update_profile(description: nil, location: nil, name: nil, url: nil) ⇒ Object
- #x_update_profile_background_image(file, tile: false, skip_status: true) ⇒ Object
- #x_update_profile_image(file) ⇒ Object
Instance Method Details
#x_before_request(&block) ⇒ Object
53 54 55 |
# File 'lib/t/requestable_api/account_endpoints.rb', line 53 def x_before_request(&block) @requestable_api_before_request = block end |
#x_filter(follow: nil, track: nil) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/t/requestable_api/account_endpoints.rb', line 66 def x_filter(follow: nil, track: nil, &) @requestable_api_before_request&.call query = build_filter_query(follow: follow, track: track) x_search(query, count: 100).each(&) rescue X::BadRequest x_search("news", count: 20).each(&) end |
#x_sample(language: nil) ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/t/requestable_api/account_endpoints.rb', line 57 def x_sample(language: nil, &) @requestable_api_before_request&.call query = language ? "lang:#{language} -is:retweet" : "has:mentions OR -is:retweet" x_search(query, count: 20).each(&) rescue X::BadRequest fallback = language ? "news lang:#{language}" : "news" x_search(fallback, count: 20).each(&) end |
#x_settings(lang:) ⇒ Object
26 27 28 29 |
# File 'lib/t/requestable_api/account_endpoints.rb', line 26 def x_settings(lang:) t_post_v1_form("account/settings.json", {lang: lang}) true end |
#x_trend_locations ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/t/requestable_api/account_endpoints.rb', line 17 def x_trend_locations Array(t_get_v1("trends/available.json")).map do |place| loc = {"woeid" => place["woeid"], "name" => place["name"], "country" => place["country"], "parent_id" => place["parentid"] || place["parent_id"], "place_type" => place.dig("placeType", "name") || place["place_type"]} loc end end |
#x_trends(woe_id, opts = {}) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/t/requestable_api/account_endpoints.rb', line 4 def x_trends(woe_id, opts = {}) params = {max_trends: "50"} params["trend.fields"] = "trend_name,tweet_count" if opts[:exclude].to_s == "hashtags" response = t_get_v2("trends/by/woeid/#{woe_id}", params) Array(response["data"]).filter_map do |trend| name = trend["trend_name"] || trend["name"] next if name.nil? next if opts[:exclude].to_s == "hashtags" && name.start_with?("#") {"name" => name} end end |
#x_update_profile(description: nil, location: nil, name: nil, url: nil) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/t/requestable_api/account_endpoints.rb', line 31 def x_update_profile(description: nil, location: nil, name: nil, url: nil) params = {} params[:description] = description unless description.nil? params[:location] = location unless location.nil? params[:name] = name unless name.nil? params[:url] = url unless url.nil? response = t_post_v1_form("account/update_profile.json", params) extract_users(response).first || (response || {}) end |
#x_update_profile_background_image(file, tile: false, skip_status: true) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/t/requestable_api/account_endpoints.rb', line 46 def x_update_profile_background_image(file, tile: false, skip_status: true) params = {image: Base64.strict_encode64(file.read), skip_status: skip_status} params[:tile] = tile if tile t_post_v1_form("account/update_profile_background_image.json", params) true end |
#x_update_profile_image(file) ⇒ Object
41 42 43 44 |
# File 'lib/t/requestable_api/account_endpoints.rb', line 41 def x_update_profile_image(file) response = t_post_v1_form("account/update_profile_image.json", {image: Base64.strict_encode64(file.read)}) extract_users(response).first || (response || {}) end |