fluffy-ruby 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5293108ca23502a00f4b6692fc74e9ee94c6a449
4
+ data.tar.gz: 5af10d47249e648805cd4f558868cee181518e35
5
+ SHA512:
6
+ metadata.gz: 9c1ac80ca83f6f1bccad05ed5fe7b1356e8974553674f3e098db7af75886746d09c3d98ee16113881fc778e8a8d870ddec3aea05f801bc6ef24d71e5442d5a1e
7
+ data.tar.gz: 068f82d4fcdcddd8bb6313ad7de89df9010e1c458ded93c2f0604c41591ca22579fa402032c29612dc42ec96fe2cae978c3f17b6148fa9d1b5d3a85fd9bb9760
data/LICENSE ADDED
@@ -0,0 +1,12 @@
1
+ Copyright 2017 Matteo Cerutti
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+
8
+ Unless required by applicable law or agreed to in writing, software
9
+ distributed under the License is distributed on an "AS IS" BASIS,
10
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ See the License for the specific language governing permissions and
12
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,12 @@
1
+ # Ruby client library for Fluffy REST API
2
+ This is a simple Ruby client library that allows to interact with the Fluffy REST API.
3
+
4
+ ## Install
5
+ To install it simply issue the following command:
6
+
7
+ ```
8
+ gem install fluffy-ruby
9
+ ```
10
+
11
+ ## Contact
12
+ Matteo Cerutti - matteo.cerutti@hotmail.co.uk
data/lib/fluffy/api.rb ADDED
@@ -0,0 +1,56 @@
1
+ module Fluffy
2
+ module API
3
+ @@api = nil
4
+
5
+ def self.api
6
+ @@api
7
+ end
8
+
9
+ # @return [HTTPClient] HTTP client instance
10
+ attr_reader :http
11
+ # @return [String] Fluffy REST API's URL
12
+ attr_reader :url
13
+
14
+ # Create a Fluffy Client API object
15
+ #
16
+ # @param url [String] Fluffy REST API's URL
17
+ #
18
+ def initialize(url:)
19
+ @http = HTTPClient.new
20
+ @url = url
21
+ end
22
+
23
+ # Perform a HTTP GET request
24
+ #
25
+ # @param endpoint [Array[String], String] HTTP API endpoint
26
+ # @param query [String] HTTP API query parameters
27
+ # @return [Array[Hash], Hash] API JSON response
28
+ #
29
+ def get(endpoint:, query: nil)
30
+ resp = self.http.get([self.url, endpoint.is_a?(Array) ? endpoint.join('/') : endpoint].join('/'), query, {'Content-Type' => 'application/json', 'Accept' => 'application/json'})
31
+ JSON.parse(resp.body)
32
+ end
33
+
34
+ # Perform a HTTP POST request
35
+ #
36
+ # @param endpoint [Array[String], String] HTTP API endpoint
37
+ # @param params [Hash] HTTP API body
38
+ # @return [Hash, nil] API JSON response
39
+ #
40
+ def post(endpoint:, params: {})
41
+ puts [self.url, endpoint.is_a?(Array) ? endpoint.join('/') : endpoint].join('/')
42
+ resp = self.http.post([self.url, endpoint.is_a?(Array) ? endpoint.join('/') : endpoint].join('/'), params.to_json, {'Content-Type' => 'application/json', 'Accept' => 'application/json'})
43
+ JSON.parse(resp.body)
44
+ end
45
+
46
+ # Perform a HTTP DELETE request
47
+ #
48
+ # @param endpoint [Array[String], String] HTTP API endpoint
49
+ # @return [Hash, nil] API JSON response
50
+ #
51
+ def delete(endpoint:)
52
+ resp = self.http.delete([self.url, endpoint.is_a?(Array) ? endpoint.join('/') : endpoint].join('/'), {'Content-Type' => 'application/json', 'Accept' => 'application/json'})
53
+ JSON.parse(resp.body)
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,66 @@
1
+ require 'httpclient'
2
+ require 'json'
3
+
4
+ require_relative 'client/api'
5
+ require_relative 'sessions'
6
+
7
+ module Fluffy
8
+ class Client
9
+ include Fluffy::API
10
+
11
+ # @return [Fluffy::Sessions] Sessions instance
12
+ attr_reader :sessions
13
+
14
+ # Create a new client
15
+ #
16
+ # @param url [String] Fluffy REST API's URL
17
+ # @param version [Integer] API version (defaults to `1`)
18
+ #
19
+ def initialize(url:, version: 1)
20
+ @url = url
21
+ @version = version
22
+ @@api = API.new(url: URI.join(url, "v#{version}"))
23
+ @sessions = Sessions.new
24
+ end
25
+
26
+ # Retrieve the active addressbook
27
+ #
28
+ # @return [Hash] List of addresses
29
+ #
30
+ def addressbook
31
+ @@api.get(endpoint: "addressbook")
32
+ end
33
+
34
+ # Retrieve the active rules
35
+ #
36
+ # @return [Hash] List of rules
37
+ #
38
+ def rules
39
+ @@api.get(endpoint: "rules")
40
+ end
41
+
42
+ # Retrieve the active chains
43
+ #
44
+ # @return [Hash] List of chains
45
+ #
46
+ def chains
47
+ @@api.get(endpoint: "chains")
48
+ end
49
+
50
+ # Retrieve the active interfaces
51
+ #
52
+ # @return [Hash] List of interfaces
53
+ #
54
+ def interfaces
55
+ @@api.get(endpoint: "interfaces")
56
+ end
57
+
58
+ # Retrieve the active services
59
+ #
60
+ # @return [Hash] List of services
61
+ #
62
+ def services
63
+ @@api.get(endpoint: "services")
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,64 @@
1
+ require_relative 'session/addressbook'
2
+ require_relative 'session/services'
3
+ require_relative 'session/rules'
4
+ require_relative 'session/interfaces'
5
+ require_relative 'session/chains'
6
+
7
+ module Fluffy
8
+ class Session
9
+ include Fluffy::API
10
+
11
+ # @return [Fluffy::Session::Addressbook] The session addressbook
12
+ attr_reader :addressbook
13
+ # @return [Fluffy::Session::Services] The session services
14
+ attr_reader :services
15
+ # @return [Fluffy::Session::Rules] The session rules
16
+ attr_reader :rules
17
+ # @return [Fluffy::Session::Interfaces] The session interfaces
18
+ attr_reader :interfaces
19
+ # @return [Fluffy::Session::Chains] The session chains
20
+ attr_reader :chains
21
+ # @return [String] The session endpoint
22
+ attr_reader :endpoint
23
+
24
+ # Create a new session
25
+ #
26
+ # @param name [String] Session name
27
+ # @param owner [String] Session owner
28
+ # @param ttl [Integer] Session time-to-live
29
+ #
30
+ def initialize(name:, owner:, ttl:)
31
+ @endpoint = ["sessions", name]
32
+
33
+ # create session
34
+ @@api.post(endpoint: @endpoint, params: {'owner' => owner, 'ttl' => ttl})
35
+
36
+ @addressbook = Addressbook.new(endpoint: @endpoint)
37
+ @services = Services.new(endpoint: @endpoint)
38
+ @rules = Rules.new(endpoint: @endpoint)
39
+ @interfaces = Interfaces.new(endpoint: @endpoint)
40
+ @chains = Chains.new(endpoint: @endpoint)
41
+ end
42
+
43
+ # Commit the session configuration
44
+ #
45
+ # @param rollback [Boolean] Enable rollback `defaults to false`
46
+ # @param rollback_interval [Integer] Rollback configuration at the given interval (seconds) `defaults to 60`
47
+ #
48
+ def commit!(rollback: true, rollback_interval: 60)
49
+ @@api.post(endpoint: self.endpoint + ['commit'], params: params)
50
+ end
51
+
52
+ # Confirm the session configuration
53
+ #
54
+ def confirm!
55
+ @@api.post(endpoint: self.endpoint + ['confirm'])
56
+ end
57
+
58
+ # Destroy the session
59
+ #
60
+ def destroy!
61
+ @@api.delete(endpoint: self.endpoint)
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,57 @@
1
+ require_relative '../api'
2
+
3
+ module Fluffy
4
+ class Session
5
+ class Addressbook
6
+ include Fluffy::API
7
+
8
+ # @return [String] The session endpoint
9
+ attr_reader :endpoint
10
+
11
+ # Create an addressbook instance for a given session
12
+ #
13
+ # @param endpoint [String] API session endpoint
14
+ #
15
+ def initialize(endpoint:)
16
+ @endpoint = endpoint + ['addressbook']
17
+ end
18
+
19
+ # Retrieve the session addressbook
20
+ #
21
+ # @return [Hash] The session addressbook
22
+ #
23
+ def get
24
+ @@api.get(endpoint: self.endpoint)
25
+ end
26
+
27
+ # Add a new entry in the session addressbook
28
+ #
29
+ # @param name [String] Entry name
30
+ # @param **params [Hash] Any number of parameters to push into the Hash
31
+ # @return [Hash, nil] API response
32
+ #
33
+ def add(name:, **params)
34
+ @@api.post(endpoint: self.endpoint + [name], params: params)
35
+ end
36
+
37
+ # Update an existing entry in the session addressbook
38
+ #
39
+ # @param name [String] Entry name
40
+ # @param **params [Hash] Any number of parameters to push into the Hash
41
+ # @return [Hash, nil] API response
42
+ #
43
+ def update(name:, **params)
44
+ @@api.post(endpoint: self.endpoint + [name], params: params)
45
+ end
46
+
47
+ # Delete an entry from the session addressbook
48
+ #
49
+ # @param name [String] Entry name
50
+ # @return [Hash, nil] API response
51
+ #
52
+ def delete(name:)
53
+ @@api.delete(endpoint: self.endpoint + [name])
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,55 @@
1
+ module Fluffy
2
+ class Session
3
+ class Chains
4
+ include Fluffy::API
5
+
6
+ # @return [String] The session endpoint
7
+ attr_reader :endpoint
8
+
9
+ # Create a chains instance for a given session
10
+ #
11
+ # @param endpoint [String] API session endpoint
12
+ #
13
+ def initialize(endpoint:)
14
+ @endpoint = endpoint + ['chains']
15
+ end
16
+
17
+ # Retrieve the session chains
18
+ #
19
+ # @return [Hash] The session chains
20
+ #
21
+ def get
22
+ @@api.get(endpoint: self.endpoint)
23
+ end
24
+
25
+ # Add a new entry in the session chains
26
+ #
27
+ # @param name [String] Entry name
28
+ # @param **params [Hash] Any number of parameters to push into the Hash
29
+ # @return [Hash, nil] API response
30
+ #
31
+ def add(name:, **params)
32
+ @@api.post(endpoint: self.endpoint + [name], params: params)
33
+ end
34
+
35
+ # Update an existing entry in the session chains
36
+ #
37
+ # @param name [String] Entry name
38
+ # @param **params [Hash] Any number of parameters to push into the Hash
39
+ # @return [Hash, nil] API response
40
+ #
41
+ def update(name:, **params)
42
+ @@api.post(endpoint: self.endpoint + [name], params: params)
43
+ end
44
+
45
+ # Delete an entry from the session chains
46
+ #
47
+ # @param name [String] Entry name
48
+ # @return [Hash, nil] API response
49
+ #
50
+ def delete(name:)
51
+ @@api.delete(endpoint: self.endpoint + [name])
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,55 @@
1
+ module Fluffy
2
+ class Session
3
+ class Interfaces
4
+ include Fluffy::API
5
+
6
+ # @return [String] The session endpoint
7
+ attr_reader :endpoint
8
+
9
+ # Create an interfaces instance for a given session
10
+ #
11
+ # @param endpoint [String] API session endpoint
12
+ #
13
+ def initialize(endpoint:)
14
+ @endpoint = endpoint + ['interfaces']
15
+ end
16
+
17
+ # Retrieve the session interfaces
18
+ #
19
+ # @return [Hash] The session interfaces
20
+ #
21
+ def get
22
+ @@api.get(endpoint: self.endpoint)
23
+ end
24
+
25
+ # Add a new entry in the session interfaces
26
+ #
27
+ # @param name [String] Entry name
28
+ # @param **params [Hash] Any number of parameters to push into the Hash
29
+ # @return [Hash, nil] API response
30
+ #
31
+ def add(name:, **params)
32
+ self.api.post(endpoint: self.endpoint + [name], params: params)
33
+ end
34
+
35
+ # Update an existing entry in the session interfaces
36
+ #
37
+ # @param name [String] Entry name
38
+ # @param **params [Hash] Any number of parameters to push into the Hash
39
+ # @return [Hash, nil] API response
40
+ #
41
+ def update(name:, **params)
42
+ @@api.post(endpoint: self.endpoint + [name], params: params)
43
+ end
44
+
45
+ # Delete an entry from the session interfaces
46
+ #
47
+ # @param name [String] Entry name
48
+ # @return [Hash, nil] API response
49
+ #
50
+ def delete(name:)
51
+ @@api.delete(endpoint: self.endpoint + [name])
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,55 @@
1
+ module Fluffy
2
+ class Session
3
+ class Rules
4
+ include Fluffy::API
5
+
6
+ # @return [String] The session endpoint
7
+ attr_reader :endpoint
8
+
9
+ # Create a rules instance for a given session
10
+ #
11
+ # @param endpoint [String] API session endpoint
12
+ #
13
+ def initialize(endpoint:)
14
+ @endpoint = endpoint + ['rules']
15
+ end
16
+
17
+ # Retrieve the session rules
18
+ #
19
+ # @return [Hash] The session rules
20
+ #
21
+ def get
22
+ @@api.get(endpoint: self.endpoint)
23
+ end
24
+
25
+ # Add a new entry in the session rules
26
+ #
27
+ # @param name [String] Entry name
28
+ # @param **params [Hash] Any number of parameters to push into the Hash
29
+ # @return [Hash, nil] API response
30
+ #
31
+ def add(name:, **params)
32
+ @@api.post(endpoint: self.endpoint + [name], params: params)
33
+ end
34
+
35
+ # Update an existing entry in the session rules
36
+ #
37
+ # @param name [String] Entry name
38
+ # @param **params [Hash] Any number of parameters to push into the Hash
39
+ # @return [Hash, nil] API response
40
+ #
41
+ def update(name:, **params)
42
+ @@api.post(endpoint: self.endpoint + [name], params: params)
43
+ end
44
+
45
+ # Delete an entry from the session rules
46
+ #
47
+ # @param name [String] Entry name
48
+ # @return [Hash, nil] API response
49
+ #
50
+ def delete(name:)
51
+ @@api.delete(endpoint: self.endpoint + [name])
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,55 @@
1
+ module Fluffy
2
+ class Session
3
+ class Services
4
+ include Fluffy::API
5
+
6
+ # @return [String] The session endpoint
7
+ attr_reader :endpoint
8
+
9
+ # Create a services instance for a given session
10
+ #
11
+ # @param endpoint [String] API session endpoint
12
+ #
13
+ def initialize(endpoint:)
14
+ @endpoint = endpoint + ['services']
15
+ end
16
+
17
+ # Retrieve the session services
18
+ #
19
+ # @return [Hash] The session services
20
+ #
21
+ def get
22
+ @@api.get(endpoint: self.endpoint)
23
+ end
24
+
25
+ # Add a new entry in the session services
26
+ #
27
+ # @param name [String] Entry name
28
+ # @param **params [Hash] Any number of parameters to push into the Hash
29
+ # @return [Hash, nil] API response
30
+ #
31
+ def add(name:, **params)
32
+ @@api.post(endpoint: self.endpoint + [name], params: params)
33
+ end
34
+
35
+ # Update an existing entry in the session services
36
+ #
37
+ # @param name [String] Entry name
38
+ # @param **params [Hash] Any number of parameters to push into the Hash
39
+ # @return [Hash, nil] API response
40
+ #
41
+ def update(name:, **params)
42
+ @@api.post(endpoint: self.endpoint + [name], params: params)
43
+ end
44
+
45
+ # Delete an entry from the session services
46
+ #
47
+ # @param name [String] Entry name
48
+ # @return [Hash, nil] API response
49
+ #
50
+ def delete(name:)
51
+ @@api.delete(endpoint: self.endpoint + [name])
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,36 @@
1
+ require_relative 'session'
2
+
3
+ module Fluffy
4
+ class Sessions
5
+ include Fluffy::API
6
+
7
+ # @return [String] Sessions API endpoint
8
+ attr_reader :endpoint
9
+
10
+ # Create a Sessions object
11
+ #
12
+ # @param api [Fluffy::Client::API] Client API instance
13
+ #
14
+ def initialize
15
+ @endpoint = ['sessions']
16
+ end
17
+
18
+ # Retrieve the active sessions
19
+ #
20
+ # @return [Hash] List of sessions
21
+ #
22
+ def get
23
+ @@api.get(endpoint: self.endpoint)
24
+ end
25
+
26
+ # Create a new session
27
+ #
28
+ # @param name [String] Session key
29
+ # @param **params [Hash] Any number of session parameters to push into the Hash
30
+ # @return [Fluffy::Session] Session instance
31
+ #
32
+ def add(name:, **params)
33
+ Session.new(name: name, **params)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,7 @@
1
+ module Fluffy
2
+ VERSION = "0.0.1"
3
+
4
+ def self.version
5
+ VERSION
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluffy-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Matteo Cerutti
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-07-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 1.7.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 1.7.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: httpclient
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.4.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 2.4.0
41
+ description: Ruby client library for Fluffy REST API
42
+ email: matteo.cerutti@hotmail.co.uk
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - LICENSE
48
+ - README.md
49
+ - lib/fluffy/api.rb
50
+ - lib/fluffy/client.rb
51
+ - lib/fluffy/session.rb
52
+ - lib/fluffy/session/addressbook.rb
53
+ - lib/fluffy/session/chains.rb
54
+ - lib/fluffy/session/interfaces.rb
55
+ - lib/fluffy/session/rules.rb
56
+ - lib/fluffy/session/services.rb
57
+ - lib/fluffy/sessions.rb
58
+ - lib/fluffy/version.rb
59
+ homepage: https://github.com/m4ce/fluffy-ruby
60
+ licenses:
61
+ - Apache 2.0
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.6.8
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: Ruby client library that allows to interact with the Fluffy REST API
83
+ test_files: []