Module: Polyseerio::SDK::Static

Defined in:
lib/sdk/factory.rb,
lib/sdk/static/find.rb,
lib/sdk/static/check.rb,
lib/sdk/static/index.rb,
lib/sdk/static/attach.rb,
lib/sdk/static/create.rb,
lib/sdk/static/detach.rb,
lib/sdk/static/remove.rb,
lib/sdk/static/update.rb,
lib/sdk/static/execute.rb,
lib/sdk/static/message.rb,
lib/sdk/static/trigger.rb,
lib/sdk/static/find_by_id.rb,
lib/sdk/static/find_by_name.rb

Overview

Static methods.

Constant Summary collapse

MAP =
Polyseerio::Helper.dir_proc_map(File.dirname(__FILE__), self)

Class Method Summary collapse

Class Method Details

.attachObject



5
6
7
8
# File 'lib/sdk/static/attach.rb', line 5

def self.attach
  proc do ||
  end
end

.checkObject



5
6
7
8
# File 'lib/sdk/static/check.rb', line 5

def self.check
  proc do ||
  end
end

.createObject



9
10
11
12
13
14
15
16
17
18
# File 'lib/sdk/static/create.rb', line 9

def self.create
  proc do |request, resource, copts, attributes, options = {}|
    options = Polyseerio::Helper.defaults(options, copts)

    eid = Helper.resolve_eid options
    uri = URL.get_resource_path(resource, eid: eid)

    request.post(uri, attributes)
  end
end

.detachObject



5
6
7
8
# File 'lib/sdk/static/detach.rb', line 5

def self.detach
  proc do ||
  end
end

.executeObject



5
6
7
8
# File 'lib/sdk/static/execute.rb', line 5

def self.execute
  proc do ||
  end
end

.factory(request, resource, statics = [], options = {}) ⇒ Object

Generates static functions.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/sdk/factory.rb', line 10

def self.factory(request, resource, statics = [], options = {})
  accumulator = Helper.accumulate_procs('static', MAP)

  statics = statics.each_with_object({}, &accumulator)

  # curry request, resource, and options
  statics.each_with_object(statics) do |(name, static), hash|
    if static.arity > 3
      hash[name] = static.curry.call(request, resource, options)
    end
  end

  statics
end

.findObject



8
9
10
11
12
13
14
15
16
17
# File 'lib/sdk/static/find.rb', line 8

def self.find
  # TODO; issue with arg arity on curry when all optional
  proc do |request, resource, _copts, _query, options = {}|
    eid = Helper.resolve_eid options
    uri = URL.get_resource_path(resource, eid: eid)

    # TODO: add query string
    request.get uri
  end
end

.find_by_idObject



9
10
11
12
13
14
15
16
17
18
# File 'lib/sdk/static/find_by_id.rb', line 9

def self.find_by_id
  proc do |request, resource, copts, id, options = {}|
    options = Polyseerio::Helper.defaults(options, copts)

    eid = Helper.resolve_eid options
    uri = URL.get_resource_path(resource, eid: eid, id: id)

    request.get uri
  end
end

.find_by_nameObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/sdk/static/find_by_name.rb', line 8

def self.find_by_name
  proc do |request, resource, copts, name, options = {}|
    options = Polyseerio::Helper.defaults(options, copts)

    name = "/name/#{name}"
    eid = Helper.resolve_eid options

    uri = URL.get_resource_path(resource, eid: eid)

    uri = if resource == Polyseerio::Enum::Resource::ENVIRONMENT
            "/environments#{name}"
          else
            "#{uri}#{name}"
          end

    request.get uri
  end
end

.messageObject



5
6
7
8
9
10
11
12
# File 'lib/sdk/static/message.rb', line 5

def self.message
  proc do |request, resource, _, attributes, options|
    eid = resolve_eid options
    uri = get_resource_path(resource, eid: eid)

    request.post(uri, attributes)
  end
end

.removeObject



9
10
11
12
13
14
15
16
17
18
# File 'lib/sdk/static/remove.rb', line 9

def self.remove
  proc do |request, resource, copts, id, options = {}|
    options = Polyseerio::Helper.defaults(options, copts)

    eid = Helper.resolve_eid options
    uri = URL.get_resource_path(resource, eid: eid, id: id)

    request.delete uri
  end
end

.triggerObject



5
6
7
8
9
10
11
12
13
14
# File 'lib/sdk/static/trigger.rb', line 5

def self.trigger
  proc do |request, resource, copts, id, payload = {}, options = {}| # rubocop:disable all
    options = Polyseerio::Helper.defaults(options, copts)

    eid = Helper.resolve_eid options
    uri = URL.get_resource_path(resource, eid: eid, id: id)

    request.post("#{uri}/trigger", payload)
  end
end

.updateObject



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/sdk/static/update.rb', line 5

def self.update
  # TODO: unit-test
  proc do |request, resource, copts, id, updates = {}, options = {}| # rubocop:disable all
    options = Polyseerio::Helper.defaults(options, copts)

    eid = Helper.resolve_eid options
    uri = URL.get_resource_path(resource, eid: eid, id: id)

    request.put(uri, updates)
  end
end