fluffy-ruby 0.0.1 → 0.0.2
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 +4 -4
- data/README.md +2 -0
- data/lib/fluffy/api.rb +50 -41
- data/lib/fluffy/client.rb +2 -2
- data/lib/fluffy/exceptions.rb +15 -0
- data/lib/fluffy/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff7ee179b75b1a98e5e4555b43c5d712885bb148
|
4
|
+
data.tar.gz: b28e79d8f015d1c4425d7116584bcf9b78d84c72
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50d36445fba495fbbc532ce88abdf274b72226c05889a6cab4f745800777866a715b937530118e008b972837f3bc37373ecb934388d5d15eefc12b3b495f5f2e
|
7
|
+
data.tar.gz: 3e1ffe1d7ad28c6cf2e7dde01b53d88e3ef33d1a4b28225b26ff2f0dac568cd10c03072294d5434c6002cf53fa21ec1108bdd6cb8d514445f1272481f1fc27d8
|
data/README.md
CHANGED
data/lib/fluffy/api.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require_relative 'exceptions'
|
2
|
+
|
1
3
|
module Fluffy
|
2
4
|
module API
|
3
5
|
@@api = nil
|
@@ -6,51 +8,58 @@ module Fluffy
|
|
6
8
|
@@api
|
7
9
|
end
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
class RESTClient
|
12
|
+
# @return [HTTPClient] HTTP client instance
|
13
|
+
attr_reader :http
|
14
|
+
# @return [String] Fluffy REST API's URL
|
15
|
+
attr_reader :url
|
13
16
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
# Create a Fluffy Client API object
|
18
|
+
#
|
19
|
+
# @param url [String] Fluffy REST API's URL
|
20
|
+
#
|
21
|
+
def initialize(url:)
|
22
|
+
@http = HTTPClient.new
|
23
|
+
@url = url
|
24
|
+
end
|
22
25
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
26
|
+
# Perform a HTTP GET request
|
27
|
+
#
|
28
|
+
# @param endpoint [Array[String], String] HTTP API endpoint
|
29
|
+
# @param query [String] HTTP API query parameters
|
30
|
+
# @return [Array[Hash], Hash] API JSON response
|
31
|
+
#
|
32
|
+
def get(endpoint:, query: nil)
|
33
|
+
resp = self.http.get([self.url, endpoint.is_a?(Array) ? endpoint.join('/') : endpoint].join('/'), query, {'Content-Type' => 'application/json', 'Accept' => 'application/json'})
|
34
|
+
data = JSON.parse(resp.body)
|
35
|
+
raise APIError.new(data['message'], data['error'], resp.status) if resp.status >= 400
|
36
|
+
data
|
37
|
+
end
|
33
38
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
39
|
+
# Perform a HTTP POST request
|
40
|
+
#
|
41
|
+
# @param endpoint [Array[String], String] HTTP API endpoint
|
42
|
+
# @param params [Hash] HTTP API body
|
43
|
+
# @return [Hash, nil] API JSON response
|
44
|
+
#
|
45
|
+
def post(endpoint:, params: {})
|
46
|
+
resp = self.http.post([self.url, endpoint.is_a?(Array) ? endpoint.join('/') : endpoint].join('/'), params.to_json, {'Content-Type' => 'application/json', 'Accept' => 'application/json'})
|
47
|
+
data = JSON.parse(resp.body)
|
48
|
+
raise APIError.new(data['message'], data['error'], resp.status) if resp.status >= 400
|
49
|
+
data['message']
|
50
|
+
end
|
45
51
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
52
|
+
# Perform a HTTP DELETE request
|
53
|
+
#
|
54
|
+
# @param endpoint [Array[String], String] HTTP API endpoint
|
55
|
+
# @return [Hash, nil] API JSON response
|
56
|
+
#
|
57
|
+
def delete(endpoint:)
|
58
|
+
resp = self.http.delete([self.url, endpoint.is_a?(Array) ? endpoint.join('/') : endpoint].join('/'), {'Content-Type' => 'application/json', 'Accept' => 'application/json'})
|
59
|
+
data = JSON.parse(resp.body)
|
60
|
+
raise APIError.new(data['message'], data['error'], resp.status) if resp.status >= 400
|
61
|
+
data['message']
|
62
|
+
end
|
54
63
|
end
|
55
64
|
end
|
56
65
|
end
|
data/lib/fluffy/client.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'httpclient'
|
2
2
|
require 'json'
|
3
3
|
|
4
|
-
require_relative '
|
4
|
+
#require_relative 'api'
|
5
5
|
require_relative 'sessions'
|
6
6
|
|
7
7
|
module Fluffy
|
@@ -19,7 +19,7 @@ module Fluffy
|
|
19
19
|
def initialize(url:, version: 1)
|
20
20
|
@url = url
|
21
21
|
@version = version
|
22
|
-
@@api =
|
22
|
+
@@api = RESTClient.new(url: URI.join(url, "v#{version}"))
|
23
23
|
@sessions = Sessions.new
|
24
24
|
end
|
25
25
|
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Fluffy
|
2
|
+
class APIError < Exception
|
3
|
+
# @return [Integer] HTTP error code
|
4
|
+
attr_reader :code
|
5
|
+
# @return [String] Reason for error message
|
6
|
+
attr_reader :error
|
7
|
+
|
8
|
+
def initialize(msg, error, code)
|
9
|
+
@code = code
|
10
|
+
@error = error
|
11
|
+
|
12
|
+
super(msg)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/fluffy/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluffy-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matteo Cerutti
|
@@ -48,6 +48,7 @@ files:
|
|
48
48
|
- README.md
|
49
49
|
- lib/fluffy/api.rb
|
50
50
|
- lib/fluffy/client.rb
|
51
|
+
- lib/fluffy/exceptions.rb
|
51
52
|
- lib/fluffy/session.rb
|
52
53
|
- lib/fluffy/session/addressbook.rb
|
53
54
|
- lib/fluffy/session/chains.rb
|