blockspring-cli 0.0.7 → 0.0.8

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: 1b8d67e4863e50ee8e4a30a578a48219d235cf45
4
- data.tar.gz: 384d2d94c4f5bd9840e23f33a81ccee172f2d843
3
+ metadata.gz: 2199ec07ab37e2240a7a71926da6987f3c79d919
4
+ data.tar.gz: 3995e24e9d19f65b51a496256bb822e825ff6201
5
5
  SHA512:
6
- metadata.gz: b8710bcadab9fc2f74c045bbbf8e955e83957990f3d972999810d89a7369c9b1ea489f43eb1983a93a35c4d604c60c194d308b8794b8943c6548e51b31518977
7
- data.tar.gz: 563e030d5c09d30f01e8b9878045fb38fcb05f21171db4df071df5d741ddab5b13386de78b6662322dcb22c8d53f541ba3a8d420e428d097820493f536d12f80
6
+ metadata.gz: b1a4f5467e6967052800e08ea77bdc7ccfdf992efdd185cfa42989b16ff26da4374efdbfca22d86119c3fd79f98b09f4d97ca947dca165549ff109130e998351
7
+ data.tar.gz: 803d0d6c3086a62248dafa2168294d8e03ef1e8d53b135588394f7c605a38373f40b90fdf4a00351efcb933cb40e9a608f72b05a62c9b23ce4e3397655cfda92
data/.editorconfig ADDED
@@ -0,0 +1,12 @@
1
+ # EditorConfig is awesome: http://EditorConfig.org
2
+
3
+ # top-most EditorConfig file
4
+ root = true
5
+
6
+ # Unix-style newlines with a newline ending every file
7
+ [*]
8
+ end_of_line = lf
9
+ insert_final_newline = true
10
+ indent_style = space
11
+ indent_size = 2
12
+ trim_trailing_whitespace = true
data/README.md CHANGED
@@ -10,23 +10,23 @@ Install via command line:
10
10
 
11
11
  ## Usage
12
12
 
13
- ### Login with your api.blockspring.com account.
13
+ #### Login with your api.blockspring.com account.
14
14
  ```bash
15
15
  blockspring login
16
16
  ```
17
17
 
18
- ### Create a new block
18
+ #### Create a new block
19
19
  ```bash
20
20
  blockspring new js "My new JS block"
21
21
  cd my-new-js-block
22
22
  ```
23
23
 
24
- ### Edit your function
24
+ #### Edit your function
25
25
  ```bash
26
26
  echo "console.log('hi');" > block.js
27
27
  ```
28
28
 
29
- ### Push
29
+ #### Push
30
30
  ```bash
31
31
  blockspring push
32
32
  ```
@@ -22,6 +22,8 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "rake"
23
23
 
24
24
  spec.add_dependency "netrc", "~> 0.8.0"
25
- spec.add_dependency "rest-client", "= 1.7.2"
26
- spec.add_dependency "json", "~> 1.8.1"
25
+ spec.add_dependency "rest-client", "> 1.6.0"
26
+ spec.add_dependency "json", "~> 1.8.1"
27
+ spec.add_dependency "launchy", "~> 2.4.2"
28
+ spec.add_dependency "blockspring", "> 0.0.0"
27
29
  end
@@ -5,12 +5,12 @@ class Blockspring::CLI::Auth
5
5
  include Blockspring::CLI::Helpers
6
6
 
7
7
  def host
8
- ENV['BLOCKSPRING_API_HOST'] || 'localhost:3000'
8
+ ENV['BLOCKSPRING_API_HOST'] || 'api.blockspring.com'
9
9
  end
10
10
 
11
11
  # TODO: change to https
12
12
  def base_url
13
- protocol = ENV['BLOCKSPRING_API_PROTOCOL'] || 'http'
13
+ protocol = ENV['BLOCKSPRING_API_PROTOCOL'] || 'https'
14
14
  "#{protocol}://#{host}"
15
15
  end
16
16
 
@@ -131,7 +131,7 @@ class Blockspring::CLI::Auth
131
131
  end
132
132
  end
133
133
 
134
- def netrc # :nodoc:
134
+ def netrc
135
135
  @netrc ||= begin
136
136
  File.exists?(netrc_path) && Netrc.read(netrc_path)
137
137
  rescue => error
