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,327 +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 Resource
         
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
                  include Utils
         
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
                  HREF_PROP_NAME = "href"
         
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
                  def initialize data_store, properties = {}
         
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
                    @data_store = data_store
         
     | 
| 
       29 
     | 
    
         
            -
                    @read_lock = Mutex.new
         
     | 
| 
       30 
     | 
    
         
            -
                    @write_lock = Mutex.new
         
     | 
| 
       31 
     | 
    
         
            -
                    @properties = Hash.new
         
     | 
| 
       32 
     | 
    
         
            -
                    @dirty_properties = Hash.new
         
     | 
| 
       33 
     | 
    
         
            -
                    set_properties properties
         
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
                  end
         
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
                  def set_properties properties
         
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
                    @write_lock.lock
         
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
                    begin
         
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
                      @properties.clear
         
     | 
| 
       44 
     | 
    
         
            -
                      @dirty_properties.clear
         
     | 
| 
       45 
     | 
    
         
            -
                      @dirty = false
         
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
                      if !properties.nil? and properties.is_a? Hash
         
     | 
| 
       48 
     | 
    
         
            -
                        @properties.replace properties
         
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
                        # Don't consider this resource materialized if it is only a reference.  A reference is any object that
         
     | 
| 
       51 
     | 
    
         
            -
                        # has only one 'href' property.
         
     | 
| 
       52 
     | 
    
         
            -
                        href_only = (@properties.size == 1 and @properties.has_key? HREF_PROP_NAME)
         
     | 
| 
       53 
     | 
    
         
            -
                        @materialized = !href_only
         
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       55 
     | 
    
         
            -
                      else
         
     | 
| 
       56 
     | 
    
         
            -
                        @materialized = false
         
     | 
| 
       57 
     | 
    
         
            -
                      end
         
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
       59 
     | 
    
         
            -
                    ensure
         
     | 
| 
       60 
     | 
    
         
            -
                      @write_lock.unlock
         
     | 
| 
       61 
     | 
    
         
            -
                    end
         
     | 
| 
       62 
     | 
    
         
            -
                  end
         
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
       64 
     | 
    
         
            -
                  def get_property name
         
     | 
| 
       65 
     | 
    
         
            -
             
     | 
| 
       66 
     | 
    
         
            -
                    if !HREF_PROP_NAME.eql? name
         
     | 
| 
       67 
     | 
    
         
            -
                      #not the href/id, must be a property that requires materialization:
         
     | 
| 
       68 
     | 
    
         
            -
                      if !is_new and !materialized
         
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
       70 
     | 
    
         
            -
                        # only materialize if the property hasn't been set previously (no need to execute a server
         
     | 
| 
       71 
     | 
    
         
            -
                        # request since we have the most recent value already):
         
     | 
| 
       72 
     | 
    
         
            -
                        present = false
         
     | 
| 
       73 
     | 
    
         
            -
                        @read_lock.lock
         
     | 
| 
       74 
     | 
    
         
            -
             
     | 
| 
       75 
     | 
    
         
            -
                        begin
         
     | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
       77 
     | 
    
         
            -
                          present = @dirty_properties.has_key? name
         
     | 
| 
       78 
     | 
    
         
            -
             
     | 
| 
       79 
     | 
    
         
            -
                        ensure
         
     | 
| 
       80 
     | 
    
         
            -
             
     | 
| 
       81 
     | 
    
         
            -
                          @read_lock.unlock
         
     | 
| 
       82 
     | 
    
         
            -
             
     | 
| 
       83 
     | 
    
         
            -
                        end
         
     | 
| 
       84 
     | 
    
         
            -
             
     | 
| 
       85 
     | 
    
         
            -
                        if !present
         
     | 
| 
       86 
     | 
    
         
            -
                          # exhausted present properties - we require a server call:
         
     | 
| 
       87 
     | 
    
         
            -
                          materialize
         
     | 
| 
       88 
     | 
    
         
            -
                        end
         
     | 
| 
       89 
     | 
    
         
            -
             
     | 
| 
       90 
     | 
    
         
            -
                      end
         
     | 
| 
       91 
     | 
    
         
            -
             
     | 
