Module: FulfilApi

Defined in:
lib/fulfil_api.rb,
lib/fulfil_api/error.rb,
lib/fulfil_api/client.rb,
lib/fulfil_api/version.rb,
lib/fulfil_api/resource.rb,
lib/fulfil_api/test_helper.rb,
lib/fulfil_api/access_token.rb,
lib/fulfil_api/configuration.rb,
lib/fulfil_api/resource/relation.rb,
lib/fulfil_api/resource/attribute_type.rb,
lib/fulfil_api/resource/relation/naming.rb,
lib/fulfil_api/resource/relation/loadable.rb,
lib/fulfil_api/resource/attribute_assignable.rb,
lib/fulfil_api/resource/relation/query_methods.rb

Defined Under Namespace

Modules: TestHelper Classes: AccessToken, Client, Configuration, Error, Resource

Constant Summary collapse

VERSION =
"0.0.1"

Class Method Summary collapse

Class Method Details

.clientFulfilApi::Client

Builds an HTTP client to interact with an API endpoint of Fulfil.

To use a different configuration, wrap the call to the client method into

an {.with_config} block.

FulfilApi.with_config(...) do
  FulfilApi.client.get(...)
end

Examples:

with a custom configuration

Returns:



124
125
126
# File 'lib/fulfil_api/client.rb', line 124

def self.client
  Client.new(FulfilApi.configuration)
end

.configurationFulfil::Configuration

Provides thread-safe access to the gem’s configuration.

Returns:

  • (Fulfil::Configuration)

    The current configuration object.



65
66
67
# File 'lib/fulfil_api/configuration.rb', line 65

def self.configuration
  @configuration_mutex.synchronize { @configuration }
end

.configuration=(options_or_configuration) ⇒ Fulfil::Configuration

Overwrites the configuration with the newly provided configuration options.

Parameters:

  • options (Hash, Fulfil::Configuration)

    A list of configuration options for the gem.

Returns:

  • (Fulfil::Configuration)

    The updated configuration object.



81
82
83
84
85
86
87
88
89
90
91
# File 'lib/fulfil_api/configuration.rb', line 81

def self.configuration=(options_or_configuration)
  @configuration_mutex.synchronize do
    if options_or_configuration.is_a?(Hash)
      options_or_configuration.each_pair do |key, value|
        @configuration.send(:"#{key}=", value) if @configuration.respond_to?(:"#{key}=")
      end
    elsif options_or_configuration.is_a?(Configuration)
      @configuration = options_or_configuration
    end
  end
end

.configure {|config| ... } ⇒ void

This method returns an undefined value.

Allows the configuration of the gem in a thread-safe manner.

Yield Parameters:

  • config (Fulfil::Configuration)

    The current configuration object.



73
74
75
# File 'lib/fulfil_api/configuration.rb', line 73

def self.configure
  @configuration_mutex.synchronize { yield(@configuration) }
end

.with_config(temporary_options) { ... } ⇒ void

This method returns an undefined value.

Temporarily applies the provided configuration options within a block,

and then reverts to the original configuration after the block executes.

Parameters:

  • temporary_options (Hash)

    A hash of temporary configuration options.

Yields:

  • Executes the block with the temporary configuration.



99
100
101
102
103
104
105
106
107
# File 'lib/fulfil_api/configuration.rb', line 99

def self.with_config(temporary_options)
  original_configuration = configuration.dup
  self.configuration = temporary_options

  yield
ensure
  # Revert to the original configuration
  self.configuration = original_configuration
end