@@ -1,4 +1,5 @@
1
1
  require "blockspring/cli/command/base"
2
+ require "launchy"
2
3
 
3
4
  # manipulate blocks (get, push, pull, new)
4
5
  #
@@ -46,7 +47,7 @@ class Blockspring::CLI::Command::Block < Blockspring::CLI::Command::Base
46
47
  # TODO: ensure valid config
47
48
  puts "Pulling #{config_json['user']}/#{config_json['id']}"
48
49
  block = get_block(config_json['id'])
49
- save_block_files(block, '.')
50
+ save_block_files(block, '.', 'Pulling')
50
51
  puts "Done."
51
52
  end
52
53
 
@@ -63,11 +64,25 @@ class Blockspring::CLI::Command::Block < Blockspring::CLI::Command::Base
63
64
  #
64
65
  def push
65
66
  _user, key = Blockspring::CLI::Auth.get_credentials
67
+
68
+ unless File.exists?('blockspring.json')
69
+ return error('blockspring.json file not found')
70
+ end
71
+
66
72
  config_text = File.read('blockspring.json')
67
73
  config_json = JSON.parse(config_text)
68
- # TODO: check for language
74
+
75
+ if config_json['language'].nil?
76
+ return error('You must declare a language in your blockspring.json file.')
77
+ end
78
+
69
79
  # language could eventually be js:0.10.x or py:3 or ruby:MRI-2.0
70
80
  script_file = "block.#{config_json['language'].split(':')[0]}"
81
+
82
+ unless File.exists?(script_file)
83
+ return error("#{script_file} file not found")
84
+ end
85
+
71
86
  script = File.read(script_file)
72
87
 
73
88
  payload = {
@@ -75,14 +90,23 @@ class Blockspring::CLI::Command::Block < Blockspring::CLI::Command::Base
75
90
  config: config_json
76
91
  }
77
92
 
93
+ if @args.include? '--force'
94
+ payload['force'] = true
95
+ end
96
+
78
97
  if config_json['id']
79
98
  uri = "#{Blockspring::CLI::Auth.base_url}/cli/blocks/#{config_json['id']}"
80
99
  else
81
100
  uri = "#{Blockspring::CLI::Auth.base_url}/cli/blocks"
82
101
  end
83
- response = RestClient.post uri, payload.to_json, :content_type => :json, :accept => :json, params: { api_key: key }, user_agent: Blockspring::CLI.user_agent
84
- json_response = JSON.parse(response.to_str)
85
- save_block_files(json_response, '.')
102
+
103
+ begin
104
+ response = RestClient.post uri, payload.to_json, :content_type => :json, :accept => :json, params: { api_key: key }, user_agent: Blockspring::CLI.user_agent
105
+ json_response = JSON.parse(response.body)
106
+ save_block_files(json_response, '.', 'Syncronizing')
107
+ rescue RestClient::Exception => msg
108
+ error(msg.inspect)
109
+ end
86
110
  end
87
111
 
88
112
  # block:new LANGUAGE "Block Name"
@@ -103,25 +127,38 @@ class Blockspring::CLI::Command::Block < Blockspring::CLI::Command::Base
103
127
  language = @args[0]
104
128
  name = @args[1]
105
129
 
106
- block = {}
130
+ begin
107
131
 
108
- block['code'] = ""
132
+ block = get_template(language)
109
133
 
110
- block['config'] = {
111
- "user" => user,
112
- "title" => name,
113
- "description" => '',
114
- "parameters" => {},
115
- "is_public" => false,
116
- "language" => language
117
- }
134
+ block['config']['title'] = name
118
135
 
119
- dir_name = create_block_directory(block)
120
- if dir_name
121
- save_block_files(block, dir_name)
136
+ dir_name = create_block_directory(block)
137
+ if dir_name
138
+ save_block_files(block, dir_name, 'Creating')
139
+ end
140
+ rescue RestClient::ResourceNotFound => msg
141
+ error("The language '#{language}' is not supported by Blockspring.")
142
+ rescue RestClient::Exception => msg
143
+ error(msg.inspect)
144
+ end
145
+ end
146
+
147
+ def open
148
+ config_text = File.read('blockspring.json')
149
+ config_json = JSON.parse(config_text)
150
+
151
+ user = config_json['user']
152
+ block_id = config_json['id']
153
+
154
+ uri = "#{Blockspring::CLI::Auth.base_url}/#{user}/#{block_id}"
155
+
156
+ Launchy.open( uri ) do |exception|
157
+ puts "Attempted to open #{uri} and failed because #{exception}"
122
158
  end
