refocus 0.1.3 → 0.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a6ed3e20b9196f523eba596e90b964b934c75821
4
- data.tar.gz: da43515dff536896a48386c0b0ce3253331a5cd3
3
+ metadata.gz: 29e511a576db53916cd93b5a32c1fbb62b2171e5
4
+ data.tar.gz: 975c4fa9a9ddd4935253e1b44d9e63cbef97f706
5
5
  SHA512:
6
- metadata.gz: 2d4d1a12437f12ab40e5e5fc65a95a3ead2c525afb063693ebeac013d4e70302e2f34a869197670cb49923157d3f0eb6f13c6bac0ab9e8a3b2823f7aa47b118a
7
- data.tar.gz: fc8fbc5ac39b097731656e94521bd704fa8a547f70dcd577727ab168df8baba37b54a4b054a19e184b91623e36d31610be5b46a9e048226171b534877f36ddb4
6
+ metadata.gz: 555c420afa099c429ec8e2aa4a235df161a2b9845f5aa5610423c3196a47578b77d82e46fb79476ceb8fa4ee8b37673cab1fa2609a9899a163fdb5fe7a67bd43
7
+ data.tar.gz: 8c0f72d975a9434ba1b857536ee7f541d90a46437bd0f0cd070c4e1b7586691db73823dedf01a4743a8e161f5cce447da7a74d72f634fe587165214556d3353e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- refocus (0.1.2)
4
+ refocus (0.1.3)
5
5
  clamp
6
6
  excon
7
7
 
data/README.md CHANGED
@@ -24,8 +24,6 @@ Or install it yourself as:
24
24
  ## Usage
25
25
 
26
26
  ### CLI
27
-
28
- Run
29
27
  ```
30
28
  Usage:
31
29
  refocus [OPTIONS] SUBCOMMAND [ARG] ...
@@ -43,19 +41,19 @@ Options:
43
41
 
44
42
  ### Library
45
43
 
46
- Refocus will pick up `REFOCUS_HOST` and `REFOCUS_API_TOKEN` environment vars if these are set.
44
+ Refocus will pick up `REFOCUS_URL` and `REFOCUS_API_TOKEN` environment vars if these are set.
47
45
  You can create a client like this in a `pry` or `irb` session, or in your ruby program:
48
46
 
49
47
  ```ruby
50
48
  require "refocus"
51
49
 
52
- # Using env vars. This will fail if REFOCUS_HOST and REFOCUS_API_TOKEN are unset:
50
+ # Using env vars. This will fail if REFOCUS_URLand REFOCUS_API_TOKEN are unset:
53
51
  refocus = Refocus.client
54
52
 
55
53
  # Doing it yourself:
56
54
  refocus = Refocus.client(url: "https://my.refocus.instance.com", token: "some-token-i-generated")
57
55
  ```
58
- ### Subjects
56
+ #### Subjects
59
57
 
60
58
  You can manage subjects like this:
61
59
 
@@ -73,7 +71,7 @@ refocus.subjects.all
73
71
  refocus.subjects.delete(name: "my-subject.child-subject")
74
72
  ```
75
73
 
76
- ### Aspects
74
+ #### Aspects
77
75
 
78
76
  You can manage aspects like this:
79
77
 
@@ -88,7 +86,7 @@ refocus.aspects.get(name: "my-aspect")
88
86
  refocus.aspects.delete(name: "my-aspect")
