blockspring 0.0.8 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +139 -15
- data/lib/blockspring.rb +1 -1
- data/lib/blockspring/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b8ab9e420b558bd558d99170c309107e2ca61d4
|
4
|
+
data.tar.gz: 4dd5631ac3ff7b68a93821a1ede92a424bc76d9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d79e1411ff725877b7837a232060dbf45359af428e837776455d8577eeadd36253e70900a613919171287c36ed271c9c1126cae488c361ff6f1153fb9163933
|
7
|
+
data.tar.gz: 38294d2c8ffc1bd2d24d83f955c8f7bb050291010ce848085648efb7366c3910217a45f09da0012230159b3e65cc62c8c41171ab37e3b9f7e43d5193578e5863
|
data/README.md
CHANGED
@@ -5,39 +5,163 @@ Ruby gem to assist in creating and running blocks (cloud functions) with Blocksp
|
|
5
5
|
http://rubygems.org/gems/blockspring
|
6
6
|
|
7
7
|
### Installation
|
8
|
+
To get started, we'll need ruby. If you don't have ruby on your machine, first visit https://www.ruby-lang.org/en/installation/ to install it.
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
Next:
|
11
|
+
|
12
|
+
$ gem install blockspring
|
13
|
+
|
14
|
+
### Getting started
|
12
15
|
|
13
|
-
### Example Usage
|
14
16
|
|
15
|
-
|
17
|
+
####Step 1: Write our block
|
18
|
+
First, in an empty directory we'll save the following code to a file called ```block.rb```.
|
16
19
|
```ruby
|
20
|
+
# save this block.rb file into an empty directory.
|
17
21
|
require 'blockspring'
|
18
22
|
|
19
23
|
myBlock = lambda do |request, response|
|
20
|
-
|
21
|
-
|
22
|
-
|
24
|
+
sum = request.params["num1"].to_f + request.params["num2"].to_f
|
25
|
+
|
26
|
+
response.addOutput("sum", sum)
|
23
27
|
|
24
|
-
|
28
|
+
response.end()
|
25
29
|
end
|
26
30
|
|
27
31
|
Blockspring.define(myBlock)
|
28
32
|
```
|
29
33
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
+
####Step 2: Test our block locally
|
35
|
+
Next, we'll test our block locally:
|
36
|
+
|
37
|
+
// pass parameters via stdin (recommended)
|
38
|
+
$ echo '{"num1":20, "num2": 50}' | ruby block.rb
|
34
39
|
|
35
40
|
or
|
36
41
|
|
37
|
-
|
38
|
-
|
42
|
+
// pass parameters via command-line arguments
|
43
|
+
$ ruby block.rb --num1=20 --num2=50
|
44
|
+
|
45
|
+
Our response should be:
|
46
|
+
|
47
|
+
$ {"_blockspring_spec":true,"_errors":[],"sum":70.0}
|
48
|
+
|
49
|
+
Looks like our block can add!
|
50
|
+
|
51
|
+
####Step 3: Deploy our block
|
52
|
+
Now it's time to deploy our block. We can deploy our block with the [Blockspring online editor](https://api.blockspring.com/blocks/new) or with the [Blockspring-CLI tool](https://www.github.com/blockspring/blockspring-cli). Let's try out the command-line tool.
|
53
|
+
|
54
|
+
We'll need to login with Blockspring so if you don't have a blockspring account, visit https://api.blockspring.com/users/sign_up.
|
55
|
+
|
56
|
+
Run the following commands in the same directory as your ```block.rb``` file:
|
57
|
+
|
58
|
+
// Install the cli tool (make sure you have ruby installed)
|
59
|
+
$ gem install blockspring-cli
|
60
|
+
|
61
|
+
// Login to blockspring
|
62
|
+
$ blockspring login
|
63
|
+
|
64
|
+
// Deploy our block
|
65
|
+
$ blockspring push
|
66
|
+
|
67
|
+
Our block is deployed. That was easy.
|
68
|
+
|
69
|
+
Blockspring generated a ```blockspring.json``` file in our working directory along the way. Find the ```user``` (our username) and ```id``` (our block's id) parameters in this file, and let's run our block from the cloud:
|
70
|
+
|
71
|
+
$ echo '{"num1":20, "num2": 50}' | blockspring run <user>/<id>
|
72
|
+
|
73
|
+
We should get back the same result as when we ran the block locally:
|
74
|
+
|
75
|
+
$ {"_blockspring_spec":true,"_errors":[],"sum":70.0}
|
76
|
+
|
77
|
+
####Step 4: Customize our block
|
78
|
+
The final step is to make our block a bit more usable. Let's open up ```blockspring.json``` and paste in the following.
|
79
|
+
|
80
|
+
<b>Note: some values like the id, user, language, updated_at, and created_at shouldn't be changed.</b>
|
81
|
+
|
82
|
+
```json
|
83
|
+
{
|
84
|
+
"id": DONT_CHANGE_THIS,
|
85
|
+
"user": DONT_CHANGE_THIS,
|
86
|
+
"title": "Summer",
|
87
|
+
"description": "A basic block to sum two numbers",
|
88
|
+
"parameters": [
|
89
|
+
{
|
90
|
+
"type": "number",
|
91
|
+
"label": "Number 1",
|
92
|
+
"parameter_name": "num1",
|
93
|
+
"default": 50,
|
94
|
+
"help_text": "Our first number to sum."
|
95
|
+
},
|
96
|
+
{
|
97
|
+
"type": "number",
|
98
|
+
"label": "Number 2",
|
99
|
+
"parameter_name": "num2",
|
100
|
+
"default": 20,
|
101
|
+
"help_text": "Our second number to sum."
|
102
|
+
}
|
103
|
+
],
|
104
|
+
"is_public": true,
|
105
|
+
"language": DONT_CHANGE_THIS,
|
106
|
+
"updated_at": DONT_CHANGE_THIS,
|
107
|
+
"created_at": DONT_CHANGE_THIS
|
108
|
+
}
|
39
109
|
```
|
40
110
|
|
111
|
+
Now let's push our block again to update it and then we'll open it up in Blockspring.
|
112
|
+
|
113
|
+
$ blockspring push
|
114
|
+
$ blockspring open
|
115
|
+
|
116
|
+
Voila! We set a title, description, and info about our block's parameters so that Blockspring could generate a simple UI. To find out more about parameters and UI input types, see here: https://api.blockspring.com/documentation.
|
117
|
+
|
118
|
+
<br/>
|
119
|
+
|
120
|
+
### API in Detail
|
121
|
+
|
122
|
+
######DEFINE
|
123
|
+
```Blockspring.define(function_name)``` accepts a single parameter: the name of the function we're defining in our block.
|
124
|
+
|
125
|
+
######RUN
|
126
|
+
```Blockspring.run(block_id, data, [api_key])``` accepts three parameters:
|
127
|
+
- ```block_id```: the block id that you'd like to run remotely.
|
128
|
+
- ```data```: a hash of keys that serve as inputs to the block you're running remotely.
|
129
|
+
- ```api_key```: our api_key found on Blockspring.com. This is an optional parameter. Without an api_key we'll rate limited to 10 calls per minute. If we're running ```Blockspring.run``` from an IDE, we should include an api_key. If we're including a ```Blockspring.run``` within our defined block, we don't need to include the api_key.
|
130
|
+
|
131
|
+
######Request
|
132
|
+
- ```request.params```: a hash of inputs being sent into our block.
|
133
|
+
- ```request.getErrors()```: parse all the errors being input into our block.
|
134
|
+
|
135
|
+
######Response
|
136
|
+
- ```response.addOutput(key, value)```: add a key and value to the output of our block.
|
137
|
+
- ```response.addFileOutput(key, path_to_file)```: add a file to the output of our block.
|
138
|
+
- ```response.addErrorOutput(title, [message])```: add an error message. Message is an optional parameter.
|
139
|
+
- ```response.end()```: call this at the end of our block to print out the results correctly.
|
140
|
+
|
141
|
+
Here's a sample block that touches on each function in the API:
|
142
|
+
|
143
|
+
```ruby
|
144
|
+
# save this block.rb file into an empty directory.
|
145
|
+
require 'blockspring'
|
146
|
+
|
147
|
+
myBlock = lambda do |request, response|
|
148
|
+
if request.getErrors().length > 0
|
149
|
+
response.addErrorOutput("Errors in request", "Our block ran even though errors were passed in through request.")
|
150
|
+
end
|
151
|
+
|
152
|
+
File.open("truth.txt", 'w') { |file| file.write("I <3 blockspring!") }
|
153
|
+
response.addFileOutput("my_file", "truth.txt")
|
154
|
+
|
155
|
+
sentiment = Blockspring.run("pkpp1233/6dd22564137f10b8108ec6c8f354f031", {"text" => "hey there, this is so much fun!"})
|
156
|
+
response.addOutput("sentiment", sentiment["polarity"])
|
157
|
+
response.end()
|
158
|
+
end
|
159
|
+
|
160
|
+
Blockspring.define(myBlock)
|
161
|
+
```
|
162
|
+
|
163
|
+
Try a ```blockspring push``` and ```blockspring open``` and check out the response using the UI.
|
164
|
+
|
41
165
|
### License
|
42
166
|
|
43
167
|
MIT
|
data/lib/blockspring.rb
CHANGED
@@ -151,7 +151,7 @@ module Blockspring
|
|
151
151
|
def addFileOutput(name, filepath)
|
152
152
|
filename = File.basename(filepath)
|
153
153
|
b64_file_contents = Base64.strict_encode64(File.read(filepath))
|
154
|
-
mime_type_object = MIME::Types.of(filename).
|
154
|
+
mime_type_object = MIME::Types.of(filename).last
|
155
155
|
mime_type = mime_type_object ? mime_type_object.content_type : nil
|
156
156
|
|
157
157
|
@result[name] = {
|
data/lib/blockspring/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blockspring
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Don Pinkus
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-
|
13
|
+
date: 2014-11-16 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|