| 
       92 
     | 
    
         
            -
                    end
         
     | 
| 
       93 
     | 
    
         
            -
             
     | 
| 
       94 
     | 
    
         
            -
                    read_property name
         
     | 
| 
       95 
     | 
    
         
            -
                  end
         
     | 
| 
       96 
     | 
    
         
            -
             
     | 
| 
       97 
     | 
    
         
            -
                  def get_property_names
         
     | 
| 
       98 
     | 
    
         
            -
                    @read_lock.lock
         
     | 
| 
       99 
     | 
    
         
            -
             
     | 
| 
       100 
     | 
    
         
            -
                    begin
         
     | 
| 
       101 
     | 
    
         
            -
                      @properties.keys
         
     | 
| 
       102 
     | 
    
         
            -
                    ensure
         
     | 
| 
       103 
     | 
    
         
            -
                      @read_lock.unlock
         
     | 
| 
       104 
     | 
    
         
            -
                    end
         
     | 
| 
       105 
     | 
    
         
            -
             
     | 
| 
       106 
     | 
    
         
            -
                  end
         
     | 
| 
       107 
     | 
    
         
            -
             
     | 
| 
       108 
     | 
    
         
            -
                  def get_href
         
     | 
| 
       109 
     | 
    
         
            -
                    get_property HREF_PROP_NAME
         
     | 
| 
       110 
     | 
    
         
            -
                  end
         
     | 
| 
       111 
     | 
    
         
            -
             
     | 
| 
       112 
     | 
    
         
            -
                  def inspect
         
     | 
| 
       113 
     | 
    
         
            -
             
     | 
| 
       114 
     | 
    
         
            -
                    @read_lock.lock
         
     | 
| 
       115 
     | 
    
         
            -
             
     | 
| 
       116 
     | 
    
         
            -
                    str = ''
         
     | 
| 
       117 
     | 
    
         
            -
             
     | 
| 
       118 
     | 
    
         
            -
                    begin
         
     | 
| 
       119 
     | 
    
         
            -
             
     | 
| 
       120 
     | 
    
         
            -
                      counter = 2
         
     | 
| 
       121 
     | 
    
         
            -
                      @properties.each do |key, value|
         
     | 
| 
       122 
     | 
    
         
            -
             
     | 
| 
       123 
     | 
    
         
            -
                        if str.empty?
         
     | 
| 
       124 
     | 
    
         
            -
             
     | 
| 
       125 
     | 
    
         
            -
                          str = '#<' + class_name_with_id + ' @properties={'
         
     | 
| 
       126 
     | 
    
         
            -
             
     | 
| 
       127 
     | 
    
         
            -
                        else
         
     | 
| 
       128 
     | 
    
         
            -
             
     | 
| 
       129 
     | 
    
         
            -
                          if printable_property? key
         
     | 
| 
       130 
     | 
    
         
            -
             
     | 
| 
       131 
     | 
    
         
            -
                            str << "\"#{key}\"=>"
         
     | 
| 
       132 
     | 
    
         
            -
             
     | 
| 
       133 
     | 
    
         
            -
                            if value.kind_of? Hash and value.has_key? HREF_PROP_NAME
         
     | 
| 
       134 
     | 
    
         
            -
             
     | 
| 
       135 
     | 
    
         
            -
                              str << '{"' << HREF_PROP_NAME + '"=>"' + value[HREF_PROP_NAME] + '"}'
         
     | 
| 
       136 
     | 
    
         
            -
             
     | 
| 
       137 
     | 
    
         
            -
                            else
         
     | 
| 
       138 
     | 
    
         
            -
             
     | 
| 
       139 
     | 
    
         
            -
                              str << "\"#{value}\""
         
     | 
| 
       140 
     | 
    
         
            -
             
     | 
| 
       141 
     | 
    
         
            -
                            end
         
     | 
| 
       142 
     | 
    
         
            -
             
     | 
| 
       143 
     | 
    
         
            -
                            if counter < @properties.length
         
     | 
| 
       144 
     | 
    
         
            -
             
     | 
| 
       145 
     | 
    
         
            -
                              str << ', '
         
     | 
| 
       146 
     | 
    
         
            -
             
     | 