89
87
  ```
90
88
 
91
- ### Lenses
89
+ #### Lenses
92
90
 
93
91
  Lenses are not supported at this time.
94
92
 
data/lib/refocus.rb CHANGED
@@ -2,7 +2,7 @@ require "refocus/client"
2
2
  require "refocus/version"
3
3
 
4
4
  module Refocus
5
- def self.client(url: "https://#{ENV.fetch("REFOCUS_HOST")}", token: ENV.fetch("REFOCUS_API_TOKEN"))
5
+ def self.client(url: ENV.fetch("REFOCUS_URL"), token: ENV.fetch("REFOCUS_API_TOKEN"))
6
6
  Client.new(url: url, token: token)
7
7
  end
8
8
  end
data/lib/refocus/cli.rb CHANGED
@@ -6,4 +6,7 @@ module Refocus
6
6
  end
7
7
 
8
8
  require "refocus/cli/samples"
9
+ require "refocus/cli/resources"
10
+ require "refocus/cli/aspects"
11
+ require "refocus/cli/subjects"
9
12
 
@@ -0,0 +1,18 @@
1
+ module Refocus
2
+ class AspectsDeleteCommand< Clamp::Command
3
+ parameter "ASPECT", "aspect to delete"
4
+
5
+ def execute
6
+ refocus.aspects.delete(name: aspect)
7
+ end
8
+
9
+ def refocus
10
+ Refocus.client
11
+ end
12
+ end
13
+
14
+ Cli.class_eval do
15
+ subcommand "aspects:delete", "Delete an aspect", Refocus::AspectsDeleteCommand
16
+ end
17
+ end
18
+
@@ -0,0 +1,51 @@
1
+ require "refocus/cli"
2
+ require "json"
3
+ require "yaml"
4
+
5
+ module Refocus
6
+ class ResourcesSyncCommand < Clamp::Command
7
+
8
+ option(["-a", "--action"], "ACTION", "action to perform: create or update", default: "create") do |s|
9
+ (raise ArgumentError, "Invalid action: #{s}") unless %w{create update}.include?(s)
10
+ s.to_sym
11
+ end
12
+
13
+ def execute
14
+ subjects.each do |subject|
15
+ refocus.subjects.send(action, {
16
+ name: subject.fetch("name"),
17
+ options: subject.fetch("properties")
18
+ })
19
+ end
20
+
21
+ aspects.each do |aspect|
22
+ refocus.aspects.send(action, {
23
+ name: aspect.fetch("name"),
24
+ options: aspect.fetch("properties")
25
+ })
26
+ end
27
+ end
28
+
29
+ def input
30
+ @input ||= YAML.safe_load(STDIN.read)
31
+ end
32
+
33
+ def subjects
34
+ input["subjects"] || []
35
+ end
36
+
37
+ def aspects
38
+ input["aspects"] || []
39
+ end
40
+
41
+ def refocus
42
+ Refocus.client
43
+ end
44
+ end
45
+
46
+ Cli.class_eval do
47
+ subcommand "resources:sync", "Create refocus resources from STDIN", ResourcesSyncCommand
48
+ end
49
+ end
50
+
51
+
@@ -0,0 +1,18 @@
1
+ module Refocus
2
+ class SubjectsDeleteCommand< Clamp::Command
3
+ parameter "SUBJECT", "subject to delete"
4
+
5
+ def execute
6
+ refocus.subjects.delete(name: subject)
7
+ end
8
+
9
+ def refocus
10
+ Refocus.client
11
+ end
12
+ end
13
+
14
+ Cli.class_eval do
15
+ subcommand "subjects:delete", "Delete a subject", Refocus::SubjectsDeleteCommand
16
+ end
17
+ end
18
+
@@ -0,0 +1,9 @@
1
+ module Refocus
2
+ class ApiError < StandardError
3
+ attr_reader :json
4
+ def initialize(json)
5
+ @json = json
6
+ super("#{json["errors"].first["message"]}:#{json["errors"].first["description"]}")
7
+ end
8
+ end
9
+ end
data/lib/refocus/http.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require "refocus/errors"
2
+
1
3
  module Refocus
2
4
  class Http
3
5
 
@@ -10,23 +12,30 @@ module Refocus
10
12
  end
11
13
 
12
14
  def post(path, body:, expects: 201)
13
- connection(path).post(body: convert(body), headers: headers, expects: expects)
15
+ handle { connection(path).post(body: convert(body), headers: headers, expects: expects) }
14
16
  end
15
17
 
16
18
  def get(path)
17
- connection(path).get(headers: headers, expects: 200)
19
+ handle { connection(path).get(headers: headers, expects: 200) }
18
20
  end
19
21
 
20
22
  def patch(path, body:)
21
- connection(path).patch(body: convert(body), headers: headers, expects: 200)
23
+ handle { connection(path).patch(body: convert(body), headers: headers, expects: 200) }
22
24
  end
23
25
 
24
26
  def put(path, body:)
25
- connection(path).put(body: convert(body), headers: headers, expects: 201)
27
+ handle { connection(path).put(body: convert(body), headers: headers, expects: 201) }
26
28
  end
27
29
 
28
30
  def delete(path)
29
- connection(path).delete(headers: headers, expects: 200)
31
+ handle { connection(path).delete(headers: headers, expects: 200) }
32
+ end
33
+
34
+ def handle(&block)
35
+ yield
36
+ rescue Excon::Error::BadRequest => e
37
+ response = JSON.parse(e.response.body)["errors"].first["message"]
38
+ raise ApiError, JSON.parse(e.response.body)
30
39
  end
31
40
 
32
41
  def headers
@@ -1,3 +1,3 @@
1
1
  module Refocus
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: refocus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Shea
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-18 00:00:00.000000000 Z
11
+ date: 2018-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -116,8 +116,12 @@ files:
116
116
  - lib/refocus.rb
117
117
  - lib/refocus/aspects.rb
118
118
  - lib/refocus/cli.rb
119
+ - lib/refocus/cli/aspects.rb
120
+ - lib/refocus/cli/resources.rb
119
121
  - lib/refocus/cli/samples.rb
122
+ - lib/refocus/cli/subjects.rb
120
123
  - lib/refocus/client.rb
124
+ - lib/refocus/errors.rb
121
125
  - lib/refocus/http.rb
122
126
  - lib/refocus/json_helper.rb
123
127
  - lib/refocus/path_helper.rb