Class: Orchestrate::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/orchestrate/application.rb

Overview

Applications in Orchestrate are the highest level of your project.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client_or_api_key, host = "https://api.orchestrate.io") {|connection| ... } ⇒ Object

Instantiate a new Application

Parameters:

  • client_or_api_key (Orchestrate::Client, #to_s)

    A client instantiated with the API key and faraday setup, or the API key for your Orchestrate Application.

Yield Parameters:

  • connection (Faraday::Connection)

    Setup for the Faraday connection.



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/orchestrate/application.rb', line 19

def initialize(client_or_api_key, host="https://api.orchestrate.io", &client_setup)
  if client_or_api_key.kind_of?(Orchestrate::Client)
    @client = client_or_api_key
    @api_key = client.api_key
    @host = client.host
  else
    @api_key = client_or_api_key
    @host = host
    @client = Client.new(api_key, host, &client_setup)
  end
  client.ping
end

Instance Attribute Details

#api_keyString (readonly)

Returns The API key provided.

Returns:

  • (String)

    The API key provided



7
8
9
# File 'lib/orchestrate/application.rb', line 7

def api_key
  @api_key
end

#clientOrchestrate::Client (readonly)

Returns The client tied to this application.

Returns:



13
14
15
# File 'lib/orchestrate/application.rb', line 13

def client
  @client
end

#hostString (readonly)

Returns The Orchestrate data center URL.

Returns:

  • (String)

    The Orchestrate data center URL



10
11
12
# File 'lib/orchestrate/application.rb', line 10

def host
  @host
end

Instance Method Details

#[](collection_name) ⇒ Object

Accessor for Collections

Parameters:

  • collection_name (#to_s)

    The name of the collection.

Returns:

  • Orchestrate::Collection



35
36
37
# File 'lib/orchestrate/application.rb', line 35

def [](collection_name)
  Collection.new(self, collection_name)
end

#in_parallel {|accumulator| ... } ⇒ Object

Note:

This method is not Thread-safe. Requests generated from the same application instance in different threads while #in_parallel is running will behave unpredictably. Use #dup to create per-thread application instances.

Performs requests in parallel. Requires using a Faraday adapter that supports parallel requests.

Examples:

Performing three requests at once

responses = app.in_parallel do |r|
  r[:some_items] = app[:site_globals].lazy
  r[:user]       = app[:users][current_user_key]
  r[:user_feed]  = app.client.list_events(:users, current_user_key, :notices)
end

Yield Parameters:

  • accumulator (Hash)

    A place to store the results of the parallel responses.

See Also:

  • See the Readme for more examples.


52
53
54
55
56
57
# File 'lib/orchestrate/application.rb', line 52

def in_parallel(&block)
  @inside_parallel = true
  results = client.in_parallel(&block)
  @inside_parallel = nil
  results
end

#inside_parallel?true, false

is the Application currently inside a block from #in_parallel??

Returns:

  • (true, false)


61
62
63
# File 'lib/orchestrate/application.rb', line 61

def inside_parallel?
  !! @inside_parallel
end

#perform(api_method, *args) ⇒ Object

Perform a request against the client.

Parameters:

  • api_method (Symbol)

    The method on the client to call

  • args (#to_s, #to_json, Hash)

    The arguments for the method being called.

Returns:

  • Orchestrate::API::Response



69
70
71
# File 'lib/orchestrate/application.rb', line 69

def perform(api_method, *args)
  client.send(api_method, *args)
end

#to_sObject Also known as: inspect

Returns a pretty-printed representation of the application.

Returns:

  • a pretty-printed representation of the application.



74
75
76
# File 'lib/orchestrate/application.rb', line 74

def to_s
  "#<Orchestrate::Application api_key=#{api_key[0..7]}...>"
end