blockspring 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 34f953f0985abacfe0267dd28ea491c749659b92
4
- data.tar.gz: a9e79c12e18a67c0854727b6476e477635f83245
3
+ metadata.gz: 8b8ab9e420b558bd558d99170c309107e2ca61d4
4
+ data.tar.gz: 4dd5631ac3ff7b68a93821a1ede92a424bc76d9a
5
5
  SHA512:
6
- metadata.gz: 5fe7599db551fa8bcf7425284f4b22f8e6bb44a34046744145607f46df73e86ebd0cb4a4b5fbe2d5c8b8f86141916f0f71bab06c45927e84403f9660e477cf16
7
- data.tar.gz: 6648b684bce51dcf8369338a6b2530f07372a3850eb9081019b6204c15c41c548a2bf7d248fa2e8e3e6562f43b776e63be3c047e13852726951454a587ada914
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
- ```ruby
10
- gem install blockspring
11
- ```
10
+ Next:
11
+
12
+ $ gem install blockspring
13
+
14
+ ### Getting started
12
15
 
13
- ### Example Usage
14
16
 
15
- Save the following script to an example.rb file:
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
- sum = request.params["num1"].to_f + request.params["num2"].to_f
21
-
22
- response.addOutput("sum", sum)
24
+ sum = request.params["num1"].to_f + request.params["num2"].to_f
25
+
26
+ response.addOutput("sum", sum)
23
27
 
24
- response.end()
28
+ response.end()
25
29
  end
26
30
 
27
31
  Blockspring.define(myBlock)
28
32
  ```
29
33
 
30
- Then in your command line write:
31
- ```shell
32
- ruby example.rb --num1=20 --num2=50
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
- ```shell
38
- echo '{"num1":20, "num2": 50}' | ruby example.rb
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).first
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] = {
@@ -1,3 +1,3 @@
1
1
  module Blockspring
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
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.8
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-10-31 00:00:00.000000000 Z
13
+ date: 2014-11-16 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler