module Cloudscreener::Helper

Cloudscreener api helper

Public Class Methods

fetch_reco(token, query) click to toggle source
# File lib/cloudscreener_ruby_sdk/helper.rb, line 20
def fetch_reco(token, query)
  response = post_json_with_token('https://api.cloudscreener.com/v1/reco', token, query.to_json)
  raise response.message if response.code >= 400

  JSON.parse(response.body)
end
fetch_token(email, password) click to toggle source
# File lib/cloudscreener_ruby_sdk/helper.rb, line 10
def fetch_token(email, password)
  body = "email=#{URI.encode_www_form_component(email)}&password=#{URI.encode_www_form_component(password)}"

  response = post_raw('https://search.cloudscreener.com/token', body)

  raise response.message if response.code >= 400

  JSON.parse(response.body)['access_token']
end

Private Class Methods

post_json_with_token(url, token, content) click to toggle source
# File lib/cloudscreener_ruby_sdk/helper.rb, line 33
def post_json_with_token(url, token, content)
  post_request(url, content, :'Content-Type' => 'application/json', Authorization: "Bearer #{token}")
end
post_raw(url, content) click to toggle source
# File lib/cloudscreener_ruby_sdk/helper.rb, line 29
def post_raw(url, content)
  post_request(url, content, :'Content-Type' => 'application/x-www-form-urlencoded')
end
post_request(url, content, headers) click to toggle source
# File lib/cloudscreener_ruby_sdk/helper.rb, line 37
def post_request(url, content, headers)
  HTTParty.post(url, body: content, headers: headers)
end