lib/bubbles/rest_client_resources.rb in bubbles-rest-client-0.1.0 vs lib/bubbles/rest_client_resources.rb in bubbles-rest-client-0.2.0

- old
+ new

@@ -1,22 +1,14 @@ require 'bubbles/config' require 'bubbles/rest_environment' module Bubbles class RestClientResources - def local_environment - Bubbles.configuration.local_environment + def environment + Bubbles.configuration.environment end - def staging_environment - Bubbles.configuration.staging_environment - end - - def production_environment - Bubbles.configuration.production_environment - end - ## # Create a new instance of +RestClientResources+. # # @param env The +RestEnvironment+ that should be used for this set of resources. # @param api_key The API key to use to send to the host for unauthenticated requests. @@ -254,21 +246,21 @@ # @param [Symbol] environment A {Symbol} describing the environment to use. Must be one of: # [:production, :staging, :local, nil]. If +nil+, note that +:production+ will be used. # # @return [RestEnvironment] The {RestEnvironment} corresponding to the given {Symbol}. # - def get_environment(environment) - if !environment || environment == :production - return self.production_environment - elsif environment == :staging - return self.staging_environment - end + # def get_environment(environment) + # if !environment || environment == :production + # return self.production_environment + # elsif environment == :staging + # return self.staging_environment + # end + # + # + # self.local_environment + # end - - self.local_environment - end - private ## # Execute a REST call to the API. # @@ -309,22 +301,22 @@ unless auth_token == nil headers[:authorization] = 'Bearer ' + auth_token end - if endpoint.expect_json - headers[:accept] = :json - end + headers[:accept] = :json response = block.call(env, url, data, headers) rescue Errno::ECONNREFUSED response = { :error => 'Unable to connect to host ' + env.host.to_s + ':' + env.port.to_s }.to_json end - unless endpoint.expect_json or endpoint.method != :head - return response + if endpoint.return_type == :body_as_object and endpoint.method != :head + return JSON.parse(response, object_class: OpenStruct) + elsif endpoint.return_type == :body_as_string and endpoint.method != :head + return response.body end - JSON.parse(response, object_class: OpenStruct) + response end end end \ No newline at end of file