class Kuvera::Api::Client

Constants

ATTACHMENT
AT_ENDPOINT
ENV_HOST
ENV_SECRET
ENV_UID
HOST
ME_ENDPOINT
RESPONSES
ROOT
SHARE_ENDPOINT
UPLOAD_ENDPOINT

Public Class Methods

new(host: ENV_HOST, uid: ENV_UID, secret: ENV_SECRET) click to toggle source
# File lib/kuvera/api/client.rb, line 25
def initialize(host: ENV_HOST, uid: ENV_UID, secret: ENV_SECRET)
  @host = host
  @uid = uid
  @secret = secret
end

Public Instance Methods

at(address) click to toggle source
# File lib/kuvera/api/client.rb, line 37
def at(address)
  response = Net::HTTP.get_response(URI.join(@host, AT_ENDPOINT, address))
  RESPONSES.fetch(response.code.to_i).call(response)
end
me() click to toggle source
# File lib/kuvera/api/client.rb, line 42
def me
  oauth.get(ME_ENDPOINT)
end
share(address) click to toggle source
# File lib/kuvera/api/client.rb, line 52
def share(address)
  oauth.post(SHARE_ENDPOINT, { secret_id: address }.to_json)
end
upload(title, io, mime) click to toggle source
# File lib/kuvera/api/client.rb, line 46
def upload(title, io, mime)
  upload = Faraday::UploadIO.new(io, mime, io.path.split('/').last)
  body = { new_secret: { type: ATTACHMENT, title: title, body: upload } }
  oauth.post(UPLOAD_ENDPOINT, body, headers: {})
end

Private Instance Methods

oauth() click to toggle source
# File lib/kuvera/api/client.rb, line 58
def oauth
  raise MissingCredentials if [@host, @uid, @secret].any?(&:nil?)

  @_oauth = Oauth.new(uid: @uid, secret: @secret, host: @host)
end