refocus 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.pryrc +6 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +43 -0
- data/README.md +79 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/refocus.rb +8 -0
- data/lib/refocus/aspects.rb +38 -0
- data/lib/refocus/client.rb +38 -0
- data/lib/refocus/http.rb +39 -0
- data/lib/refocus/json_helper.rb +7 -0
- data/lib/refocus/perspectives.rb +30 -0
- data/lib/refocus/samples.rb +17 -0
- data/lib/refocus/samples/collector.rb +27 -0
- data/lib/refocus/subjects.rb +32 -0
- data/lib/refocus/version.rb +3 -0
- data/refocus.gemspec +28 -0
- metadata +134 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3796fbad7b14d1d5e154aa27c0e08575328adeba
|
4
|
+
data.tar.gz: f57ed90a8d676a6696f09aaed4ff69ceec132444
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 36ca0a7d8c64123146c495fc748aea3b897f7def80eb55b509f784b03d9b2f76bced23862548e52bf6d825a7540d21397ad138e6679949661e26fbe0a657e831
|
7
|
+
data.tar.gz: c92068f6462416c11ea47a403c327555b30741f51a4ead800ed2001cdda5c25ec49fb8df581fea6c2c0843c62224abf42a5a3ae652bd54a5508c3f081b38c8a6
|
data/.gitignore
ADDED
data/.pryrc
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
refocus (0.1.0)
|
5
|
+
excon
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
coderay (1.1.2)
|
11
|
+
diff-lcs (1.3)
|
12
|
+
excon (0.60.0)
|
13
|
+
method_source (0.9.0)
|
14
|
+
pry (0.11.3)
|
15
|
+
coderay (~> 1.1.0)
|
16
|
+
method_source (~> 0.9.0)
|
17
|
+
rake (10.5.0)
|
18
|
+
rspec (3.7.0)
|
19
|
+
rspec-core (~> 3.7.0)
|
20
|
+
rspec-expectations (~> 3.7.0)
|
21
|
+
rspec-mocks (~> 3.7.0)
|
22
|
+
rspec-core (3.7.1)
|
23
|
+
rspec-support (~> 3.7.0)
|
24
|
+
rspec-expectations (3.7.0)
|
25
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
26
|
+
rspec-support (~> 3.7.0)
|
27
|
+
rspec-mocks (3.7.0)
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
+
rspec-support (~> 3.7.0)
|
30
|
+
rspec-support (3.7.0)
|
31
|
+
|
32
|
+
PLATFORMS
|
33
|
+
ruby
|
34
|
+
|
35
|
+
DEPENDENCIES
|
36
|
+
bundler (~> 1.16)
|
37
|
+
pry
|
38
|
+
rake (~> 10.0)
|
39
|
+
refocus!
|
40
|
+
rspec (~> 3.0)
|
41
|
+
|
42
|
+
BUNDLED WITH
|
43
|
+
1.16.1
|
data/README.md
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
# Refocus
|
2
|
+
|
3
|
+
A ruby client library for [Refocus](https://github.com/salesforce/refocus).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'refocus'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install refocus
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Refocus will pick up `REFOCUS_HOST` and `REFOCUS_API_TOKEN` environment vars if these are set.
|
24
|
+
You can create a client like this:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
# Using env vars. This will fail if REFOCUS_HOST and REFOCUS_API_TOKEN are unset:
|
28
|
+
refocs = Refocus.client
|
29
|
+
|
30
|
+
# Doing it yourself:
|
31
|
+
refocus = Refocus.client(url: "https://my.refocus.instance.com", token: "some-token-i-generated"
|
32
|
+
```
|
33
|
+
### Subjects
|
34
|
+
|
35
|
+
You can manage subjects like this:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
# Create a root subject (returns a hash):
|
39
|
+
refocus.subjects.create(name: "my-subject")
|
40
|
+
|
41
|
+
# Create a child subject (returns a hash):
|
42
|
+
refocus.subjects.create(parent: "my-subject", name: "child-subject")
|
43
|
+
|
44
|
+
# List all subjects (includes root subjects and children, in an array):
|
45
|
+
refocus.subjects.all
|
46
|
+
|
47
|
+
# Delete a child subject (returns a hash):
|
48
|
+
refocus.subjects.delete(name: "my-subject.child-subject")
|
49
|
+
```
|
50
|
+
|
51
|
+
### Aspects
|
52
|
+
|
53
|
+
You can manage aspects like this:
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
# Create an aspect:
|
57
|
+
refocus.aspects.create(name: "my-aspect", "timeout" => "5m")
|
58
|
+
|
59
|
+
# Describe an aspect:
|
60
|
+
refocus.aspects.get(name: "my-aspect")
|
61
|
+
|
62
|
+
# Delete an aspect by name:
|
63
|
+
refocus.aspects.delete(name: "my-aspect")
|
64
|
+
```
|
65
|
+
|
66
|
+
### Lenses
|
67
|
+
|
68
|
+
IN PROGRESS
|
69
|
+
|
70
|
+
|
71
|
+
## Development
|
72
|
+
|
73
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
74
|
+
|
75
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
76
|
+
|
77
|
+
## Contributing
|
78
|
+
|
79
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/sheax0r/refocus.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "refocus"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "pry"
|
14
|
+
Pry.start
|
data/bin/setup
ADDED
data/lib/refocus.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require "refocus/http"
|
2
|
+
require "refocus/json_helper"
|
3
|
+
|
4
|
+
module Refocus
|
5
|
+
class Aspects
|
6
|
+
include JsonHelper
|
7
|
+
|
8
|
+
attr_reader :http
|
9
|
+
|
10
|
+
def initialize(url:, token:)
|
11
|
+
@http = Refocus::Http.new(url: url, token: token)
|
12
|
+
end
|
13
|
+
|
14
|
+
def all
|
15
|
+
json(http.get(""))
|
16
|
+
end
|
17
|
+
|
18
|
+
def create(parent: nil, name:, options: {} )
|
19
|
+
path = parent ? "#{parent}/child" : ""
|
20
|
+
body = default_options.merge("name" => name).merge(options)
|
21
|
+
json(http.post(path, body: body))
|
22
|
+
end
|
23
|
+
|
24
|
+
def delete(name:)
|
25
|
+
json(http.delete(name))
|
26
|
+
end
|
27
|
+
|
28
|
+
def get(name:)
|
29
|
+
json(http.get(name))
|
30
|
+
end
|
31
|
+
|
32
|
+
def default_options
|
33
|
+
{
|
34
|
+
"timeout" => "5m"
|
35
|
+
}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require "excon"
|
2
|
+
require "json"
|
3
|
+
require "refocus/aspects"
|
4
|
+
require "refocus/subjects"
|
5
|
+
require "refocus/samples"
|
6
|
+
require "refocus/perspectives"
|
7
|
+
|
8
|
+
module Refocus
|
9
|
+
class Client
|
10
|
+
API_PATH = "v1"
|
11
|
+
|
12
|
+
attr_reader :url, :token, :debug_request, :debug_response
|
13
|
+
|
14
|
+
def initialize(url:, token:, debug_request: false, debug_response: false)
|
15
|
+
@url = url
|
16
|
+
@token = token
|
17
|
+
@debug_request = debug_request
|
18
|
+
@debug_response = debug_response
|
19
|
+
end
|
20
|
+
|
21
|
+
def subjects
|
22
|
+
Refocus::Subjects.new(url: "#{url}/v1/subjects", token: token)
|
23
|
+
end
|
24
|
+
|
25
|
+
def aspects
|
26
|
+
Refocus::Aspects.new(url: "#{url}/v1/aspects", token: token)
|
27
|
+
end
|
28
|
+
|
29
|
+
def samples
|
30
|
+
Refocus::Samples.new(url: "#{url}/v1/samples", token: token)
|
31
|
+
end
|
32
|
+
|
33
|
+
def perspectives
|
34
|
+
Refocus::Perspectives.new(url: "#{url}/v1/perspectives", token: token)
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
data/lib/refocus/http.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
module Refocus
|
2
|
+
class Http
|
3
|
+
|
4
|
+
attr_reader :url, :token, :content_type
|
5
|
+
|
6
|
+
def initialize(url:, token:, content_type: "application/json")
|
7
|
+
@url = url
|
8
|
+
@token = token
|
9
|
+
@content_type = content_type
|
10
|
+
end
|
11
|
+
|
12
|
+
def post(path, body:)
|
13
|
+
connection(path).post(body: convert(body), headers: headers, expects: 201)
|
14
|
+
end
|
15
|
+
|
16
|
+
def get(path)
|
17
|
+
connection(path).get(headers: headers, expects: 200)
|
18
|
+
end
|
19
|
+
|
20
|
+
def delete(path)
|
21
|
+
connection(path).delete(headers: headers, expects: 200)
|
22
|
+
end
|
23
|
+
|
24
|
+
def headers
|
25
|
+
{
|
26
|
+
"Authorization" => token,
|
27
|
+
"Content-Type" => content_type
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
def convert(body)
|
32
|
+
content_type == "application/json" ? body.to_json : body
|
33
|
+
end
|
34
|
+
|
35
|
+
def connection(path)
|
36
|
+
Excon.new("#{url}/#{path}")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require "refocus/http"
|
2
|
+
require "refocus/json_helper"
|
3
|
+
module Refocus
|
4
|
+
class Perspectives
|
5
|
+
include JsonHelper
|
6
|
+
|
7
|
+
attr_reader :http
|
8
|
+
|
9
|
+
def initialize(url:, token:)
|
10
|
+
@http = Refocus::Http.new(url: url, token: token)
|
11
|
+
end
|
12
|
+
|
13
|
+
def all
|
14
|
+
json(http.get(""))
|
15
|
+
end
|
16
|
+
|
17
|
+
def get(name:)
|
18
|
+
json(http.get(name))
|
19
|
+
end
|
20
|
+
|
21
|
+
def create(name:, lens:, root_subject:)
|
22
|
+
body = {
|
23
|
+
"name" => name,
|
24
|
+
"lensId" => lens,
|
25
|
+
"rootSubject" => root_subject
|
26
|
+
}
|
27
|
+
json(http.post("", body: body))
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "refocus/http"
|
2
|
+
module Refocus
|
3
|
+
class Samples
|
4
|
+
attr_reader :http
|
5
|
+
|
6
|
+
def initialize(url:, token:)
|
7
|
+
@http = Refocus::Http.new(url: url, token: token)
|
8
|
+
end
|
9
|
+
|
10
|
+
def collector
|
11
|
+
Collector.new(http: http)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
require "refocus/samples/collector"
|
17
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Refocus
|
2
|
+
class Samples
|
3
|
+
class Collector
|
4
|
+
|
5
|
+
attr_reader :http, :samples
|
6
|
+
|
7
|
+
def initialize(http:)
|
8
|
+
@http = http
|
9
|
+
@samples = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def add(name:, aspect:, value:)
|
13
|
+
samples << {name: "#{name}|#{aspect}", value: value.to_s}
|
14
|
+
end
|
15
|
+
|
16
|
+
def submit
|
17
|
+
result = json(http.post("upsert/bulk", body: samples))
|
18
|
+
samples.clear
|
19
|
+
true
|
20
|
+
end
|
21
|
+
|
22
|
+
def json(response)
|
23
|
+
JSON.parse(response.body)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "refocus/http"
|
2
|
+
require "refocus/json_helper"
|
3
|
+
|
4
|
+
module Refocus
|
5
|
+
class Subjects
|
6
|
+
include JsonHelper
|
7
|
+
|
8
|
+
attr_reader :http
|
9
|
+
|
10
|
+
def initialize(url:, token:)
|
11
|
+
@http = Refocus::Http.new(url: url, token: token)
|
12
|
+
end
|
13
|
+
|
14
|
+
def all
|
15
|
+
json(http.get(""))
|
16
|
+
end
|
17
|
+
|
18
|
+
def create(parent: nil, name:, options: {})
|
19
|
+
path = parent ? "#{parent}/child" : ""
|
20
|
+
body = options.merge({"name" => name})
|
21
|
+
json(http.post(path, body: body))
|
22
|
+
end
|
23
|
+
|
24
|
+
def delete(name:)
|
25
|
+
json(http.delete(name))
|
26
|
+
end
|
27
|
+
|
28
|
+
def get(name:)
|
29
|
+
json(http.get(name))
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/refocus.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "refocus/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "refocus"
|
8
|
+
spec.version = Refocus::VERSION
|
9
|
+
spec.authors = ["Michael Shea"]
|
10
|
+
spec.email = ["michael.shea@heroku.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Refocus ruby client}
|
13
|
+
spec.description = %q{Ruby client for https://github.com/salesforce/refocus}
|
14
|
+
spec.homepage = "https://github.com/heroku/refocus-ruby"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
26
|
+
spec.add_development_dependency "pry"
|
27
|
+
spec.add_dependency "excon"
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: refocus
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michael Shea
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-01-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: excon
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Ruby client for https://github.com/salesforce/refocus
|
84
|
+
email:
|
85
|
+
- michael.shea@heroku.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".pryrc"
|
92
|
+
- ".rspec"
|
93
|
+
- ".travis.yml"
|
94
|
+
- Gemfile
|
95
|
+
- Gemfile.lock
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- bin/console
|
99
|
+
- bin/setup
|
100
|
+
- lib/refocus.rb
|
101
|
+
- lib/refocus/aspects.rb
|
102
|
+
- lib/refocus/client.rb
|
103
|
+
- lib/refocus/http.rb
|
104
|
+
- lib/refocus/json_helper.rb
|
105
|
+
- lib/refocus/perspectives.rb
|
106
|
+
- lib/refocus/samples.rb
|
107
|
+
- lib/refocus/samples/collector.rb
|
108
|
+
- lib/refocus/subjects.rb
|
109
|
+
- lib/refocus/version.rb
|
110
|
+
- refocus.gemspec
|
111
|
+
homepage: https://github.com/heroku/refocus-ruby
|
112
|
+
licenses: []
|
113
|
+
metadata: {}
|
114
|
+
post_install_message:
|
115
|
+
rdoc_options: []
|
116
|
+
require_paths:
|
117
|
+
- lib
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
requirements: []
|
129
|
+
rubyforge_project:
|
130
|
+
rubygems_version: 2.5.1
|
131
|
+
signing_key:
|
132
|
+
specification_version: 4
|
133
|
+
summary: Refocus ruby client
|
134
|
+
test_files: []
|