hse 0.1.16 → 0.1.17
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.
- data/hse.gemspec +3 -2
- data/lib/hse/cli.rb +5 -4
- data/lib/hse/remote.rb +15 -29
- data/lib/hse/version.rb +1 -1
- metadata +23 -7
data/hse.gemspec
CHANGED
@@ -26,8 +26,9 @@ Gem::Specification.new do |gem|
|
|
26
26
|
|
27
27
|
gem.add_runtime_dependency(%q<json>, ["~> 1.7.5"])
|
28
28
|
gem.add_runtime_dependency(%q<mime-types>, ["~> 1.16"])
|
29
|
-
gem.add_runtime_dependency(%q<
|
30
|
-
#gem.add_runtime_dependency(%q<
|
29
|
+
gem.add_runtime_dependency(%q<addressable>)
|
30
|
+
#gem.add_runtime_dependency(%q<typhoeus>, ["~> 0.6.3"])
|
31
|
+
gem.add_runtime_dependency(%q<rest-client>)
|
31
32
|
gem.add_runtime_dependency(%q<thor>, ["~> 0.15"])
|
32
33
|
gem.add_runtime_dependency(%q<uuidtools>, ["~> 2.1"])
|
33
34
|
# gem.add_runtime_dependency(%q<redcarpet>, ["~> 2.2.2"])
|
data/lib/hse/cli.rb
CHANGED
@@ -2,7 +2,8 @@
|
|
2
2
|
require 'thor'
|
3
3
|
require 'thor/actions'
|
4
4
|
require 'uuidtools'
|
5
|
-
require 'typhoeus'
|
5
|
+
#require 'typhoeus'
|
6
|
+
require 'rest_client'
|
6
7
|
require 'pp'
|
7
8
|
# require 'redcarpet'
|
8
9
|
|
@@ -86,9 +87,9 @@ module Hse
|
|
86
87
|
# puts "_ID = #{_id} - #{uuid}"
|
87
88
|
# end
|
88
89
|
|
89
|
-
desc 'get [
|
90
|
-
def get(
|
91
|
-
remote(env).
|
90
|
+
desc 'get [ID]', 'get doc by id'
|
91
|
+
def get(id = false, env = 'default')
|
92
|
+
remote(env).get_id id
|
92
93
|
end
|
93
94
|
|
94
95
|
desc 'user [EMAIL] push=false', 'get/push user by email'
|
data/lib/hse/remote.rb
CHANGED
@@ -6,28 +6,12 @@ module Hse
|
|
6
6
|
def initialize(app_dir, env = 'default') #, config_path = nil)
|
7
7
|
self.env = env
|
8
8
|
self.app_dir = File.expand_path(app_dir) + '/'
|
9
|
-
#self.config_path = config_path
|
10
|
-
#load_config
|
11
9
|
load_couchapprc
|
12
10
|
end
|
13
11
|
|
14
|
-
# def config_path=(config_path)
|
15
|
-
# @config_path = config_path || File.join(app_dir, 'config.js')
|
16
|
-
# end
|
17
|
-
|
18
|
-
# def load_config
|
19
|
-
# if File.readable?(config_path)
|
20
|
-
# @config = JSON.parse(File.read(config_path))
|
21
|
-
# else
|
22
|
-
# raise "Could not find config at '#{config_path}'. Run `soca init`"
|
23
|
-
# end
|
24
|
-
# end
|
25
|
-
|
26
12
|
def load_couchapprc
|
27
13
|
@config ||= {}
|
28
14
|
@config['couchapprc'] = JSON.parse(File.read(File.join(app_dir, '.couchapprc')))
|
29
|
-
puts "COUCHAPPRC #{@config['couchapprc']}"
|
30
|
-
#run_hooks!(:after_load_couchapprc)
|
31
15
|
end
|
32
16
|
|
33
17
|
def db_url
|
@@ -36,26 +20,29 @@ module Hse
|
|
36
20
|
else
|
37
21
|
env_config = config['couchapprc']['env'][env]
|
38
22
|
raise "No such env: #{env}" unless env_config && env_config['db']
|
39
|
-
puts "
|
23
|
+
puts "db_url #{env_config['db']}"
|
40
24
|
env_config['db']
|
41
25
|
end
|
42
26
|
end
|
43
27
|
|
44
|
-
def
|
45
|
-
path = "#{db_url}/#{
|
46
|
-
response =
|
47
|
-
|
48
|
-
|
28
|
+
def get_id id
|
29
|
+
path = "#{db_url}/#{id}?include_docs=true"
|
30
|
+
response = RestClient.get path, :content_type => :json, :accept => :json # rescue nil
|
31
|
+
return "no _id #{id}" unless response.code == 200
|
32
|
+
result = JSON.parse(response.body)
|
33
|
+
response.code == 200 ? result : nil
|
49
34
|
end
|
50
35
|
|
51
36
|
def user email, push
|
52
37
|
server = "#{db_url}".split("/")[0..-2].join("/")
|
53
38
|
path = "#{server}/_users/org.couchdb.user:#{email}"
|
54
|
-
|
55
|
-
#
|
39
|
+
puts "USER PATH #{path}"
|
40
|
+
#response = Typhoeus::Request.get(path)
|
41
|
+
response = RestClient.get path, :content_type => :json, :accept => :json # rescue nil
|
42
|
+
puts "GET Response: #{response.code} #{response.body[0..200]}"
|
56
43
|
response.code == 200 ? response.body : nil
|
57
44
|
user = JSON.parse(response.body)
|
58
|
-
|
45
|
+
pp user
|
59
46
|
return unless push
|
60
47
|
# curl -vX PUT $HOST/_users/org.couchdb.user:bob -d '{"name":"bob", "password":"bobspassword", "roles":[], "type":"user"}' -H "Content-Type: application/json"
|
61
48
|
picture = email.split("@").first
|
@@ -65,16 +52,15 @@ module Hse
|
|
65
52
|
json = newuser.to_json
|
66
53
|
path = "#{server}/_users/#{id}"
|
67
54
|
#headers = {"Content-Type" => "application/json"}
|
68
|
-
response = Typhoeus::Request.put(path, body:json)
|
55
|
+
#response = Typhoeus::Request.put(path, body:json)
|
69
56
|
puts "PUT Response: #{response.code} #{response.body[0..200]}"
|
70
57
|
end
|
71
58
|
|
72
59
|
def get_doc_revision doc
|
73
60
|
puts "getting current revision"
|
74
|
-
current =
|
61
|
+
current = get_id doc
|
75
62
|
if current
|
76
63
|
current_json = JSON.parse(current)
|
77
|
-
#self.revision = current_json['_rev']
|
78
64
|
puts "current revision: #{current_json['_rev']}"
|
79
65
|
end
|
80
66
|
current ? current_json['_rev'] : nil
|
@@ -84,7 +70,7 @@ module Hse
|
|
84
70
|
path = "#{db_url}/#{id}"
|
85
71
|
puts "remote: PUT path #{path}"
|
86
72
|
puts "remote: PUT body: #{body[0..80]} ..."
|
87
|
-
response = Typhoeus::Request.put(path, :body => body)
|
73
|
+
#response = Typhoeus::Request.put(path, :body => body)
|
88
74
|
puts "PUT Response: #{response.code} #{response.body[0..200]}"
|
89
75
|
response
|
90
76
|
end
|
data/lib/hse/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hse
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.17
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-06-
|
12
|
+
date: 2013-06-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: yard
|
@@ -108,21 +108,37 @@ dependencies:
|
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: '1.16'
|
110
110
|
- !ruby/object:Gem::Dependency
|
111
|
-
name:
|
111
|
+
name: addressable
|
112
112
|
requirement: !ruby/object:Gem::Requirement
|
113
113
|
none: false
|
114
114
|
requirements:
|
115
|
-
- -
|
115
|
+
- - ! '>='
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: 0
|
117
|
+
version: '0'
|
118
118
|
type: :runtime
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
none: false
|
122
122
|
requirements:
|
123
|
-
- -
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: rest-client
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
type: :runtime
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
124
140
|
- !ruby/object:Gem::Version
|
125
|
-
version: 0
|
141
|
+
version: '0'
|
126
142
|
- !ruby/object:Gem::Dependency
|
127
143
|
name: thor
|
128
144
|
requirement: !ruby/object:Gem::Requirement
|