2015-04-09 03:32:10 +00:00
|
|
|
## Installation
|
|
|
|
|
|
|
|
### Build a gem
|
|
|
|
|
|
|
|
You can build the generated client into a gem:
|
|
|
|
|
|
|
|
```shell
|
|
|
|
gem build swagger-client.gemspec
|
|
|
|
```
|
|
|
|
|
|
|
|
Then you can either install the gem:
|
|
|
|
|
|
|
|
```shell
|
2015-04-17 01:33:49 +00:00
|
|
|
gem install ./swagger-client-1.0.0.gem
|
2015-04-09 03:32:10 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
or publish the gem to a gem server like [RubyGems](https://rubygems.org/).
|
|
|
|
|
|
|
|
Finally add this to your Gemfile:
|
|
|
|
|
2015-04-17 01:33:49 +00:00
|
|
|
gem 'swagger-client', '~> 1.0.0'
|
2015-04-09 03:32:10 +00:00
|
|
|
|
|
|
|
### Host as a git repository
|
|
|
|
|
|
|
|
You can also choose to host the generated client as a git repository, e.g. on github:
|
|
|
|
https://github.com/xhh/swagger-petstore-ruby
|
|
|
|
|
|
|
|
Then you can reference it in Gemfile:
|
|
|
|
|
|
|
|
gem 'swagger-client', :git => 'https://github.com/xhh/swagger-petstore-ruby.git'
|
|
|
|
|
|
|
|
### Use without installation
|
|
|
|
|
|
|
|
You can also use the client directly like this:
|
|
|
|
|
|
|
|
```shell
|
|
|
|
ruby -Ilib script.rb
|
|
|
|
```
|
|
|
|
|
|
|
|
## Configuration
|
|
|
|
|
|
|
|
```ruby
|
|
|
|
require 'swagger-client'
|
|
|
|
|
2015-04-20 02:12:02 +00:00
|
|
|
SwaggerClient::Swagger.configure do |config|
|
2015-04-09 03:32:10 +00:00
|
|
|
config.api_key = 'special-key'
|
|
|
|
config.host = 'petstore.swagger.io'
|
|
|
|
config.base_path = '/v2'
|
|
|
|
end
|
|
|
|
```
|
|
|
|
|
|
|
|
## Getting Started
|
|
|
|
|
|
|
|
```ruby
|
2015-04-20 02:12:02 +00:00
|
|
|
pet = SwaggerClient::PetApi.get_pet_by_id(5)
|
2015-04-09 03:32:10 +00:00
|
|
|
puts pet.to_body
|
|
|
|
```
|