Sha256: 9fc5f389d100b2a89cd62cc34a357dfdcee4d0ff29079ea57d20bc9b1dd70eeb

Contents?: true

Size: 1.52 KB

Versions: 3

Compression:

Stored size: 1.52 KB

Contents

require 'faraday'
require 'json'
require 'hashie'

module Atlas
  module Api
    class Client

      def initialize(options = {})
        @api_endpoint = options[:api_endpoint]
        @auth_token = options[:auth_token]
      end

      # Builds
      # ------------------------------------------------------------------------

      def builds(options = {})
        get("builds", options)
      end

      def build(id, options = {})
        get("builds/#{id}", options)
      end

      def create_build(options)
        post("builds", options)
      end

      # Build Formats
      # ------------------------------------------------------------------------

      def update_build_format(uuid, options = {})
        put("build_formats/#{uuid}", options)
      end

      # HTTP methods
      # ------------------------------------------------------------------------

      def get(path, options = {})
        request :get, path, options
      end

      def post(path, options = {})
        request :post, path, options
      end

      def put(path, options = {})
        request :put, path, options
      end

      def delete(path, options = {})
        request :delete, path, options
      end

      def agent
        @agent ||= Faraday.new(url: @api_endpoint, params: { auth_token: @auth_token })
        @agent
      end

      private

      def request(method, path, options)
        @last_response = response = agent.send(method, URI.encode(path), options)
        Hashie::Mash.new(JSON.parse(response.body))
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
atlas-api-0.0.4 lib/atlas-api/client.rb
atlas-api-0.0.3 lib/atlas-api/client.rb
atlas-api-0.0.2 lib/atlas-api/client.rb