<commit_before>require 'httparty'

# @author <NAME>
#
# An API wrapper for the http://mongohq.com API
# @see Client Client documentation for examples how to use the API.
module Mongohq
  # The client to access the API.
  # @example Create a database
  #   client = Mongohq::Client.new("arthur","dent")
  #   client.create_database 'mydatabase','micro'
  #
  #   
  class Client
    include HTTParty
    base_uri 'https://mongohq.com/api'

    # Inititalizer for the client class. 
    # @param [String] api_key the api_key name of your mongohq.com account.
    # @param [String] api_secret the api_secret of your mongohq.com account.
    # @return [Client] a new instance of the client.
    def initialize(api_key, api_secret )
      @auth = {:api_key => api_key, :api_secret => api_secret}
    end
          
private
    # Examines a bad response and raises an appropriate exception
    #
    # @param [HTTParty::Response] the response as returned by the web request.
    # @raise [ResponseError] raised in case of a web service related error.
    # @raise [StandardError] raised in case of an error that is not web service related. 
    # @return [HTTParty::Response] the response as returned by the web request.
    def self.bad_response(response)
      if response.class == HTTParty::Response
       raise ResponseError, response
      end
      raise StandardError, "Unkown error"
    end

    # Examines a response and either returns the response or
    # raise an exception.
    # @param [HTTParty::Response] the response as returned by the web request.
    # @raise [ResponseError] raised in case of a web service related error.
    # @raise [StandardError] raised in case of an error that is not web service related. 
    # @return [HTTParty::Response] the response as returned by the web request.
    def handle_result(response)
      response.ok? ? response : self.bad_response(response) 
    end

public  

    # Returns a list of all databases.
    # @return [HTTParty::Response] A response.
    #   An array containing a list of databases.
    #   ["scottyapp","shopsnearme","taglist","triponadeal"]  
    def databases()
      options={:basic_auth => @auth}
      handle_result self.class.get('/databases', options)
    end

    # Creates a new database
    # @param (String) name the name of the new database.
    # @param (String) db_type the type of the new database. Can be micro, small, large. Check mongohq.com for additional options
    # @return [HTTParty::Response] A response.
    def create_database(name,db_type)<commit_msg>handle response test<commit_after>require 'httparty'

# @author <NAME>
#
# An API wrapper for the http://mongohq.com API
# @see Client Client documentation for examples how to use the API.
module Mongohq
  # The client to access the API.
  # @example Create a database
  #   client = Mongohq::Client.new("arthur","dent")
  #   client.create_database 'mydatabase','micro'
  #
  #   
  class Client
    include HTTParty
    base_uri 'https://mongohq.com/api'

    # Inititalizer for the client class. 
    # @param [String] api_key the api_key name of your mongohq.com account.
    # @param [String] api_secret the api_secret of your mongohq.com account.
    # @return [Client] a new instance of the client.
    def initialize(api_key, api_secret )
      @auth = {:api_key => api_key, :api_secret => api_secret}
    end
          
    # Examines a bad response and raises an appropriate exception
    #
    # @param [HTTParty::Response] the response as returned by the web request.
    # @raise [ResponseError] raised in case of a web service related error.
    # @raise [StandardError] raised in case of an error that is not web service related. 
    # @return [HTTParty::Response] the response as returned by the web request.
    def self.bad_response(response)
      if response.class == HTTParty::Response
       raise ResponseError, response
      end
      raise StandardError, "Unkown error"
    end

    # Examines a response and either returns the response or
    # raise an exception.
    # @param [HTTParty::Response] the response as returned by the web request.
    # @raise [ResponseError] raised in case of a web service related error.
    # @raise [StandardError] raised in case of an error that is not web service related. 
    # @return [HTTParty::Response] the response as returned by the web request.
    def handle_result(response)
      puts response.inspect
      response.ok? ? response : self.bad_response(response) 
    end

public  

    # Returns a list of all databases.
    # @return [HTTParty::Response] A response.
    #   An array containing a list of databases.
    #   ["scottyapp","shopsnearme","taglist","triponadeal"]  
    def databases()
      options={:basic_auth => @auth}
      handle_result self.class.get('/databases', options)
    end

    # Creates a new database
    # @param (String) name the name of the new database.
    # @param (String) db_type the type of the new database. Can be micro, small, large. Check mongohq.com for additional options
    # @return [HTTParty::Response] A response.
    def create_database(name,db_type)
{'fraction_non_alphanumeric': 0.08754143107818288, 'fraction_numerical': 0.0, 'mean_word_length': 3.2083675143560297, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '76297', 'n_tokens_mistral': 1494, 'n_tokens_neox': 1461, 'n_words': 566}