Class: TarPipe

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

Overview

This class encapsulates the TarPipe funcionality

Defined Under Namespace

Classes: NoWorkflowKey

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key = "") ⇒ TarPipe

The key is optional



27
28
29
30
31
# File 'lib/tarpipe.rb', line 27

def initialize(key = "")
  @key = key
  @endpoint = 'rest.receptor.tarpipe.net'
  @endpoint_port = 8000
end

Instance Attribute Details

#endpointObject

If we want to change the endpoint



18
19
20
# File 'lib/tarpipe.rb', line 18

def endpoint
  @endpoint
end

#endpoint_portObject

If we want to change the endpoint



18
19
20
# File 'lib/tarpipe.rb', line 18

def endpoint_port
  @endpoint_port
end

#keyObject

This acessor allows the user to select the worflow key anytime



21
22
23
# File 'lib/tarpipe.rb', line 21

def key
  @key
end

Instance Method Details

#upload(params = {}) ⇒ Object

Makes a call to a workflow. All the parameters are optional:

:title a title
:body  a body
:image a fill path for an existing file

Raises:



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/tarpipe.rb', line 37

def upload(params = {})
  @key = params[:key] if params[:key]
  raise NoWorkflowKey, "TarPipe API requires your Workflow Key" unless @key

  # Filter arguments
  args = [:title, :body].inject({}) do |res, arg|
    res[arg] = params[arg] if params[arg]
    res
  end

  # Filter files
  files = [:image].inject({}) do |res, arg|
    res[arg] = params[arg] if params[arg]
    res
  end

  post "/?key=#{@key}", args, files
end