Skip to content
This repository was archived by the owner on Dec 10, 2019. It is now read-only.

Commit efc943c

Browse files
authored
Point to user-configable swagger spec location (#49)
1 parent 218abca commit efc943c

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

README.rst

+11
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ Usage
2121
# Get TMS URl without token
2222
one_project.tms()
2323
24+
Versions
25+
~~~~~~~~
26+
27+
The latest version of `rasterfoundry` always points to the most recently released swagger spec in
28+
the raster-foundry/raster-foundy-api-spec repository. If you need to point to a different spec
29+
version, either install a version of the python client that refers to the appropriate spec, or
30+
set the `RF_API_SPEC_PATH` environment variable to a url or local file path pointing to the
31+
version of the spec that you want to use.
32+
33+
Generally this shouldn't matter, because the Raster Foundry API shouldn't have breaking changes.
34+
2435

2536
Installation
2637
------------

rasterfoundry/api.py

+19-8
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
1-
import os
21
import json
2+
import os
33
import uuid
44

5-
from bravado.requests_client import RequestsClient
65
from bravado.client import SwaggerClient
7-
from bravado.swagger_model import load_file
6+
from bravado.requests_client import RequestsClient
7+
from bravado.swagger_model import load_file, load_url
88
from simplejson import JSONDecodeError
99

10-
from .models import Project, MapToken, Analysis
11-
from .exceptions import RefreshTokenException
1210
from .aws.s3 import str_to_file
11+
from .exceptions import RefreshTokenException
12+
from .models import Analysis, MapToken, Project
1313
from .settings import RV_TEMP_URI
1414

15-
SPEC_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)),
16-
'spec.yml')
15+
try:
16+
from urllib.parse import urlparse
17+
except ImportError:
18+
from urlparse import urlparse
19+
20+
21+
SPEC_PATH = os.getenv(
22+
'RF_API_SPEC_PATH',
23+
'https://raw.githubusercontent.com/raster-foundry/raster-foundry-api-spec/master/spec.yml'
24+
)
1725

1826

1927
class API(object):
@@ -34,7 +42,10 @@ def __init__(self, refresh_token=None, api_token=None,
3442
self.http = RequestsClient()
3543
self.scheme = scheme
3644

37-
spec = load_file(SPEC_PATH)
45+
if urlparse(SPEC_PATH).netloc:
46+
spec = load_url(SPEC_PATH)
47+
else:
48+
spec = load_file(SPEC_PATH)
3849

3950
spec['host'] = host
4051
spec['schemes'] = [scheme]

0 commit comments

Comments
 (0)