stormpath-sdk 0.4.0 → 1.0.0.beta
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.
- data/.gitignore +6 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +27 -0
- data/CHANGES.md +21 -1
- data/Gemfile +1 -2
- data/README.md +457 -11
- data/Rakefile +15 -1
- data/lib/stormpath-sdk.rb +52 -33
- data/lib/stormpath-sdk/{resource/group_list.rb → api_key.rb} +5 -9
- data/lib/stormpath-sdk/auth/authentication_result.rb +3 -13
- data/lib/stormpath-sdk/auth/basic_authenticator.rb +5 -11
- data/lib/stormpath-sdk/auth/basic_login_attempt.rb +6 -8
- data/lib/stormpath-sdk/auth/username_password_request.rb +2 -5
- data/lib/stormpath-sdk/cache/cache.rb +54 -0
- data/lib/stormpath-sdk/cache/cache_entry.rb +33 -0
- data/lib/stormpath-sdk/cache/cache_manager.rb +22 -0
- data/lib/stormpath-sdk/cache/cache_stats.rb +35 -0
- data/lib/stormpath-sdk/cache/memory_store.rb +29 -0
- data/lib/stormpath-sdk/cache/redis_store.rb +32 -0
- data/lib/stormpath-sdk/client.rb +111 -0
- data/lib/stormpath-sdk/data_store.rb +241 -0
- data/lib/stormpath-sdk/{client/api_key.rb → error.rb} +16 -10
- data/lib/stormpath-sdk/{util → ext}/hash.rb +1 -2
- data/lib/stormpath-sdk/http/authc/sauthc1_signer.rb +8 -4
- data/lib/stormpath-sdk/http/http_client_request_executor.rb +8 -7
- data/lib/stormpath-sdk/http/request.rb +4 -8
- data/lib/stormpath-sdk/{util/request_utils.rb → http/utils.rb} +17 -38
- data/lib/stormpath-sdk/resource/account.rb +12 -108
- data/lib/stormpath-sdk/resource/application.rb +35 -171
- data/lib/stormpath-sdk/resource/associations.rb +97 -0
- data/lib/stormpath-sdk/resource/base.rb +256 -0
- data/lib/stormpath-sdk/resource/collection.rb +94 -0
- data/lib/stormpath-sdk/resource/directory.rb +11 -68
- data/lib/stormpath-sdk/resource/email_verification_token.rb +3 -9
- data/lib/stormpath-sdk/resource/error.rb +4 -38
- data/lib/stormpath-sdk/resource/expansion.rb +28 -0
- data/lib/stormpath-sdk/resource/group.rb +8 -66
- data/lib/stormpath-sdk/resource/group_membership.rb +4 -55
- data/lib/stormpath-sdk/resource/{application_list.rb → instance.rb} +7 -13
- data/lib/stormpath-sdk/resource/password_reset_token.rb +5 -23
- data/lib/stormpath-sdk/resource/status.rb +22 -28
- data/lib/stormpath-sdk/resource/tenant.rb +5 -52
- data/lib/stormpath-sdk/resource/utils.rb +43 -13
- data/lib/stormpath-sdk/util/assert.rb +5 -15
- data/lib/stormpath-sdk/version.rb +3 -3
- data/spec/api_key_spec.rb +19 -0
- data/spec/auth/basic_authenticator_spec.rb +25 -0
- data/spec/auth/sauthc1_signer_spec.rb +42 -0
- data/spec/cache/cache_entry_spec.rb +157 -0
- data/spec/cache/cache_spec.rb +89 -0
- data/spec/cache/cache_stats_spec.rb +106 -0
- data/spec/client_spec.rb +538 -0
- data/spec/data_store_spec.rb +130 -0
- data/spec/resource/account_spec.rb +74 -0
- data/spec/resource/application_spec.rb +148 -0
- data/spec/resource/base_spec.rb +114 -0
- data/spec/resource/collection_spec.rb +169 -0
- data/spec/resource/directory_spec.rb +30 -0
- data/spec/resource/expansion_spec.rb +100 -0
- data/spec/resource/group_spec.rb +49 -0
- data/spec/spec_helper.rb +135 -0
- data/spec/support/resource_factory.rb +48 -0
- data/spec/support/resource_matchers.rb +27 -0
- data/spec/support/test_cache_stores.rb +9 -0
- data/spec/support/test_request_executor.rb +11 -0
- data/stormpath-sdk.gemspec +14 -4
- data/support/api.rb +55 -0
- metadata +214 -44
- data/lib/stormpath-sdk/client/client.rb +0 -38
- data/lib/stormpath-sdk/client/client_application.rb +0 -38
- data/lib/stormpath-sdk/client/client_application_builder.rb +0 -351
- data/lib/stormpath-sdk/client/client_builder.rb +0 -305
- data/lib/stormpath-sdk/ds/data_store.rb +0 -210
- data/lib/stormpath-sdk/ds/resource_factory.rb +0 -37
- data/lib/stormpath-sdk/resource/account_list.rb +0 -32
- data/lib/stormpath-sdk/resource/collection_resource.rb +0 -91
- data/lib/stormpath-sdk/resource/directory_list.rb +0 -30
- data/lib/stormpath-sdk/resource/group_membership_list.rb +0 -32
- data/lib/stormpath-sdk/resource/instance_resource.rb +0 -28
- data/lib/stormpath-sdk/resource/resource.rb +0 -327
- data/lib/stormpath-sdk/resource/resource_error.rb +0 -47
- data/test/client/client.yml +0 -16
- data/test/client/client_application_builder_spec.rb +0 -114
- data/test/client/client_builder_spec.rb +0 -176
- data/test/client/read_spec.rb +0 -254
- data/test/client/write_spec.rb +0 -420
- data/test/resource/resource_spec.rb +0 -41
- data/test/resource/test_resource.rb +0 -28
@@ -1,210 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Copyright 2012 Stormpath, Inc.
|
3
|
-
#
|
4
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
# you may not use this file except in compliance with the License.
|
6
|
-
# You may obtain a copy of the License at
|
7
|
-
#
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
#
|
10
|
-
# Unless required by applicable law or agreed to in writing, software
|
11
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
# See the License for the specific language governing permissions and
|
14
|
-
# limitations under the License.
|
15
|
-
#
|
16
|
-
module Stormpath
|
17
|
-
|
18
|
-
module DataStore
|
19
|
-
|
20
|
-
class DataStore
|
21
|
-
|
22
|
-
include Stormpath::Http
|
23
|
-
include Stormpath::Resource
|
24
|
-
include Stormpath::Resource::Utils
|
25
|
-
include Stormpath::Util::Assert
|
26
|
-
|
27
|
-
DEFAULT_SERVER_HOST = "api.stormpath.com"
|
28
|
-
|
29
|
-
DEFAULT_API_VERSION = 1
|
30
|
-
|
31
|
-
def initialize(request_executor, *base_url)
|
32
|
-
|
33
|
-
assert_not_nil request_executor, "RequestExecutor cannot be null."
|
34
|
-
@base_url = get_base_url *base_url
|
35
|
-
@request_executor = request_executor
|
36
|
-
@resource_factory = ResourceFactory.new(self)
|
37
|
-
end
|
38
|
-
|
39
|
-
def instantiate(clazz, properties = {})
|
40
|
-
|
41
|
-
@resource_factory.instantiate(clazz, properties)
|
42
|
-
end
|
43
|
-
|
44
|
-
def get_resource(href, clazz)
|
45
|
-
|
46
|
-
q_href = href
|
47
|
-
|
48
|
-
if needs_to_be_fully_qualified q_href
|
49
|
-
q_href = qualify q_href
|
50
|
-
end
|
51
|
-
|
52
|
-
data = execute_request('get', q_href, nil)
|
53
|
-
@resource_factory.instantiate(clazz, data.to_hash)
|
54
|
-
|
55
|
-
end
|
56
|
-
|
57
|
-
def create parent_href, resource, return_type
|
58
|
-
|
59
|
-
returned_resource = save_resource parent_href, resource, return_type
|
60
|
-
|
61
|
-
if resource.kind_of? return_type
|
62
|
-
|
63
|
-
resource.set_properties to_hash(returned_resource)
|
64
|
-
|
65
|
-
end
|
66
|
-
|
67
|
-
returned_resource
|
68
|
-
|
69
|
-
end
|
70
|
-
|
71
|
-
def save resource, *clazz
|
72
|
-
assert_not_nil resource, "resource argument cannot be null."
|
73
|
-
assert_kind_of Stormpath::Resource::Resource, resource, "resource argument must be instance of Stormpath::Resource::Resource"
|
74
|
-
|
75
|
-
href = resource.get_href
|
76
|
-
assert_true href.length > 0, "save may only be called on objects that have already been persisted (i.e. they have an existing href)."
|
77
|
-
|
78
|
-
if needs_to_be_fully_qualified(href)
|
79
|
-
href = qualify(href)
|
80
|
-
end
|
81
|
-
|
82
|
-
clazz = (clazz.nil? or clazz.length == 0) ? to_class_from_instance(resource) : clazz[0]
|
83
|
-
|
84
|
-
return_value = save_resource href, resource, clazz
|
85
|
-
|
86
|
-
#ensure the caller's argument is updated with what is returned from the server:
|
87
|
-
resource.set_properties to_hash(return_value)
|
88
|
-
|
89
|
-
return_value
|
90
|
-
|
91
|
-
end
|
92
|
-
|
93
|
-
def delete resource
|
94
|
-
|
95
|
-
assert_not_nil resource, "resource argument cannot be null."
|
96
|
-
assert_kind_of Stormpath::Resource::Resource, resource, "resource argument must be instance of Stormpath::Resource::Resource"
|
97
|
-
|
98
|
-
execute_request('delete', resource.get_href, nil)
|
99
|
-
|
100
|
-
end
|
101
|
-
|
102
|
-
protected
|
103
|
-
|
104
|
-
def needs_to_be_fully_qualified href
|
105
|
-
!href.downcase.start_with? 'http'
|
106
|
-
end
|
107
|
-
|
108
|
-
def qualify href
|
109
|
-
|
110
|
-
slash_added = ''
|
111
|
-
|
112
|
-
if !href.start_with? '/'
|
113
|
-
slash_added = '/'
|
114
|
-
end
|
115
|
-
|
116
|
-
@base_url + slash_added + href
|
117
|
-
end
|
118
|
-
|
119
|
-
private
|
120
|
-
|
121
|
-
def execute_request(http_method, href, body)
|
122
|
-
|
123
|
-
request = Request.new(http_method, href, nil, Hash.new, body)
|
124
|
-
apply_default_request_headers request
|
125
|
-
response = @request_executor.execute_request request
|
126
|
-
|
127
|
-
result = response.body.length > 0 ? MultiJson.load(response.body) : ''
|
128
|
-
|
129
|
-
if response.error?
|
130
|
-
error = Error.new result
|
131
|
-
raise ResourceError.new error
|
132
|
-
end
|
133
|
-
|
134
|
-
result
|
135
|
-
end
|
136
|
-
|
137
|
-
def apply_default_request_headers request
|
138
|
-
|
139
|
-
request.http_headers.store 'Accept', 'application/json'
|
140
|
-
request.http_headers.store 'User-Agent', 'Stormpath-RubySDK/' + Stormpath::VERSION
|
141
|
-
|
142
|
-
if !request.body.nil? and request.body.length > 0
|
143
|
-
request.http_headers.store 'Content-Type', 'application/json'
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
def save_resource href, resource, return_type
|
148
|
-
|
149
|
-
assert_not_nil resource, "resource argument cannot be null."
|
150
|
-
assert_not_nil return_type, "returnType class cannot be null."
|
151
|
-
assert_kind_of Stormpath::Resource::Resource, resource, "resource argument must be instance of Stormpath::Resource::Resource"
|
152
|
-
|
153
|
-
q_href = href
|
154
|
-
|
155
|
-
if needs_to_be_fully_qualified q_href
|
156
|
-
q_href = qualify q_href
|
157
|
-
end
|
158
|
-
|
159
|
-
response = execute_request('post', q_href, MultiJson.dump(to_hash(resource)))
|
160
|
-
@resource_factory.instantiate(return_type, response.to_hash)
|
161
|
-
|
162
|
-
end
|
163
|
-
|
164
|
-
def get_base_url *base_url
|
165
|
-
(!base_url.empty? and !base_url[0].nil?) ?
|
166
|
-
base_url[0] :
|
167
|
-
"https://" + DEFAULT_SERVER_HOST + "/v" + DEFAULT_API_VERSION.to_s
|
168
|
-
end
|
169
|
-
|
170
|
-
def to_hash resource
|
171
|
-
|
172
|
-
property_names = resource.get_property_names
|
173
|
-
properties = Hash.new
|
174
|
-
|
175
|
-
property_names.each do |name|
|
176
|
-
|
177
|
-
property = resource.get_property name
|
178
|
-
|
179
|
-
if property.kind_of? Hash
|
180
|
-
|
181
|
-
property = to_simple_reference name, property
|
182
|
-
|
183
|
-
end
|
184
|
-
|
185
|
-
properties.store name, property
|
186
|
-
|
187
|
-
end
|
188
|
-
|
189
|
-
properties
|
190
|
-
|
191
|
-
end
|
192
|
-
|
193
|
-
def to_simple_reference property_name, hash
|
194
|
-
|
195
|
-
href_prop_name = Resource::Resource::HREF_PROP_NAME
|
196
|
-
assert_true (hash.kind_of? Hash and !hash.empty? and hash.has_key? href_prop_name), "Nested resource " +
|
197
|
-
"'#{property_name}' must have an 'href' property."
|
198
|
-
|
199
|
-
href = hash[href_prop_name]
|
200
|
-
|
201
|
-
{href_prop_name => href}
|
202
|
-
|
203
|
-
end
|
204
|
-
|
205
|
-
end
|
206
|
-
|
207
|
-
end
|
208
|
-
|
209
|
-
end
|
210
|
-
|
@@ -1,37 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Copyright 2012 Stormpath, Inc.
|
3
|
-
#
|
4
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
# you may not use this file except in compliance with the License.
|
6
|
-
# You may obtain a copy of the License at
|
7
|
-
#
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
#
|
10
|
-
# Unless required by applicable law or agreed to in writing, software
|
11
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
# See the License for the specific language governing permissions and
|
14
|
-
# limitations under the License.
|
15
|
-
#
|
16
|
-
module Stormpath
|
17
|
-
|
18
|
-
module DataStore
|
19
|
-
|
20
|
-
class ResourceFactory
|
21
|
-
|
22
|
-
def initialize(data_store)
|
23
|
-
|
24
|
-
@data_store = data_store
|
25
|
-
end
|
26
|
-
|
27
|
-
def instantiate(clazz, constructor_args = {})
|
28
|
-
|
29
|
-
clazz.new @data_store, constructor_args
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
37
|
-
|
@@ -1,32 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Copyright 2012 Stormpath, Inc.
|
3
|
-
#
|
4
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
# you may not use this file except in compliance with the License.
|
6
|
-
# You may obtain a copy of the License at
|
7
|
-
#
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
#
|
10
|
-
# Unless required by applicable law or agreed to in writing, software
|
11
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
# See the License for the specific language governing permissions and
|
14
|
-
# limitations under the License.
|
15
|
-
#
|
16
|
-
module Stormpath
|
17
|
-
|
18
|
-
module Resource
|
19
|
-
|
20
|
-
class AccountList < CollectionResource
|
21
|
-
|
22
|
-
def get_item_type
|
23
|
-
|
24
|
-
Account
|
25
|
-
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
|
-
|
@@ -1,91 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Copyright 2012 Stormpath, Inc.
|
3
|
-
#
|
4
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
# you may not use this file except in compliance with the License.
|
6
|
-
# You may obtain a copy of the License at
|
7
|
-
#
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
#
|
10
|
-
# Unless required by applicable law or agreed to in writing, software
|
11
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
# See the License for the specific language governing permissions and
|
14
|
-
# limitations under the License.
|
15
|
-
#
|
16
|
-
module Stormpath
|
17
|
-
|
18
|
-
module Resource
|
19
|
-
|
20
|
-
class CollectionResource < Resource
|
21
|
-
|
22
|
-
OFFSET = "offset"
|
23
|
-
LIMIT = "limit"
|
24
|
-
ITEMS = "items"
|
25
|
-
|
26
|
-
def each(&block)
|
27
|
-
get_current_page.items.each(&block)
|
28
|
-
end
|
29
|
-
|
30
|
-
protected
|
31
|
-
|
32
|
-
def get_offset
|
33
|
-
get_property OFFSET
|
34
|
-
end
|
35
|
-
|
36
|
-
def get_limit
|
37
|
-
get_property LIMIT
|
38
|
-
end
|
39
|
-
|
40
|
-
def get_current_page
|
41
|
-
|
42
|
-
value = get_property ITEMS
|
43
|
-
items = to_resource_array value
|
44
|
-
|
45
|
-
Page.new get_offset, get_limit, items
|
46
|
-
end
|
47
|
-
|
48
|
-
def to_resource clazz, properties
|
49
|
-
self.data_store.instantiate clazz, properties
|
50
|
-
end
|
51
|
-
|
52
|
-
private
|
53
|
-
|
54
|
-
def to_resource_array vals
|
55
|
-
|
56
|
-
clazz = get_item_type
|
57
|
-
items = Array.new
|
58
|
-
|
59
|
-
if vals.is_a? Array
|
60
|
-
|
61
|
-
i = 0
|
62
|
-
vals.each { |val|
|
63
|
-
resource = to_resource clazz, val
|
64
|
-
items[i] = resource
|
65
|
-
i = i + 1
|
66
|
-
}
|
67
|
-
|
68
|
-
end
|
69
|
-
|
70
|
-
items
|
71
|
-
|
72
|
-
end
|
73
|
-
|
74
|
-
end
|
75
|
-
|
76
|
-
|
77
|
-
class Page
|
78
|
-
|
79
|
-
attr_reader :offset, :limit, :items
|
80
|
-
|
81
|
-
def initialize offset, limit, items
|
82
|
-
@offset = offset
|
83
|
-
@limit = limit
|
84
|
-
@items = items
|
85
|
-
end
|
86
|
-
|
87
|
-
end
|
88
|
-
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
@@ -1,30 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Copyright 2012 Stormpath, Inc.
|
3
|
-
#
|
4
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
# you may not use this file except in compliance with the License.
|
6
|
-
# You may obtain a copy of the License at
|
7
|
-
#
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
#
|
10
|
-
# Unless required by applicable law or agreed to in writing, software
|
11
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
# See the License for the specific language governing permissions and
|
14
|
-
# limitations under the License.
|
15
|
-
#
|
16
|
-
module Stormpath
|
17
|
-
|
18
|
-
module Resource
|
19
|
-
|
20
|
-
class DirectoryList < CollectionResource
|
21
|
-
|
22
|
-
def get_item_type
|
23
|
-
Directory
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
@@ -1,32 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Copyright 2012 Stormpath, Inc.
|
3
|
-
#
|
4
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
# you may not use this file except in compliance with the License.
|
6
|
-
# You may obtain a copy of the License at
|
7
|
-
#
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
#
|
10
|
-
# Unless required by applicable law or agreed to in writing, software
|
11
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
# See the License for the specific language governing permissions and
|
14
|
-
# limitations under the License.
|
15
|
-
#
|
16
|
-
module Stormpath
|
17
|
-
|
18
|
-
module Resource
|
19
|
-
|
20
|
-
class GroupMembershipList < CollectionResource
|
21
|
-
|
22
|
-
def get_item_type
|
23
|
-
|
24
|
-
GroupMembership
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Copyright 2012 Stormpath, Inc.
|
3
|
-
#
|
4
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
# you may not use this file except in compliance with the License.
|
6
|
-
# You may obtain a copy of the License at
|
7
|
-
#
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
#
|
10
|
-
# Unless required by applicable law or agreed to in writing, software
|
11
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
# See the License for the specific language governing permissions and
|
14
|
-
# limitations under the License.
|
15
|
-
#
|
16
|
-
module Stormpath
|
17
|
-
|
18
|
-
module Resource
|
19
|
-
|
20
|
-
class InstanceResource < Resource
|
21
|
-
|
22
|
-
def save
|
23
|
-
data_store.save self
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|