class CrystalSDK::Profile::Request
Attributes
id[R]
Public Class Methods
check_for_error(resp)
click to toggle source
# File lib/crystal_sdk/profile/request.rb, line 26 def check_for_error(resp) raise Profile::RateLimitHitError if resp.code == '429' raise Profile::NotAuthedError.new(Base.key) if resp.code == '401' raise Profile::NotFoundError if resp.code == '404' end
from_search(query)
click to toggle source
# File lib/crystal_sdk/profile/request.rb, line 14 def from_search(query) begin resp = Api.make_request(:post, 'profiles/async', params: query) rescue Nestful::ResponseError => e check_for_error(e.response) raise e end body = JSON.parse(resp.body || '{}', symbolize_names: true) Profile::Request.new(body[:request_id]) end
new(id)
click to toggle source
# File lib/crystal_sdk/profile/request.rb, line 9 def initialize(id) @id = id end
Public Instance Methods
did_find_profile?()
click to toggle source
# File lib/crystal_sdk/profile/request.rb, line 65 def did_find_profile? return false unless did_finish? && fetch_status == 'complete' info = fetch_request_info !info[:info][:error] rescue Profile::NotFoundError false end
did_finish?()
click to toggle source
# File lib/crystal_sdk/profile/request.rb, line 56 def did_finish? status = fetch_status status == 'complete' || status == 'error' rescue Profile::NotFoundError true rescue Profile::NotAuthedError true end
fetch_request_info()
click to toggle source
# File lib/crystal_sdk/profile/request.rb, line 33 def fetch_request_info return @cached_data if @cached_data begin resp = Api.make_request(:get, "profiles/results/#{@id}") rescue Nestful::ResponseError => e Request.check_for_error(e.response) raise e end body = resp.body ? JSON.parse(resp.body, symbolize_names: true) : nil if body[:status] == 'complete' || body[:status] == 'error' @cached_data = body end body end
fetch_status()
click to toggle source
# File lib/crystal_sdk/profile/request.rb, line 52 def fetch_status fetch_request_info[:status] end
profile_info()
click to toggle source
# File lib/crystal_sdk/profile/request.rb, line 74 def profile_info return nil unless did_find_profile? req_info = fetch_request_info profile_info = RecursiveOpenStruct.new(req_info[:info]) recommendations = RecursiveOpenStruct.new(req_info[:recommendations]) { info: profile_info, recommendations: recommendations } end