blockspring 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ec78e591f079dee66f3eb2ae395457ca9bff491a
4
+ data.tar.gz: 26c21db69c8b4c945b44c551fe42d4a03ca1f824
5
+ SHA512:
6
+ metadata.gz: 3fc30637ddac01ad93f2b931e065aeca92a542687e8aa48dc6f1500c872a0f96a541910c8c2ae9ea3e3457caa3d3e3e20197e5c1e061b8e25a974fc8c5a9fd28
7
+ data.tar.gz: 4e81f5740e1917564204a0c58b40e3498677559c71605f0255468050daee5a036f61593be33a1de0408a94af44e1db163cc8d44ae333bbaa5205ac2d2ebbe3ca
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ .DS_Store
data/README.md ADDED
@@ -0,0 +1,18 @@
1
+ blockspring-ruby
2
+ ================
3
+
4
+ Gem for local dev with Blockspring.
5
+
6
+ http://rubygems.org/gems/blockspring
7
+
8
+ To use
9
+ ======
10
+ In a gemfile: `gem 'blockspring'`
11
+
12
+ Not in a gemfile:
13
+ ```
14
+ $ gem install 'blockspring'
15
+
16
+ # In a ruby script
17
+ require 'blockspring'
18
+ ```
@@ -0,0 +1,22 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'blockspring/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'blockspring'
7
+ spec.version = Blockspring::VERSION
8
+ spec.date = '2014-10-22'
9
+ spec.summary = "This gem lets you locally define a Blockspring function."
10
+ spec.description = "Gem for defining Blockspring functions locally."
11
+ spec.authors = ["Don Pinkus", "Paul Katsen", "Jason Tokoph"]
12
+ spec.email = 'founders@blockspring.com'
13
+ spec.files = `git ls-files -z`.split("\x0")
14
+ spec.homepage = 'https://www.blockspring.com'
15
+ spec.license = 'MIT'
16
+
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.6"
20
+
21
+ spec.add_dependency "rest-client", "= 1.6.7"
22
+ end
@@ -0,0 +1,85 @@
1
+ require 'rest_client'
2
+ require 'json'
3
+ require 'base64'
4
+ require 'mime/types'
5
+
6
+ module Blockspring
7
+ def self.run(block, data)
8
+ api_key = ENV['BLOCKSPRING_API_KEY']
9
+
10
+ if(!api_key)
11
+ raise "BLOCKSPRING_API_KEY environment variable not set"
12
+ end
13
+
14
+ block_parts = block.split("/")
15
+ block = block_parts[block_parts.length - 1]
16
+
17
+ response = RestClient.post "https://sender.blockspring.com/api_v1/blocks/#{block}?api_key=#{api_key}", data.to_json, :content_type => :json, :accept => :json
18
+
19
+ body = JSON.parse(response.body)
20
+
21
+ begin
22
+ body["results"] = JSON.parse(body["results"])
23
+ return body
24
+ rescue
25
+ return body
26
+ end
27
+ end
28
+
29
+ def self.define(block)
30
+ @request = {
31
+ params: {}
32
+ }
33
+
34
+ # From STDIN
35
+ stdin = STDIN.tty? ? "{}" : $stdin.read
36
+ stdin_params = JSON.parse(stdin)
37
+
38
+ @request[:params] = stdin_params
39
+
40
+ # From sysargs
41
+ sys_args = Hash[ ARGV.flat_map{|s| s.scan(/--?([^=\s]+)(?:=(\S+))?/) } ]
42
+
43
+ sys_args.each do |param_name, param_value|
44
+ @request[:params][param_name] = param_value
45
+ end
46
+
47
+ # Set response
48
+ @response = Response.new
49
+
50
+ block.call(@request, @response)
51
+ end
52
+
53
+ class Response
54
+ def initialize
55
+ @result = {
56
+ data: {},
57
+ files: {},
58
+ errors: nil
59
+ }
60
+ end
61
+
62
+ def addOutput(name, value)
63
+ @result[:data][name] = value
64
+ return self
65
+ end
66
+
67
+ def addFileOutput(name, filepath)
68
+ filename = File.basename(filepath)
69
+ b64_file_contents = Base64.encode64(File.read(filepath))
70
+ mime_type_object = MIME::Types.of(filename).first
71
+ mime_type = mime_type_object ? mime_type_object.content_type : nil
72
+
73
+ @result[:files][name] = {
74
+ filename: filename,
75
+ mimeType: mime_type,
76
+ data: b64_file_contents
77
+ }
78
+ return self
79
+ end
80
+
81
+ def end
82
+ puts @result.to_json
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,3 @@
1
+ module Blockspring
2
+ VERSION = "0.0.3"
3
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: blockspring
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Don Pinkus
8
+ - Paul Katsen
9
+ - Jason Tokoph
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2014-10-22 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: bundler
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: '1.6'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: '1.6'
29
+ - !ruby/object:Gem::Dependency
30
+ name: rest-client
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - '='
34
+ - !ruby/object:Gem::Version
35
+ version: 1.6.7
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - '='
41
+ - !ruby/object:Gem::Version
42
+ version: 1.6.7
43
+ description: Gem for defining Blockspring functions locally.
44
+ email: founders@blockspring.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - README.md
51
+ - blockspring.gemspec
52
+ - lib/blockspring.rb
53
+ - lib/blockspring/version.rb
54
+ homepage: https://www.blockspring.com
55
+ licenses:
56
+ - MIT
57
+ metadata: {}
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubyforge_project:
74
+ rubygems_version: 2.2.2
75
+ signing_key:
76
+ specification_version: 4
77
+ summary: This gem lets you locally define a Blockspring function.
78
+ test_files: []