Skip to content

Commit

Permalink
feat: add RapidAPI::API.load
Browse files Browse the repository at this point in the history
  • Loading branch information
adamcooke committed Oct 7, 2020
1 parent ac2db76 commit e5e60c7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,10 @@ rescue RapidAPI::CommunicationError => error
error.message # => Text describing the communication error
end
```

If you prefer to make a quick API call, you can do so more quickly...

```ruby
api = RapidAPI::API.load('api.example.com')
api.perform(:get, 'products')
```
10 changes: 10 additions & 0 deletions lib/rapid_api/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,15 @@ def handle_response(response)
raise RequestError.new(self, status_code, body)
end

class << self

def load(*args)
api = new(*args)
api.load_schema
api
end

end

end
end
8 changes: 8 additions & 0 deletions spec/specs/lib/rapid_api/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
describe RapidAPI::API do
subject(:api) { described_class.new('api.example.com', namespace: 'v1') }

context '.load' do
it 'loads the schema' do
api = described_class.load('api.example.com', namespace: 'v1')
expect(api.schema?).to be true
expect(api.schema).to be_a RapidSchemaParser::Schema
end
end

context '#ssl?' do
it 'is true by default' do
expect(api.ssl?).to be true
Expand Down

0 comments on commit e5e60c7

Please # to comment.