class Mirrorhub::API::Client

Attributes

location[R]
token[RW]

Public Class Methods

new(location) click to toggle source
# File lib/mirrorhub/api/client.rb, line 8
def initialize(location)
  @location = location
end

Public Instance Methods

auth() click to toggle source
# File lib/mirrorhub/api/client.rb, line 12
def auth
  res = post('contacts/auth',
             headers: {'Grpc-Metadata-ContactEmail': mail,
                       'Grpc-Metadata-ContactPassword': password})

  true if @token = res['token']
end
get(resource, params: {}, headers: {}) click to toggle source
# File lib/mirrorhub/api/client.rb, line 20
def get(resource, params: {}, headers: {})
  request = Typhoeus::Request.new(
    "#{@location}/#{resource}",
    method: :get,
    params: params,
    headers: headers
  )
  res = request.run
  JSON.parse(res.response_body)
end
post(resource, params: {}, headers: {}, body: {}) click to toggle source
# File lib/mirrorhub/api/client.rb, line 31
def post(resource, params: {}, headers: {}, body: {})
  request = Typhoeus::Request.new(
    "#{@location}/#{resource}",
    method: :post,
    params: params,
    body: body.to_json,
    headers: headers
  )
  res = request.run
  JSON.parse(res.response_body)

end