Class: NewsmastMastodon::SearchPostService

Inherits:
BaseService
  • Object
show all
Defined in:
app/services/newsmast_mastodon/search_post_service.rb

Instance Method Summary collapse

Constructor Details

#initialize(api_base_url, token, query) ⇒ SearchPostService

Returns a new instance of SearchPostService.



9
10
11
12
13
# File 'app/services/newsmast_mastodon/search_post_service.rb', line 9

def initialize(api_base_url, token, query)
  @api_base_url = api_base_url
  @token = token
  @query = query
end

Instance Method Details

#callObject



15
16
17
18
19
20
21
22
23
24
25
# File 'app/services/newsmast_mastodon/search_post_service.rb', line 15

def call
  response = HTTParty.get("#{@api_base_url}/api/v2/search",
    query: { q: @query, type: 'statuses', resolve: true, limit: 1 },
    headers: { 'Authorization' => "Bearer #{@token}" }
  )
  if response.success?
    return response['statuses']&.first&.dig('id')
  end

  nil
end