| 
       147 
     | 
    
         
            -
                            end
         
     | 
| 
       148 
     | 
    
         
            -
             
     | 
| 
       149 
     | 
    
         
            -
                          end
         
     | 
| 
       150 
     | 
    
         
            -
             
     | 
| 
       151 
     | 
    
         
            -
                          counter+= 1
         
     | 
| 
       152 
     | 
    
         
            -
             
     | 
| 
       153 
     | 
    
         
            -
                        end
         
     | 
| 
       154 
     | 
    
         
            -
             
     | 
| 
       155 
     | 
    
         
            -
                      end
         
     | 
| 
       156 
     | 
    
         
            -
             
     | 
| 
       157 
     | 
    
         
            -
                    ensure
         
     | 
| 
       158 
     | 
    
         
            -
             
     | 
| 
       159 
     | 
    
         
            -
                      @read_lock.unlock
         
     | 
| 
       160 
     | 
    
         
            -
             
     | 
| 
       161 
     | 
    
         
            -
                    end
         
     | 
| 
       162 
     | 
    
         
            -
             
     | 
| 
       163 
     | 
    
         
            -
                    if !str.empty?
         
     | 
| 
       164 
     | 
    
         
            -
                      str << '}>'
         
     | 
| 
       165 
     | 
    
         
            -
                    end
         
     | 
| 
       166 
     | 
    
         
            -
             
     | 
| 
       167 
     | 
    
         
            -
                    str
         
     | 
| 
       168 
     | 
    
         
            -
             
     | 
| 
       169 
     | 
    
         
            -
                  end
         
     | 
| 
       170 
     | 
    
         
            -
             
     | 
| 
       171 
     | 
    
         
            -
                  def to_s
         
     | 
| 
       172 
     | 
    
         
            -
                    '#<' + class_name_with_id + '>'
         
     | 
| 
       173 
     | 
    
         
            -
                  end
         
     | 
| 
       174 
     | 
    
         
            -
             
     | 
| 
       175 
     | 
    
         
            -
                  def to_yaml
         
     | 
| 
       176 
     | 
    
         
            -
             
     | 
| 
       177 
     | 
    
         
            -
                    yaml = '--- !ruby/object:' << self.class.name << "\n"
         
     | 
| 
       178 
     | 
    
         
            -
             
     | 
| 
       179 
     | 
    
         
            -
                    @read_lock.lock
         
     | 
| 
       180 
     | 
    
         
            -
             
     | 
| 
       181 
     | 
    
         
            -
                    begin
         
     | 
| 
       182 
     | 
    
         
            -
             
     | 
| 
       183 
     | 
    
         
            -
                      first_property = true
         
     | 
| 
       184 
     | 
    
         
            -
                      @properties.each do |key, value|
         
     | 
| 
       185 
     | 
    
         
            -
             
     | 
| 
       186 
     | 
    
         
            -
                        if printable_property? key
         
     | 
| 
       187 
     | 
    
         
            -
             
     | 
| 
       188 
     | 
    
         
            -
                          if first_property
         
     | 
| 
       189 
     | 
    
         
            -
             
     | 
| 
       190 
     | 
    
         
            -
                            yaml << " properties\n "
         
     | 
| 
       191 
     | 
    
         
            -
             
     | 
| 
       192 
     | 
    
         
            -
                          end
         
     | 
| 
       193 
     | 
    
         
            -
             
     | 
| 
       194 
     | 
    
         
            -
                          yaml << ' ' << key << ': ' << value << "\n"
         
     | 
| 
       195 
     | 
    
         
            -
             
     | 
| 
       196 
     | 
    
         
            -
                          first_property = false
         
     | 
| 
       197 
     | 
    
         
            -
             
     | 
| 
       198 
     | 
    
         
            -
                        end
         
     | 
| 
       199 
     | 
    
         
            -
             
     | 
| 
       200 
     | 
    
         
            -
                      end
         
     | 
| 
       201 
     | 
    
         
            -
             
     | 
| 
       202 
     | 
    
         
            -
                    ensure
         
     | 
| 
       203 
     | 
    
         
            -
             
     | 
| 
       204 
     | 
    
         
            -
                      @read_lock.unlock
         
     | 
