Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
pooza committed May 1, 2024
1 parent c79b484 commit f67d72d
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions app/lib/mulukhiya/service/annict_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ class AnnictService
include SNSMethods
attr_reader :timestamps, :sns

INVALID_KEYWORD = '__??!!__'.freeze

def initialize(token = nil, guest: true)
@token = (token.decrypt rescue token)
@guest = guest
Expand Down Expand Up @@ -41,7 +39,7 @@ def account
def works(keyword = nil)
titles = [keyword] if keyword.present?
titles = self.class.keywords unless titles.present?
titles = [INVALID_KEYWORD] unless titles.present?
titles = nil unless titles.present?
works = query(:works, {titles:}).dig('data', 'searchWorks', 'edges').map do |work|
self.class.create_work_info(work['node'])
end
Expand Down Expand Up @@ -313,10 +311,10 @@ def crawlable?(activity, params)
end

def query(template, variables = nil)
query = File.join(Environment.dir, 'app/query/annict', "#{template}.graphql")
endpoint = Ginseng::URI.parse(config['/annict/urls/api/graphql'])
body = {query: File.read(query)}
query = File.read(File.join(Environment.dir, 'app/query/annict', "#{template}.graphql"))
body = {query:}
body[:variables] = variables.deep_stringify_keys if variables
endpoint = Ginseng::URI.parse(config['/annict/urls/api/graphql'])
response = graphql_service.post(endpoint.path, {
body: body.to_json,
headers: {Authorization: "Bearer #{@token}"},
Expand Down

0 comments on commit f67d72d

Please sign in to comment.