123
159
  end
124
160
 
161
+ alias_command "open", "block:open"
125
162
  alias_command "get", "block:get"
126
163
  alias_command "pull", "block:pull"
127
164
  alias_command "push", "block:push"
@@ -136,6 +173,12 @@ protected
136
173
  JSON.parse(response.to_str)
137
174
  end
138
175
 
176
+ def get_template(format)
177
+ _user, key = Blockspring::CLI::Auth.get_credentials
178
+ response = RestClient.get "#{Blockspring::CLI::Auth.base_url}/cli/templates/#{format}", params: { api_key: key }, user_agent: Blockspring::CLI.user_agent
179
+ JSON.parse(response.to_str)
180
+ end
181
+
139
182
  def create_block_directory(block)
140
183
 
141
184
  dir_name = get_block_directory(block)
@@ -160,15 +203,22 @@ protected
160
203
  end
161
204
  end
162
205
 
163
- def save_block_files(block, dir_name)
164
- # create script file
206
+ def save_block_script(block, dir_name, action='Syncing')
165
207
  script_file = File.join(dir_name, "block.#{block['config']['language'].split(':')[0]}")
166
- puts "Syncing script file #{script_file}"
208
+ puts "#{action} script file #{script_file}"
167
209
  File.open(script_file, 'w') { |file| file.write(block['code']) }
210
+ end
168
211
 
169
- # create config file
212
+ def save_block_config(block, dir_name, action='Syncing')
170
213
  config_file = File.join(dir_name, "blockspring.json")
171
- puts "Syncing config file #{config_file}"
214
+ puts "#{action} config file #{config_file}"
172
215
  File.open(config_file, 'w') { |file| file.write(JSON.pretty_generate(block['config']) + "\n") }
173
216
  end
217
+
218
+ def save_block_files(block, dir_name, action='Syncing')
219
+ # create script file
220
+ save_block_script(block, dir_name, action)
221
+ # create config file
222
+ save_block_config(block, dir_name, action)
223
+ end
174
224
  end
@@ -54,6 +54,19 @@ class Blockspring::CLI::Command::Run < Blockspring::CLI::Command::Base
54
54
  # $ blockspring run:remote jtokoph/aasdfj332flk3 --zip-code=94110
55
55
  #
56
56
  def remote
57
- error('not yet implimented')
57
+ require 'blockspring'
58
+
59
+ _, key = Blockspring::CLI::Auth.get_credentials
60
+
61
+ block_id = @args[0]
62
+
63
+ myBlock = lambda do |request, response|
64
+ response = Blockspring.run(block_id, request.params, key)
65
+
66
+ # TODO: don't autoparse the json in the library, I want the raw json
67
+ puts response.to_json
68
+ end
69
+
70
+ Blockspring.define(myBlock)
58
71
  end
59
72
  end
@@ -1,5 +1,5 @@
1
1
  module Blockspring
2
2
  module CLI
3
- VERSION = "0.0.7"
3
+ VERSION = "0.0.8"
4
4
  end
5
5
  end
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.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blockspring
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-25 00:00:00.000000000 Z
11
+ date: 2014-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -56,16 +56,16 @@ dependencies:
56
56
  name: rest-client
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '='
59
+ - - ">"
60
60
  - !ruby/object:Gem::Version
61
- version: 1.7.2
61
+ version: 1.6.0
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '='
66
+ - - ">"
67
67
  - !ruby/object:Gem::Version
68
- version: 1.7.2
68
+ version: 1.6.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: json
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +80,34 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: 1.8.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: launchy
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 2.4.2
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 2.4.2
97
+ - !ruby/object:Gem::Dependency
98
+ name: blockspring
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.0.0
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.0.0
83
111
  description: This is the command line helper for blockspring
84
112
  email:
85
113
  - founders@blockspring.com
@@ -88,6 +116,7 @@ executables:
88
116
  extensions: []
89
117
  extra_rdoc_files: []
90
118
  files:
119
+ - ".editorconfig"
91
120
  - ".gitignore"
92
121
  - Gemfile
93
122
  - LICENSE.txt