class Prospector::Client

Constants

DEFAULT_ENDPOINT

Attributes

endpoint[R]

Public Class Methods

deliver(*args) click to toggle source
# File lib/prospector/client.rb, line 7
def self.deliver(*args)
  new.deliver(*args)
end
new(endpoint = DEFAULT_ENDPOINT, secret_token = nil, client_secret = nil) click to toggle source
# File lib/prospector/client.rb, line 11
def initialize(endpoint = DEFAULT_ENDPOINT, secret_token = nil, client_secret = nil)
  @endpoint       = URI(endpoint)
  @secret_token   = secret_token
  @client_secret  = client_secret
end

Public Instance Methods

client_secret() click to toggle source
# File lib/prospector/client.rb, line 29
def client_secret
  @client_secret ||= Prospector.configuration.client_secret
end
deliver(specifications, ruby_version) click to toggle source
# File lib/prospector/client.rb, line 17
def deliver(specifications, ruby_version)
  set_request_body(specifications, ruby_version)

  case response.code
  when "401" then raise AuthenticationError
  when "402" then raise AccountSubscriptionStatusError, json[:error]
  when "200" then return true
  else
    raise UnknownError
  end
end
secret_token() click to toggle source
# File lib/prospector/client.rb, line 33
def secret_token
  @secret_token ||= Prospector.configuration.secret_token
end

Private Instance Methods

build_request() click to toggle source
# File lib/prospector/client.rb, line 51
def build_request
  request = Net::HTTP::Post.new(endpoint)
  request['X-Auth-Token']   = secret_token
  request['X-Auth-Secret']  = client_secret
  request['Content-Type']   = 'application/json'
  request
end
hash_from_specifications(specifications) click to toggle source
# File lib/prospector/client.rb, line 72
def hash_from_specifications(specifications)
  specifications.to_a.map do |spec|
    {
      name: spec.name,
      version: spec.version.to_s
    }
  end
end
json() click to toggle source
# File lib/prospector/client.rb, line 47
def json
  @json ||= JSON.parse(response.body)
end
make_request() click to toggle source
# File lib/prospector/client.rb, line 66
def make_request
  Net::HTTP.start(endpoint.hostname, endpoint.port) do |http|
    http.request(request)
  end
end
request() click to toggle source
# File lib/prospector/client.rb, line 39
def request
  @request ||= build_request
end
response() click to toggle source
# File lib/prospector/client.rb, line 43
def response
  @response ||= make_request
end
set_request_body(specifications, ruby_version) click to toggle source
# File lib/prospector/client.rb, line 59
def set_request_body(specifications, ruby_version)
  request.body = {
    ruby_version: ruby_version.to_json,
    specifications: hash_from_specifications(specifications)
  }.to_json
end