Sha256: f053f10c7f65381e3d1e1bff5404cd98354ce15704360a4d8dac79744383ce07

Contents?: true

Size: 1.46 KB

Versions: 13

Compression:

Stored size: 1.46 KB

Contents

module DeployGate
  module API
    module V1
      class Base
        BASE_URL     = 'https://deploygate.com'
        API_BASE_URL = "#{BASE_URL}/api"

        # @param [String] token
        # @return [DeployGate::API::V1::Base]
        def initialize(token = nil)
          @token = token
        end

        # @param [String] path
        # @param [Hash] params
        # @return [Hash] Responce parse json
        def get(path, params)
          url = API_BASE_URL + path

          res = client.get(url, params, headers)
          JSON.parse(res.body)
        end

        # @param [String] path
        # @param [Hash] params
        # @yield Upload process block
        # @return [Hash] Responce parse json
        def post(path, params, &process_block)
          url = API_BASE_URL + path

          connection = client.post_async(url, params, headers)
          while true
            break if connection.finished?
            process_block.call unless process_block.nil?
          end
          io = connection.pop.content
          body = ''
          while str = io.read(40)
            body += str
          end

          JSON.parse(body)
        end

        private

        def client
          HTTPClient.new(:agent_name => "dg/#{DeployGate::VERSION}")
        end

        def headers
          extheaders = []
          unless @token.nil?
            extheaders.push(['AUTHORIZATION', @token])
          end

          extheaders
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
deploygate-0.2.3 lib/deploygate/api/v1/base.rb
deploygate-0.2.2 lib/deploygate/api/v1/base.rb
deploygate-0.2.1 lib/deploygate/api/v1/base.rb
deploygate-0.2.0 lib/deploygate/api/v1/base.rb
deploygate-0.1.2 lib/deploygate/api/v1/base.rb
deploygate-0.1.1 lib/deploygate/api/v1/base.rb
deploygate-0.1.0 lib/deploygate/api/v1/base.rb
deploygate-0.0.6 lib/deploygate/api/v1/base.rb
deploygate-0.0.5 lib/deploygate/api/v1/base.rb
deploygate-0.0.4 lib/deploygate/api/v1/base.rb
deploygate-0.0.3 lib/deploygate/api/v1/base.rb
deploygate-0.0.2 lib/deploygate/api/v1/base.rb
deploygate-0.0.1 lib/deploygate/api/v1/base.rb