moonrope-client 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/moonrope_client/connection.rb +18 -14
- data/lib/moonrope_client/controller.rb +10 -6
- data/lib/moonrope_client/request.rb +18 -7
- data/lib/moonrope_client/request_error.rb +8 -0
- data/lib/moonrope_client/response.rb +9 -9
- data/lib/moonrope_client/version.rb +2 -2
- data/lib/moonrope_client.rb +0 -3
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1d837d5dba07f1d26178db09d1d19dca25463ed
|
4
|
+
data.tar.gz: bb8d38e1f9612a4093b391f75a05a2794f58c03d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 178d8c782f0c8693e05428b6c4a4ae024cc553d1303eeaad99ff32688d1ebdf01cb636617f137f04e626e0acc64b2ff759856d2d5ad3ff6c8e5ede89916e761d
|
7
|
+
data.tar.gz: 156bdd464baa75bbdb2d4dc9044066953e13fc358015c1fe41fa39d6c152db8b9d2217eb367c09cbcf996e5cb44069d94110fdd0f1393f3e8ff2613dbbc0cdfd
|
@@ -12,20 +12,20 @@ module MoonropeClient
|
|
12
12
|
def initialize(host, options = {})
|
13
13
|
@host, @options = host, options
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
#
|
17
17
|
# @return [String] the endpoint hostname
|
18
18
|
#
|
19
19
|
attr_reader :host
|
20
|
-
|
20
|
+
|
21
21
|
#
|
22
22
|
# @return [String] the path prefix
|
23
23
|
#
|
24
24
|
def path_prefix
|
25
25
|
@options[:path_prefix] || 'api'
|
26
26
|
end
|
27
|
-
|
28
|
-
#
|
27
|
+
|
28
|
+
#
|
29
29
|
# @return [Boolean] whether or not SSL is enabled for requests or not
|
30
30
|
#
|
31
31
|
def ssl
|
@@ -33,26 +33,26 @@ module MoonropeClient
|
|
33
33
|
end
|
34
34
|
|
35
35
|
#
|
36
|
-
# @return [Integer] the port to conncet to
|
36
|
+
# @return [Integer] the port to conncet to
|
37
37
|
#
|
38
38
|
def port
|
39
39
|
@options[:port] || (ssl ? 443 : 80)
|
40
40
|
end
|
41
|
-
|
42
|
-
#
|
41
|
+
|
42
|
+
#
|
43
43
|
# @return [Hash] return headers to be set on all requests to the API
|
44
44
|
#
|
45
45
|
def headers
|
46
46
|
@options[:headers] || {}
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
#
|
50
50
|
# @return [Integer] the version of the API to use
|
51
51
|
#
|
52
52
|
def version
|
53
53
|
@options[:version] || 1
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
#
|
57
57
|
# Make a request and return an appropriate request object.
|
58
58
|
#
|
@@ -63,15 +63,19 @@ module MoonropeClient
|
|
63
63
|
def request(controller, action, params = {})
|
64
64
|
MoonropeClient::Request.new(self, controller, action, params).make
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
|
+
def request!(controller, action, params = {})
|
68
|
+
MoonropeClient::Request.new(self, controller, action, params).make!
|
69
|
+
end
|
70
|
+
|
67
71
|
def controller(name)
|
68
72
|
MoonropeClient::Controller.new(self, name)
|
69
73
|
end
|
70
|
-
|
74
|
+
|
71
75
|
def method_missing(name, value = nil)
|
72
76
|
value.nil? ? self.controller(name) : super
|
73
77
|
end
|
74
|
-
|
78
|
+
|
75
79
|
#
|
76
80
|
# Make a request to the remote API server and return the raw output from
|
77
81
|
# the request.
|
@@ -96,6 +100,6 @@ module MoonropeClient
|
|
96
100
|
else raise Error, "Internal server error occurred"
|
97
101
|
end
|
98
102
|
end
|
99
|
-
|
103
|
+
|
100
104
|
end
|
101
|
-
end
|
105
|
+
end
|
@@ -1,20 +1,24 @@
|
|
1
1
|
module MoonropeClient
|
2
2
|
class Controller
|
3
|
-
|
3
|
+
|
4
4
|
def initialize(connection, controller_name)
|
5
5
|
@connection = connection
|
6
6
|
@controller_name = controller_name
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
attr_reader :name
|
10
|
-
|
10
|
+
|
11
11
|
def method_missing(name, params = {})
|
12
12
|
request(name, params)
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
def request(action_name, params = {})
|
16
|
-
|
16
|
+
if action_name =~ /\A(.*)\!\z/
|
17
|
+
@connection.request!(@controller_name, $1, params)
|
18
|
+
else
|
19
|
+
@connection.request(@controller_name, action_name, params)
|
20
|
+
end
|
17
21
|
end
|
18
|
-
|
22
|
+
|
19
23
|
end
|
20
24
|
end
|
@@ -1,6 +1,8 @@
|
|
1
|
+
require 'moonrope_client/request_error'
|
2
|
+
|
1
3
|
module MoonropeClient
|
2
4
|
class Request
|
3
|
-
|
5
|
+
|
4
6
|
#
|
5
7
|
# Initialize a new request
|
6
8
|
#
|
@@ -15,21 +17,30 @@ module MoonropeClient
|
|
15
17
|
@action = action.to_sym
|
16
18
|
@params = params
|
17
19
|
end
|
18
|
-
|
20
|
+
|
19
21
|
attr_reader :params
|
20
|
-
|
22
|
+
|
21
23
|
def make
|
22
24
|
raw_data_to_response_object(make_request)
|
23
25
|
end
|
24
|
-
|
26
|
+
|
27
|
+
def make!
|
28
|
+
result = raw_data_to_response_object(make_request)
|
29
|
+
if result.success?
|
30
|
+
result
|
31
|
+
else
|
32
|
+
raise MoonropeClient::RequestError.new(result), "Request was not successful. Got #{result.class}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
25
36
|
private
|
26
|
-
|
37
|
+
|
27
38
|
def make_request
|
28
39
|
params = {:params => @params.to_json}
|
29
40
|
path = "/#{@connection.path_prefix}/v#{@connection.version}/#{@controller}/#{@action}"
|
30
41
|
JSON.parse(@connection.raw_request(path, params))
|
31
42
|
end
|
32
|
-
|
43
|
+
|
33
44
|
#
|
34
45
|
# Convert rhe result of a request into an appropriate response object
|
35
46
|
#
|
@@ -48,6 +59,6 @@ module MoonropeClient
|
|
48
59
|
MoonropeClient::Response.new(self, data)
|
49
60
|
end
|
50
61
|
end
|
51
|
-
|
62
|
+
|
52
63
|
end
|
53
64
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
module MoonropeClient
|
2
2
|
class Response
|
3
|
-
|
3
|
+
|
4
4
|
#
|
5
5
|
# Initialize a new response object
|
6
|
-
#
|
6
|
+
#
|
7
7
|
# @param request [MoonropeClient::Request]
|
8
8
|
# @param data [Hash]
|
9
9
|
#
|
@@ -11,7 +11,7 @@ module MoonropeClient
|
|
11
11
|
@request = request
|
12
12
|
@data = data
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
#
|
16
16
|
# Is this a successful response?
|
17
17
|
#
|
@@ -20,33 +20,33 @@ module MoonropeClient
|
|
20
20
|
def success?
|
21
21
|
false
|
22
22
|
end
|
23
|
-
|
24
|
-
#
|
23
|
+
|
24
|
+
#
|
25
25
|
# @return [String] the status of the request returned by the server
|
26
26
|
#
|
27
27
|
def status
|
28
28
|
@data['status']
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
#
|
32
32
|
# @return [Hash] any flags returned by the server
|
33
33
|
def flags
|
34
34
|
@data['flags']
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
#
|
38
38
|
# @return [Object] the data returned by the server
|
39
39
|
#
|
40
40
|
def data
|
41
41
|
@data['data']
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
#
|
45
45
|
# @return [Float] the time the request took at the server
|
46
46
|
#
|
47
47
|
def time
|
48
48
|
@data['time']
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
end
|
52
52
|
end
|
@@ -1,3 +1,3 @@
|
|
1
1
|
module MoonropeClient
|
2
|
-
VERSION = '1.0.
|
3
|
-
end
|
2
|
+
VERSION = '1.0.2'
|
3
|
+
end
|
data/lib/moonrope_client.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: moonrope-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Cooke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -63,6 +63,7 @@ files:
|
|
63
63
|
- lib/moonrope_client/controller.rb
|
64
64
|
- lib/moonrope_client/error.rb
|
65
65
|
- lib/moonrope_client/request.rb
|
66
|
+
- lib/moonrope_client/request_error.rb
|
66
67
|
- lib/moonrope_client/response.rb
|
67
68
|
- lib/moonrope_client/responses/access_denied.rb
|
68
69
|
- lib/moonrope_client/responses/paginated_collection.rb
|
@@ -90,9 +91,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
91
|
version: '0'
|
91
92
|
requirements: []
|
92
93
|
rubyforge_project:
|
93
|
-
rubygems_version: 2.
|
94
|
+
rubygems_version: 2.4.5
|
94
95
|
signing_key:
|
95
96
|
specification_version: 4
|
96
97
|
summary: A client library for the the Moonrope API server.
|
97
98
|
test_files: []
|
98
|
-
has_rdoc:
|