| 
       205 
     | 
    
         
            -
             
     | 
| 
       206 
     | 
    
         
            -
                    end
         
     | 
| 
       207 
     | 
    
         
            -
             
     | 
| 
       208 
     | 
    
         
            -
                    yaml << "\n"
         
     | 
| 
       209 
     | 
    
         
            -
             
     | 
| 
       210 
     | 
    
         
            -
                  end
         
     | 
| 
       211 
     | 
    
         
            -
             
     | 
| 
       212 
     | 
    
         
            -
                  protected
         
     | 
| 
       213 
     | 
    
         
            -
             
     | 
| 
       214 
     | 
    
         
            -
                  attr_reader :data_store, :materialized
         
     | 
| 
       215 
     | 
    
         
            -
             
     | 
| 
       216 
     | 
    
         
            -
                  def get_resource_property key, clazz
         
     | 
| 
       217 
     | 
    
         
            -
             
     | 
| 
       218 
     | 
    
         
            -
                    value = get_property key
         
     | 
| 
       219 
     | 
    
         
            -
             
     | 
| 
       220 
     | 
    
         
            -
                    if value.is_a? Hash
         
     | 
| 
       221 
     | 
    
         
            -
                      href = get_href_from_hash value
         
     | 
| 
       222 
     | 
    
         
            -
                    end
         
     | 
| 
       223 
     | 
    
         
            -
             
     | 
| 
       224 
     | 
    
         
            -
                    if !href.nil?
         
     | 
| 
       225 
     | 
    
         
            -
                      @data_store.instantiate clazz, value
         
     | 
| 
       226 
     | 
    
         
            -
                    end
         
     | 
| 
       227 
     | 
    
         
            -
                  end
         
     | 
| 
       228 
     | 
    
         
            -
             
     | 
| 
       229 
     | 
    
         
            -
                  ##
         
     | 
| 
       230 
     | 
    
         
            -
                  # Returns {@code true} if the resource doesn't yet have an assigned 'href' property, {@code false} otherwise.
         
     | 
| 
       231 
     | 
    
         
            -
                  #
         
     | 
| 
       232 
     | 
    
         
            -
                  # @return {@code true} if the resource doesn't yet have an assigned 'href' property, {@code false} otherwise.
         
     | 
| 
       233 
     | 
    
         
            -
                  def is_new
         
     | 
| 
       234 
     | 
    
         
            -
             
     | 
| 
       235 
     | 
    
         
            -
                    #we can't call get_href in here, otherwise we'll have an infinite loop:
         
     | 
| 
       236 
     | 
    
         
            -
             
     | 
| 
       237 
     | 
    
         
            -
                    prop = read_property HREF_PROP_NAME
         
     | 
| 
       238 
     | 
    
         
            -
             
     | 
| 
       239 
     | 
    
         
            -
                    if prop.nil?
         
     | 
| 
       240 
     | 
    
         
            -
                      true
         
     | 
| 
       241 
     | 
    
         
            -
             
     | 
| 
       242 
     | 
    
         
            -
                    else
         
     | 
| 
       243 
     | 
    
         
            -
                      prop.respond_to? 'empty' and prop.empty?
         
     | 
| 
       244 
     | 
    
         
            -
                    end
         
     | 
| 
       245 
     | 
    
         
            -
             
     | 
| 
       246 
     | 
    
         
            -
                  end
         
     | 
| 
       247 
     | 
    
         
            -
             
     | 
| 
       248 
     | 
    
         
            -
                  def set_property name, value
         
     | 
| 
       249 
     | 
    
         
            -
             
     | 
| 
       250 
     | 
    
         
            -
                    @write_lock.lock
         
     | 
| 
       251 
     | 
    
         
            -
             
     | 
| 
       252 
     | 
    
         
            -
                    begin
         
     | 
| 
       253 
     | 
    
         
            -
                      @properties.store name, value
         
     | 
| 
       254 
     | 
    
         
            -
                      @dirty_properties.store name, value
         
     | 
| 
       255 
     | 
    
         
            -
                      @dirty = true
         
     | 
| 
       256 
     | 
    
         
            -
                    ensure
         
     | 
