Skip to content

Commit

Permalink
Readme indentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
tszolar committed May 27, 2014
1 parent 8305943 commit 7ca8902
Showing 1 changed file with 18 additions and 27 deletions.
45 changes: 18 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,21 @@ And then execute:

$ bundle

<!--
Or install it yourself as:
$ gem install kosapi_client
-->

## Basic usage

```ruby
# Creates a new instance of client with OAuth2 credentials
client = KOSapiClient.new(OAUTH_CLIENT_ID, OAUTH_SECRET)

# Creates a new instance of client with OAuth2 credentials
client = KOSapiClient.new(OAUTH_CLIENT_ID, OAUTH_SECRET)

# Retrieves first page of all course events
course_events_page = client.course_events
course_events_page.each { |event| do_stuff_with_event(event) }

# Fetches page of parallels according to API parameters
parallels_page = client.parallels.offset(0).limit(50).query('course.department' => '18*')

# Finds all parallels related to parallel with id = 42
client.parallels.find(42).related
# Retrieves first page of all course events
course_events_page = client.course_events
course_events_page.each { |event| do_stuff_with_event(event) }

# Fetches page of parallels according to API parameters
parallels_page = client.parallels.offset(0).limit(50).query('course.department' => '18*')

# Finds all parallels related to parallel with id = 42
client.parallels.find(42).related
```

## Configuration
Expand All @@ -52,23 +45,21 @@ KOSapiClient can be created and configured in two ways.
The simple way is to call `KOSapiClient.new`, which returns ApiClient instance.

```ruby

client = KOSapiClient.new(OAUTH_CLIENT_ID, OAUTH_SECRET)
client.parallels.find(42)
client = KOSapiClient.new(OAUTH_CLIENT_ID, OAUTH_SECRET)
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.

```ruby
KOSapiClient.configure do |c|
c.client_id = ENV['KOSAPI_OAUTH_CLIENT_ID']
c.client_secret = ENV['KOSAPI_OAUTH_CLIENT_SECRET']
end

KOSapiClient.configure do |c|
c.client_id = ENV['KOSAPI_OAUTH_CLIENT_ID']
c.client_secret = ENV['KOSAPI_OAUTH_CLIENT_SECRET']
end

KOSapiClient.parallels.find(42)
KOSapiClient.parallels.find(42)
```


Expand Down

0 comments on commit 7ca8902

Please sign in to comment.