blockspring-cli 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.DS_Store +0 -0
- data/README.md +163 -21
- data/lib/blockspring/cli/auth.rb +9 -5
- data/lib/blockspring/cli/command/block.rb +24 -8
- data/lib/blockspring/cli/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: 292e435f1ec64d78ded1b4ac70d3bfa987ae6645
|
4
|
+
data.tar.gz: 17844302c5ef29a5192b41dbd378e54e9f0b0b5a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 616de4bda0e684004c6eb093a97f7e36077f883c76f5fe871d96d074acdbf87f19e32a42339c51c65d17c6a9b7d39db0b715edcfc0c3aa323cd99670373959b7
|
7
|
+
data.tar.gz: 3c8dddad60d3b0634089805bb1724cb9de2fa6f9c756632e79996d4759575dd376119df599b09648544dad4b0acf0de1f1414eed10b598d1c200d45e1be42e58
|
data/.DS_Store
CHANGED
Binary file
|
data/README.md
CHANGED
@@ -1,36 +1,178 @@
|
|
1
1
|
# Blockspring CLI
|
2
2
|
|
3
|
-
The Blockspring CLI is used to manage and
|
3
|
+
The Blockspring CLI is used to manage, run, and deploy cloud functions (we call them "blocks") from the command line.
|
4
4
|
|
5
|
-
|
5
|
+
Once deployed, you can use your blocks from just about anywhere. For more info, check out: https://www.blockspring.com.
|
6
6
|
|
7
|
-
|
7
|
+
## Getting Started
|
8
|
+
|
9
|
+
Let's deploy our first block in less than 60 seconds.
|
10
|
+
|
11
|
+
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.
|
12
|
+
|
13
|
+
#### Step 1: Install the Blockspring-CLI tool
|
8
14
|
|
9
15
|
$ gem install blockspring-cli
|
10
16
|
|
11
|
-
|
17
|
+
#### Step 2: Login to Blockspring
|
18
|
+
We'll need to login with our Blockspring account. No Blockspring account yet? Sign up here first: https://api.blockspring.com/users/sign_up.
|
19
|
+
|
20
|
+
$ blockspring login
|
21
|
+
Enter your Blockspring credentials.
|
22
|
+
Username or email: jason@example.com
|
23
|
+
Password (typing will be hidden):
|
24
|
+
You are logged in as jason.
|
25
|
+
|
26
|
+
#### Step 3: Create a new block
|
27
|
+
We can create blocks in ruby, python, javascript, php, or R (and more languages are coming soon). Let's create a ruby block since ruby is already installed on our machine.
|
28
|
+
|
29
|
+
$ blockspring new rb "My new Ruby block"
|
30
|
+
Creating directory my-new-ruby-block
|
31
|
+
Creating script file my-new-ruby-block/block.rb
|
32
|
+
Creating config file my-new-ruby-block/blockspring.json
|
33
|
+
|
34
|
+
#### Step 4: Deploy your block
|
35
|
+
Let's enter our new block's directory and deploy.
|
36
|
+
|
37
|
+
$ cd my-new-ruby-block
|
38
|
+
$ blockspring push
|
39
|
+
Syncronizing script file ./block.rb
|
40
|
+
Syncronizing config file ./blockspring.json
|
41
|
+
|
42
|
+
#### Step 5: Visit your block's homepage
|
43
|
+
Now that our block is now deployed we can visit its homepage to see it in action.
|
44
|
+
|
45
|
+
$ blockspring open
|
46
|
+
|
47
|
+
That's it! We've deployed our first block. To learn more about the Blockspring-CLI, check out the [API in Detail](#api-in-detail) section below. Otherwise, let's pick out our favorite language and start writing our own blocks.
|
48
|
+
|
49
|
+
######Language-Specific Libraries
|
50
|
+
<table>
|
51
|
+
<tr>
|
52
|
+
<th>If you prefer this language...</th>
|
53
|
+
<th>Use this library...</th>
|
54
|
+
</tr>
|
55
|
+
<tr>
|
56
|
+
<td>Ruby</td>
|
57
|
+
<td style="text-align: left"><a href="https://github.com/blockspring/blockspring.rb">https://github.com/blockspring/blockspring.rb</a></td>
|
58
|
+
</tr>
|
59
|
+
<tr>
|
60
|
+
<td>Python</td>
|
61
|
+
<td style="text-align: left"><a href="https://github.com/blockspring/blockspring.py">https://github.com/blockspring/blockspring.py</a></td>
|
62
|
+
</tr>
|
63
|
+
<tr>
|
64
|
+
<td>Javascript</td>
|
65
|
+
<td style="text-align: left"><a href="https://github.com/blockspring/blockspring.js">https://github.com/blockspring/blockspring.js</a></td>
|
66
|
+
</tr>
|
67
|
+
<tr>
|
68
|
+
<td>PHP</td>
|
69
|
+
<td style="text-align: left"><a href="https://github.com/blockspring/blockspring.php">https://github.com/blockspring/blockspring.php</a></td>
|
70
|
+
</tr>
|
71
|
+
<tr>
|
72
|
+
<td>R</td>
|
73
|
+
<td style="text-align: left"><a href="https://github.com/blockspring/blockspring.R">https://github.com/blockspring/blockspring.R</a></td>
|
74
|
+
</tr>
|
75
|
+
</table>
|
76
|
+
|
77
|
+
<br/>
|
78
|
+
## API in Detail
|
79
|
+
Let's explore the Blockspring-CLI tool API in detail.
|
80
|
+
|
81
|
+
####Authentication
|
82
|
+
######LOGIN
|
83
|
+
You must be logged in to run Blockspring-CLI tool commands.
|
84
|
+
|
85
|
+
$ blockspring login
|
86
|
+
|
87
|
+
######LOGOUT
|
88
|
+
|
89
|
+
$ blockspring logout
|
90
|
+
|
91
|
+
####Block Management
|
92
|
+
######GET
|
93
|
+
We can ```GET``` a block down to our local machine. The block will be saved in a new directory and can be edited or even executed locally.
|
94
|
+
|
95
|
+
$ blockspring get <block id>
|
96
|
+
|
97
|
+
Below is an example ```GET``` request for the following block: https://api.blockspring.com/pkpp1233/6dd22564137f10b8108ec6c8f354f031. The block id can be found directly in the URL.
|
98
|
+
|
99
|
+
$ blockspring get pkpp1233/6dd22564137f10b8108ec6c8f354f031
|
100
|
+
|
101
|
+
######NEW
|
102
|
+
To create a ```NEW``` block:
|
103
|
+
|
104
|
+
$ blockspring new <language> <block name>
|
105
|
+
|
106
|
+
Here are explicit commands to create a new block in each supported language:
|
107
|
+
|
108
|
+
// Ruby: creates dir w/ block.rb & blockspring.json
|
109
|
+
$ blockspring new rb "fun ruby block"
|
110
|
+
|
111
|
+
// Python: creates dir w/ block.py & blockspring.json
|
112
|
+
$ blockspring new py "fun python block"
|
113
|
+
|
114
|
+
// Javascript: creates dir w/ block.js & blockspring.json
|
115
|
+
$ blockspring new js "fun javascript block"
|
116
|
+
|
117
|
+
// PHP: creates dir w/ block.php & blockspring.json
|
118
|
+
$ blockspring new php "fun php block"
|
119
|
+
|
120
|
+
// R: creates dir w/ block.R & blockspring.json
|
121
|
+
$ blockspring new R "fun R block"
|
122
|
+
|
123
|
+
The ```NEW``` command creates a working directory for your block and populates that directory with two files: a ```block.*``` (asterisk is for your language of choice - file holds your function) and a ```blockspring.json``` (this file holds the block's configs and additional data).
|
124
|
+
|
125
|
+
######PULL
|
126
|
+
We can ```PULL``` a block's recent changes down to our machine. ```PULL``` is used from our block's working directory.
|
127
|
+
|
128
|
+
$ blockspring pull
|
129
|
+
|
130
|
+
Note: If the block isn't in a directory on our machine yet, we either need to use ```GET``` to retrieve it or ```NEW``` to create it.
|
131
|
+
|
132
|
+
######PUSH
|
133
|
+
We can ```PUSH``` a block's recent changes up to Blockspring. ```PUSH``` is used from our block's working directory.
|
134
|
+
|
135
|
+
$ blockspring push
|
136
|
+
|
137
|
+
######OPEN
|
138
|
+
|
139
|
+
We can ```OPEN``` our block's homepage on Blockspring. ```OPEN``` is used from our block's working directory.
|
140
|
+
|
141
|
+
$ blockspring open
|
142
|
+
|
143
|
+
####Executing Blocks from the Command Line
|
144
|
+
######RUN
|
145
|
+
We can execute our blocks directly from the command line with the ```RUN``` command. ```RUN``` can be used to execute blocks remotely, or to execute blocks locally on your machine. Blocks, whether they're executed in the cloud or locally, can easily pipe together with other command-line tools.
|
146
|
+
|
147
|
+
Let's execute a block remotely by passing parameters into stdin or via command-line arguments.
|
148
|
+
|
149
|
+
// execute with stdin (recommended).
|
150
|
+
$ echo '{"num1": 30, "num2": 50}' | blockspring run <block id>
|
151
|
+
|
152
|
+
// execute with args.
|
153
|
+
$ blockspring run <block id> --num1=30 --num2=50
|
154
|
+
|
155
|
+
Remember, a block id can be found directly in a block's URL. The block id for https://api.blockspring.com/pkpp1233/ce6c7c230d8a4ff4d22ae96654ca4bd2 is pkpp1233/ce6c7c230d8a4ff4d22ae96654ca4bd2. Try running the sum with this block id.
|
156
|
+
|
157
|
+
$ echo '{"num1": 30, "num2": 50}' | blockspring run pkpp1233/ce6c7c230d8a4ff4d22ae96654ca4bd2
|
158
|
+
|
159
|
+
######RUN:LOCAL
|
160
|
+
|
161
|
+
We can also run blocks locally on our computer. Let's do a ```GET``` request to a local directory and then use ```RUN:LOCAL``` to execute that block locally without sending any data to Blockspring.
|
12
162
|
|
13
|
-
|
14
|
-
|
15
|
-
blockspring
|
16
|
-
|
163
|
+
$ blockspring get pkpp1233/ce6c7c230d8a4ff4d22ae96654ca4bd2
|
164
|
+
$ cd summer-ce6c7c23
|
165
|
+
$ echo '{"num1": 30, "num2": 50}' | blockspring run:local python block.py
|
166
|
+
|
167
|
+
Note: To```RUN``` blocks locally, we need to have the proper runtimes and dependencies installed. This is a Blockspring WIP. To run the above example locally, we need to make sure we have the python runtime and the blockspring python library installed (see [Language-Specific Libraries](#language-specific-libraries)).
|
17
168
|
|
18
|
-
####
|
19
|
-
```bash
|
20
|
-
blockspring new js "My new JS block"
|
21
|
-
cd my-new-js-block
|
22
|
-
```
|
169
|
+
####Help
|
23
170
|
|
24
|
-
|
25
|
-
```bash
|
26
|
-
echo "console.log('hi');" > block.js
|
27
|
-
```
|
171
|
+
$ blockspring help
|
28
172
|
|
29
|
-
|
30
|
-
```bash
|
31
|
-
blockspring push
|
32
|
-
```
|
173
|
+
If ```HELP``` isn't particularly helpful for your problem, just email us: <a href="mailto:founders@blockspring.com">founders@blockspring.com</a>
|
33
174
|
|
175
|
+
<br/>
|
34
176
|
## License
|
35
177
|
|
36
178
|
MIT - see the license file.
|
data/lib/blockspring/cli/auth.rb
CHANGED
@@ -81,11 +81,15 @@ class Blockspring::CLI::Auth
|
|
81
81
|
end
|
82
82
|
|
83
83
|
def api_key(login, password)
|
84
|
-
response = RestClient.post "#{base_url}/cli/login", { login: login, password: password }, user_agent: Blockspring::CLI.user_agent
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
84
|
+
response = RestClient.post "#{base_url}/cli/login", { login: login, password: password }, user_agent: Blockspring::CLI.user_agent do |response, request, result, &block|
|
85
|
+
case response.code
|
86
|
+
when 200
|
87
|
+
response.to_str
|
88
|
+
when 401
|
89
|
+
error('Invalid username or password.')
|
90
|
+
else
|
91
|
+
error('login failed')
|
92
|
+
end
|
89
93
|
end
|
90
94
|
end
|
91
95
|
|
@@ -109,12 +109,17 @@ class Blockspring::CLI::Command::Block < Blockspring::CLI::Command::Base
|
|
109
109
|
uri = "#{Blockspring::CLI::Auth.base_url}/cli/blocks"
|
110
110
|
end
|
111
111
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
112
|
+
|
113
|
+
response = RestClient.post(uri, payload.to_json, :content_type => :json, :accept => :json, params: { api_key: key }, user_agent: Blockspring::CLI.user_agent) do |response, request, result, &block|
|
114
|
+
case response.code
|
115
|
+
when 200
|
116
|
+
json_response = JSON.parse(response.body)
|
117
|
+
save_block_files(json_response, '.', 'Syncronizing')
|
118
|
+
when 401
|
119
|
+
error('You must be logged in to push a block')
|
120
|
+
when 404
|
121
|
+
error('That block does not exist or you don\'t have permission to push to it')
|
122
|
+
end
|
118
123
|
end
|
119
124
|
end
|
120
125
|
|
@@ -136,6 +141,9 @@ class Blockspring::CLI::Command::Block < Blockspring::CLI::Command::Base
|
|
136
141
|
language = @args[0]
|
137
142
|
name = @args[1]
|
138
143
|
|
144
|
+
return error('You must specify a language') unless language
|
145
|
+
return error('You must specify a name for your block') unless name
|
146
|
+
|
139
147
|
begin
|
140
148
|
|
141
149
|
block = get_template(language)
|
@@ -178,8 +186,16 @@ protected
|
|
178
186
|
# TODO: move this to another file like 'api'
|
179
187
|
def get_block(block_id)
|
180
188
|
_user, key = Blockspring::CLI::Auth.get_credentials
|
181
|
-
response = RestClient.get
|
182
|
-
|
189
|
+
response = RestClient.get("#{Blockspring::CLI::Auth.base_url}/cli/blocks/#{block_id}", params: { api_key: key }, user_agent: Blockspring::CLI.user_agent) do |response, request, result, &block|
|
190
|
+
case response.code
|
191
|
+
when 200
|
192
|
+
JSON.parse(response.to_str)
|
193
|
+
when 404
|
194
|
+
error('That block does not exist or you don\'t have permission to access it')
|
195
|
+
else
|
196
|
+
error('Could not get block data from server')
|
197
|
+
end
|
198
|
+
end
|
183
199
|
end
|
184
200
|
|
185
201
|
def get_template(format)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blockspring-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Blockspring
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|