| 
       257 
     | 
    
         
            -
                      @write_lock.unlock
         
     | 
| 
       258 
     | 
    
         
            -
                    end
         
     | 
| 
       259 
     | 
    
         
            -
             
     | 
| 
       260 
     | 
    
         
            -
                  end
         
     | 
| 
       261 
     | 
    
         
            -
             
     | 
| 
       262 
     | 
    
         
            -
                  def materialize
         
     | 
| 
       263 
     | 
    
         
            -
                    clazz = to_class_from_instance self
         
     | 
| 
       264 
     | 
    
         
            -
             
     | 
| 
       265 
     | 
    
         
            -
                    @write_lock.lock
         
     | 
| 
       266 
     | 
    
         
            -
             
     | 
| 
       267 
     | 
    
         
            -
                    begin
         
     | 
| 
       268 
     | 
    
         
            -
             
     | 
| 
       269 
     | 
    
         
            -
                      resource = @data_store.get_resource get_href, clazz
         
     | 
| 
       270 
     | 
    
         
            -
                      @properties.replace resource.properties
         
     | 
| 
       271 
     | 
    
         
            -
             
     | 
| 
       272 
     | 
    
         
            -
                      #retain dirty properties:
         
     | 
| 
       273 
     | 
    
         
            -
                      @properties.merge! @dirty_properties
         
     | 
| 
       274 
     | 
    
         
            -
             
     | 
| 
       275 
     | 
    
         
            -
                      @materialized = true
         
     | 
| 
       276 
     | 
    
         
            -
             
     | 
| 
       277 
     | 
    
         
            -
                    ensure
         
     | 
| 
       278 
     | 
    
         
            -
             
     | 
| 
       279 
     | 
    
         
            -
                      @write_lock.unlock
         
     | 
| 
       280 
     | 
    
         
            -
                    end
         
     | 
| 
       281 
     | 
    
         
            -
             
     | 
| 
       282 
     | 
    
         
            -
                  end
         
     | 
| 
       283 
     | 
    
         
            -
             
     | 
| 
       284 
     | 
    
         
            -
                  def properties
         
     | 
| 
       285 
     | 
    
         
            -
                    @properties
         
     | 
| 
       286 
     | 
    
         
            -
                  end
         
     | 
| 
       287 
     | 
    
         
            -
             
     | 
| 
       288 
     | 
    
         
            -
                  ##
         
     | 
| 
       289 
     | 
    
         
            -
                  # Returns {@code true} if the internal property is safe to print in to_s or inspect, {@code false} otherwise.
         
     | 
| 
       290 
     | 
    
         
            -
                  #
         
     | 
| 
       291 
     | 
    
         
            -
                  # @param property_name The name of the property to check for safe printing
         
     | 
| 
       292 
     | 
    
         
            -
                  # @return {@code true} if the internal property is safe to print in to_s, {@code false} otherwise.
         
     | 
| 
       293 
     | 
    
         
            -
                  def printable_property? property_name
         
     | 
| 
       294 
     | 
    
         
            -
             
     | 
| 
       295 
     | 
    
         
            -
                    return true
         
     | 
| 
       296 
     | 
    
         
            -
             
     | 
| 
       297 
     | 
    
         
            -
                  end
         
     | 
| 
       298 
     | 
    
         
            -
             
     | 
| 
       299 
     | 
    
         
            -
                  private
         
     | 
| 
       300 
     | 
    
         
            -
             
     | 
| 
       301 
     | 
    
         
            -
                  def get_href_from_hash(props)
         
     | 
| 
       302 
     | 
    
         
            -
             
     | 
| 
       303 
     | 
    
         
            -
                    if !props.nil? and props.is_a? Hash
         
     | 
| 
       304 
     | 
    
         
            -
                      value = props[HREF_PROP_NAME]
         
     | 
| 
       305 
     | 
    
         
            -
                    end
         
     | 
| 
       306 
     | 
    
         
            -
             
     | 
| 
       307 
     | 
    
         
            -
                    value
         
     | 
| 
       308 
     | 
    
         
            -
                  end
         
     | 
| 
       309 
     | 
    
         
            -
             
     | 
