Skip to content

Commit

Permalink
Fix pdf download bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Coder-Srinivas committed Dec 23, 2024
1 parent e3d739b commit 86b55fb
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions backend/app/services/open_badge_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require 'json'
require 'singleton'
require 'uri'

class OpenBadgeApi
include Singleton
Expand Down Expand Up @@ -104,10 +105,16 @@ def get_pdf(badge_id, email)

def fetch_event_response(email)
# Response is an octet stream

base_url = "https://openbadgefactory.com/v1/event/#{@client_id}"
query_params = URI.encode_www_form(email: email)

url = "#{base_url}?#{query_params}"

response = HTTPX.plugin(:auth)
.with(headers: { 'content-type' => 'application/json' })
.authorization("Bearer #{token}")
.get("https://openbadgefactory.com/v1/event/#{@client_id}?email=#{email}")
.with(headers: { 'content-type' => 'application/json' })
.authorization("Bearer #{token}")
.get(url)

json_objects = response.body.to_s.split("\n").map(&:strip).reject(&:empty?)
json_objects.map { |json_str| JSON.parse(json_str) }
Expand Down

0 comments on commit 86b55fb

Please sign in to comment.