Skip to content

Commit

Permalink
Client instance is now accessible with KOSapiClient.client reader.
Browse files Browse the repository at this point in the history
  • Loading branch information
tszolar committed May 27, 2014
1 parent 7ca8902 commit d612909
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ client.parallels.find(42)
```

The other way is to use configure client using `KOSapiClient.configure` and setting options inside block.
In addition to returning the client instance from `configure`, the client is also stored in `KOSapiClient` singleton property and its method can be accessed by calling them on `KOSapiClient` directly.
This approach is more suitable for configuring client inside initializer.
In addition to returning the client instance from `configure`, the client is also stored in `KOSapiClient` singleton property and its methods can be accessed by calling them on `KOSapiClient` directly.
This approach is more suitable for configuring client inside an initializer.

```ruby
KOSapiClient.configure do |c|
Expand Down
2 changes: 2 additions & 0 deletions lib/kosapi_client/kosapi_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ module KOSapiClient

singleton_class.class_eval do

attr_reader :client

def new(credentials, root_url = DEFAULT_KOSAPI_ROOT_URL)
http_adapter = OAuth2HttpAdapter.new(credentials, root_url)
http_client = HTTPClient.new(http_adapter)
Expand Down
25 changes: 23 additions & 2 deletions spec/kosapi_client/kosapi_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,29 @@
end
end

it 'can be configured via block' do
expect(@client).not_to be_nil
describe '.configure' do

it 'can be configured via block' do
expect(@client).not_to be_nil
end

end

describe '.reset' do

it 'cleans stored ApiClient instance' do
KOSapiClient.reset
expect(KOSapiClient.client).to be_nil
end

end

describe '.client' do

it 'provides client instance via reader' do
expect(KOSapiClient.client).to eq @client
end

end

it 'delegates missing methods to stored client instance' do
Expand Down

0 comments on commit d612909

Please sign in to comment.