| 
       310 
     | 
    
         
            -
                  def read_property name
         
     | 
| 
       311 
     | 
    
         
            -
                    @read_lock.lock
         
     | 
| 
       312 
     | 
    
         
            -
             
     | 
| 
       313 
     | 
    
         
            -
                    begin
         
     | 
| 
       314 
     | 
    
         
            -
                      @properties[name]
         
     | 
| 
       315 
     | 
    
         
            -
                    ensure
         
     | 
| 
       316 
     | 
    
         
            -
                      @read_lock.unlock
         
     | 
| 
       317 
     | 
    
         
            -
                    end
         
     | 
| 
       318 
     | 
    
         
            -
             
     | 
| 
       319 
     | 
    
         
            -
                  end
         
     | 
| 
       320 
     | 
    
         
            -
             
     | 
| 
       321 
     | 
    
         
            -
                  def class_name_with_id
         
     | 
| 
       322 
     | 
    
         
            -
                    self.class.name + ':0x' + ('%x' % (self.object_id << 1)).to_s
         
     | 
| 
       323 
     | 
    
         
            -
                  end
         
     | 
| 
       324 
     | 
    
         
            -
                end
         
     | 
| 
       325 
     | 
    
         
            -
              end
         
     | 
| 
       326 
     | 
    
         
            -
             
     | 
| 
       327 
     | 
    
         
            -
            end
         
     | 
| 
         @@ -1,47 +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 ResourceError < RuntimeError
         
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
                  def initialize error
         
     | 
| 
       23 
     | 
    
         
            -
                    super !error.nil? ? error.get_message : ''
         
     | 
| 
       24 
     | 
    
         
            -
                    @error = error
         
     | 
| 
       25 
     | 
    
         
            -
                  end
         
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
                  def get_status
         
     | 
| 
       28 
     | 
    
         
            -
                    !@error.nil? ? @error.get_status : -1
         
     | 
| 
       29 
     | 
    
         
            -
                  end
         
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
                  def get_code
         
     | 
| 
       32 
     | 
    
         
            -
                    !@error.nil? ? @error.get_code : -1
         
     | 
| 
       33 
     | 
    
         
            -
                  end
         
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
                  def get_developer_message
         
     | 
| 
       36 
     | 
    
         
            -
                    !@error.nil? ? @error.get_developer_message : nil
         
     | 
| 
       37 
     | 
    
         
            -
                  end
         
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
                  def get_more_info
         
     | 
| 
       40 
     | 
    
         
            -
                    !@error.nil? ? @error.get_more_info : nil
         
     | 
| 
       41 
     | 
    
         
            -
                  end
         
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
                end
         
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
              end
         
     | 
| 
       46 
     | 
    
         
            -
            end
         
     | 
| 
       47 
     | 
    
         
            -
             
     | 
    
        data/test/client/client.yml
    DELETED
    
    | 
         @@ -1,16 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            apiKey.id: myApiKeyId
         
     | 
| 
       2 
     | 
    
         
            -
            apiKey.secret: myApkiKeySecret
         
     | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
            different.apiKey.id: myApiKeyId
         
     | 
| 
       5 
     | 
    
         
            -
            different.apiKey.secret: myApkiKeySecret
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
            stormpath:
         
     | 
| 
       9 
     | 
    
         
            -
              apiKey:
         
     | 
| 
       10 
     | 
    
         
            -
                id: myApiKeyId
         
     | 
| 
       11 
     | 
    
         
            -
                secret: myApkiKeySecret
         
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
            different.stormpath:
         
     | 
| 
       14 
     | 
    
         
            -
              different.apiKey:
         
     | 
| 
       15 
     | 
    
         
            -
                different.id: myApiKeyId
         
     | 
| 
       16 
     | 
    
         
            -
                different.secret: myApkiKeySecret
         
     | 
| 
         @@ -1,114 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require "stormpath-sdk"
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            include Stormpath::Client
         
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
            describe "Client Application Builder Tests" do
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
              before(:all) do
         
     | 
| 
       8 
     | 
    
         
            -
                @client_file = 'test/client/client.yml'
         
     | 
| 
       9 
     | 
    
         
            -
                @client_remote_file = 'http://localhost:8081/client.yml'
         
     | 
