Class: Blockspring::CLI::Command::Run

Inherits:
Base
  • Object
show all
Defined in:
lib/blockspring/cli/command/run.rb

Overview

set BLOCKSPRING_API_KEY environment variable and run block

Instance Attribute Summary

Attributes inherited from Base

#args, #options

Instance Method Summary collapse

Methods inherited from Base

#initialize, namespace

Methods included from Helpers

#display, #error, error_with_failure, error_with_failure=, #format_with_bang, #home_directory, #longest, #output_with_bang, #running_on_a_mac?, #running_on_windows?

Constructor Details

This class inherits a constructor from Blockspring::CLI::Command::Base

Instance Method Details

#indexObject

run:local COMMAND

set api key environment variable and run block

Automatically detects if local or remote Use run:local or run:remote to specify

Example:

$ blockspring run:local node block.js –zip-code=94110



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/blockspring/cli/command/run.rb', line 17

def index
  if ENV['BLOCKSPRING_API_KEY'].to_s.strip.empty?
    _, key = Blockspring::CLI::Auth.get_credentials
    if key
      ENV['BLOCKSPRING_API_KEY'] = key
    end
  end

  match = /([^\/]+\/)([^\/]+)/.match(@args[0])

  if(match and not File.exist?(@args[0]))
    remote
  else
    local
  end
end

#localObject

run:local COMMAND

set api key environment variable and run a local block

Example:

$ blockspring run:local node block.js –zip-code=94110



42
43
44
# File 'lib/blockspring/cli/command/run.rb', line 42

def local
  system(*@args)
end

#remoteObject

run:remote USER/BLOCKID

set api key environment variable and run a remote block

–argname=value …

# specify arguments for the block

Example:

$ blockspring run:remote jtokoph/aasdfj332flk3 –zip-code=94110



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/blockspring/cli/command/run.rb', line 56

def remote
  require 'blockspring'

  _, key = Blockspring::CLI::Auth.get_credentials

  block_id = @args[0]

  myBlock = lambda do |request, response|
    response = Blockspring.run(block_id, request.params, key)

    # TODO: don't autoparse the json in the library, I want the raw json
    puts response.to_json
  end

  Blockspring.define(myBlock)
end