| Total Complexity | 10 |
| Total Lines | 50 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | module Rapis |
||
| 2 | class Client |
||
| 3 | def api |
||
| 4 | Aws::APIGateway::Client.new |
||
| 5 | end |
||
| 6 | |||
| 7 | def create(name, desc) |
||
| 8 | opt = {} |
||
| 9 | opt[:name] = name |
||
| 10 | opt[:description] = desc unless desc.nil? |
||
| 11 | api.create_rest_api(opt) |
||
| 12 | end |
||
| 13 | |||
| 14 | def get_apis(pos = nil) |
||
| 15 | opt = {} |
||
| 16 | opt[:limit] = 500 |
||
| 17 | opt[:position] = pos unless pos.nil? |
||
| 18 | |||
| 19 | ret = api.get_rest_apis(opt) |
||
| 20 | ret.items.concat(get_apis(ret.posision)) unless ret.position.nil? |
||
| 21 | ret.items |
||
| 22 | end |
||
| 23 | |||
| 24 | def get_stages(api_id) |
||
| 25 | api.get_stages(rest_api_id: api_id).item |
||
| 26 | end |
||
| 27 | |||
| 28 | def export_api(api_id, stage_name) |
||
| 29 | ret = api.get_export( |
||
| 30 | rest_api_id: api_id, |
||
| 31 | stage_name: stage_name, |
||
| 32 | export_type: 'swagger', |
||
| 33 | parameters: { extensions: 'integrations' } |
||
| 34 | ) |
||
| 35 | |||
| 36 | JSON.load(ret.body.read) |
||
| 37 | end |
||
| 38 | |||
| 39 | def put_api(api_id, data) |
||
| 40 | api.put_rest_api( |
||
| 41 | rest_api_id: api_id, |
||
| 42 | mode: 'overwrite', |
||
| 43 | parameters: { extensions: 'integrations' }, |
||
| 44 | body: JSON.dump(data) |
||
| 45 | ) |
||
| 46 | end |
||
| 47 | |||
| 48 | def deploy(args) |
||
| 49 | api.create_deployment(args) |
||
| 50 | end |
||
| 51 | end |
||
| 53 |