| 
       10 
     | 
    
         
            -
                @application_href = 'http://localhost:8080/v1/applications/uGBNDZ7TRhm_tahanqvn9A'
         
     | 
| 
       11 
     | 
    
         
            -
                @http_prefix = 'http://'
         
     | 
| 
       12 
     | 
    
         
            -
                @app_href_without_http = '@localhost:8080/v1/applications/uGBNDZ7TRhm_tahanqvn9A'
         
     | 
| 
       13 
     | 
    
         
            -
                @client_builder = ClientBuilder.new.set_base_url 'http://localhost:8080/v1'
         
     | 
| 
       14 
     | 
    
         
            -
                @test_remote_file = false
         
     | 
| 
       15 
     | 
    
         
            -
              end
         
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
              it 'Builder should read default properties from YAML file location with application href' do
         
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
                result = ClientApplicationBuilder.new(@client_builder).
         
     | 
| 
       21 
     | 
    
         
            -
                    set_api_key_file_location(@client_file).
         
     | 
| 
       22 
     | 
    
         
            -
                    set_application_href(@application_href).
         
     | 
| 
       23 
     | 
    
         
            -
                    build
         
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
                result.should be_kind_of ClientApplication
         
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
              end
         
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
              it 'Builder should create ClientApplication with data from application href with credentials' do
         
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
                # getting the properties from file...just to avoid writing them directly
         
     | 
| 
       32 
     | 
    
         
            -
                # in the 'properties' Hash
         
     | 
| 
       33 
     | 
    
         
            -
                yml_obj = YAML::load(File.open @client_file)
         
     | 
| 
       34 
     | 
    
         
            -
                api_key_id_keyword = 'apiKey.id'
         
     | 
| 
       35 
     | 
    
         
            -
                api_key_secret_keyword = 'apiKey.secret'
         
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
                # we create the client from this Hash instead of from a file
         
     | 
| 
       38 
     | 
    
         
            -
                properties = {api_key_id_keyword => yml_obj[api_key_id_keyword],
         
     | 
| 
       39 
     | 
    
         
            -
                              api_key_secret_keyword => yml_obj[api_key_secret_keyword]}
         
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
                application_href = @http_prefix +
         
     | 
| 
       42 
     | 
    
         
            -
                    properties[api_key_id_keyword] +
         
     | 
| 
       43 
     | 
    
         
            -
                    ':' +
         
     | 
| 
       44 
     | 
    
         
            -
                    properties[api_key_secret_keyword] +
         
     | 
| 
       45 
     | 
    
         
            -
                    @app_href_without_http
         
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
                result = ClientApplicationBuilder.new(@client_builder).
         
     | 
| 
       48 
     | 
    
         
            -
                    set_application_href(application_href).
         
     | 
| 
       49 
     | 
    
         
            -
                    build
         
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
                result.should be_kind_of ClientApplication
         
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       53 
     | 
    
         
            -
              end
         
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       55 
     | 
    
         
            -
              it 'Builder should read custom complex properties from YAML file locatio with application href' do
         
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
                @client_builder = ClientBuilder.new.set_base_url 'http://localhost:8080/v1'
         
     | 
| 
       58 
     | 
    
         
            -
                result = ClientApplicationBuilder.new(@client_builder).
         
     | 
| 
       59 
     | 
    
         
            -
                    set_api_key_file_location(@client_file).
         
     | 
| 
       60 
     | 
    
         
            -
                    set_api_key_id_property_name('stormpath', 'apiKey', 'id').
         
     | 
| 
       61 
     | 
    
         
            -
                    set_api_key_secret_property_name('stormpath', 'apiKey', 'secret').
         
     | 
| 
       62 
     | 
    
         
            -
                    set_application_href(@application_href).
         
     | 
| 
       63 
     | 
    
         
            -
                    build
         
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
       65 
     | 
    
         
            -
                result.should be_kind_of ClientApplication
         
     | 
| 
       66 
     | 
    
         
            -
             
     | 
| 
       67 
     | 
    
         
            -
              end
         
     | 
| 
       68 
     | 
    
         
            -
             
     | 
| 
       69 
     | 
    
         
            -
              it 'Builder should read custom simple properties from YAML file locatio with application href' do
         
     | 
| 
       70 
     | 
    
         
            -
             
     | 
| 
       71 
     | 
    
         
            -
                # getting the properties from file...just to avoid writing them directly
         
     | 
| 
       72 
     | 
    
         
            -
                # in the 'properties' Hash
         
     | 
| 
       73 
     | 
    
         
            -
                yml_obj = YAML::load(File.open @client_file)
         
     | 
| 
       74 
     | 
    
         
            -
                api_key_id_keyword = 'different.apiKey.id'
         
     | 
| 
       75 
     | 
    
         
            -
                api_key_secret_keyword = 'different.apiKey.secret'
         
     | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
       77 
     | 
    
         
            -
                # we create the client from this Hash instead of from a file
         
     | 
| 
       78 
     | 
    
         
            -
                properties = {api_key_id_keyword => yml_obj[api_key_id_keyword],
         
     | 
| 
       79 
     | 
    
         
            -
                              api_key_secret_keyword => yml_obj[api_key_secret_keyword]}
         
     | 
| 
       80 
     | 
    
         
            -
             
     | 
| 
       81 
     | 
    
         
            -
                result = ClientApplicationBuilder.new(@client_builder).
         
     | 
| 
       82 
     | 
    
         
            -
                    set_api_key_properties(properties.to_yaml).
         
     | 
| 
       83 
     | 
    
         
            -
                    set_api_key_id_property_name(api_key_id_keyword).
         
     | 
| 
       84 
     | 
    
         
            -
                    set_api_key_secret_property_name(api_key_secret_keyword).
         
     | 
| 
       85 
     | 
    
         
            -
                    set_application_href(@application_href).
         
     | 
| 
       86 
     | 
    
         
            -
                    build
         
     | 
| 
       87 
     | 
    
         
            -
             
     | 
| 
       88 
     | 
    
         
            -
                result.should be_kind_of ClientApplication
         
     | 
| 
       89 
     | 
    
         
            -
             
     | 
| 
       90 
     | 
    
         
            -
              end
         
     | 
| 
       91 
     | 
    
         
            -
             
     | 
| 
       92 
     | 
    
         
            -
              it 'Builder should throw exception when creating it with wrong argument' do
         
     | 
| 
       93 
     | 
    
         
            -
             
     | 
| 
       94 
     | 
    
         
            -
                expect { ClientApplicationBuilder.new 'WRONG' }.to raise_error ArgumentError
         
     | 
| 
       95 
     | 
    
         
            -
             
     | 
| 
       96 
     | 
    
         
            -
              end
         
     | 
| 
       97 
     | 
    
         
            -
             
     | 
| 
       98 
     | 
    
         
            -
              it 'Builder should throw exception when trying to build without application href' do
         
     | 
| 
       99 
     | 
    
         
            -
             
     | 
| 
       100 
     | 
    
         
            -
                expect { ClientApplicationBuilder.new(@client_builder).build }.to raise_error ArgumentError
         
     | 
| 
       101 
     | 
    
         
            -
             
     | 
| 
       102 
     | 
    
         
            -
              end
         
     | 
| 
       103 
     | 
    
         
            -
             
     | 
| 
       104 
     | 
    
         
            -
              it 'Builder should throw exception when trying to build with an invalid application href' do
         
     | 
| 
       105 
     | 
    
         
            -
             
     | 
| 
       106 
     | 
    
         
            -
                expect { ClientApplicationBuilder.new(@client_builder).
         
     | 
| 
       107 
     | 
    
         
            -
                    set_api_key_file_location(@client_file).
         
     | 
| 
       108 
     | 
    
         
            -
                    set_application_href('id:secret@stormpath.com/v1').
         
     | 
| 
       109 
     | 
    
         
            -
                    build }.
         
     | 
| 
       110 
     | 
    
         
            -
                    to raise_error ArgumentError
         
     | 
| 
       111 
     | 
    
         
            -
             
     | 
| 
       112 
     | 
    
         
            -
              end
         
     | 
| 
       113 
     | 
    
         
            -
             
     | 
| 
       114 
     | 
    
         
            -
            end
         
     |