Skip to content
This repository was archived by the owner on Jun 24, 2022. It is now read-only.

Swagger-codegen library #48

Merged
merged 28 commits into from
Jan 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
73 changes: 68 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,68 @@
*~
*.pyc
clever.egg-info
dist
build
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/
venv/
.python-version

# Translations
*.mo
*.pot

# Django stuff:
*.log

# Sphinx documentation
docs/_build/

# PyBuilder
target/

#Ipython Notebook
.ipynb_checkpoints

.travis.yml
git_push.sh
.swagger-codegen/
24 changes: 24 additions & 0 deletions .swagger-codegen-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Swagger Codegen Ignore
# Generated by swagger-codegen https://github.com/swagger-api/swagger-codegen

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell Swagger Codgen to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux

# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
.gitignore
1 change: 0 additions & 1 deletion MANIFEST.in

This file was deleted.

16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.PHONY: all test override deps publish
SHELL := /bin/bash

all: deps test

deps:
pip install -r requirements.txt

test:
python -m unittest discover test

override:
./override/override.sh

publish:
./publish.sh
105 changes: 38 additions & 67 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# Clever Python bindings
# Clever - the Python library for the Clever API

## Maintenance
## API Documentation
View more detailed documentation [here](docs/README.md)

Clever is moving to a community supported model with our client libraries. We will still respond to and merge incoming PRs but are looking to turn over ownership of these libraries to the community. If you are interested, please contact our partner-engineering team at tech-support@clever.com.
## Requirements.

## Installation
Python 2.7 and 3.4+

## Installation
From PyPi:

```bash
Expand All @@ -24,97 +26,66 @@ Or from source:
$ python setup.py install
```

## Usage

Get started by importing the `clever` module and setting your authentication method:

Then import the package:
```python
import clever
clever.set_token('YOUR_OAUTH_TOKEN')
import clever
```

The `clever` module exposes classes corresponding to resources:
## Getting Started

* Contact
* District
* DistrictAdmin
* School
* SchoolAdmin
* Section
* Student
* Teacher
* Event

Each exposes a class method `all` that returns a list of all data in that resource that you have access to. Keyword arguments correspond to the same query parameters supported in the HTTP API, except that `limit` and `page` are not supported (pagination is handled automatically).
Please follow the [installation procedure](#installation) and then run the following:

```python
schools = clever.School.all() # gets information about all schools you have access to
schools = clever.School.all(where=json.dumps({'name': 'Of Hard Knocks'}))
schools = clever.School.all(sort='state')
```
from __future__ import print_function
import time
import clever
from clever.rest import ApiException
from pprint import pprint

# Note: This is hard coded for demo purposes only. Keep your access tokens secret!
# https://dev.clever.com/docs/security#section-security-best-practices
clever.configuration.access_token = 'TEST_TOKEN'
# create an instance of the API class
api_instance = clever.DataApi()

try:
api_response = api_instance.get_students()
for student in api_response.data:
pprint(student.data.id)
except ApiException as e:
print("Exception when calling DataApi->get_students: %s\n" % e)

If you'd like more control over pagination, or to limit the number of resources returned, use the `iter` class method:

```python
students = clever.Student.iter()
for i in range(0,2000):
print students.next()
```

You may also use the `starting_after` or `ending_before` parameters with the `iter` method:
## Updating the Library

```python
students = clever.Student.iter(starting_after="530e5960049e75a9262cff1d")
for s in students:
print students.next()
```
1. Git clone swagger-codegen (https://github.com/swagger-api/swagger-codegen)

The `retrieve` class method takes in a Clever ID and returns a specific resource. The object (or list of objects in the case of `all`) supports accessing properties using either dot notation or dictionary notation:
2. Git clone Clever's swagger-api repo (https://github.com/Clever/swagger-api)

```python
demo_school = clever.School.retrieve("4fee004cca2e43cf27000001")
assert demo_school.name == 'Clever Academy'
assert demo_school['name'] == 'Clever Academy'
3. Run this command in the swagger-codegen repo
```

## CLI

The library comes with a basic command-line interface:

```bash
$ export CLEVER_API_TOKEN=DEMO_TOKEN
$ clever districts all
Running the equivalent of:
--
curl https://api.clever.com/v1.1/districts -H "Authorization: Bearer DEMO_TOKEN"
--
Starting new HTTPS connection (1): api.clever.com
API request to https://api.clever.com/v1.1/districts returned (response code, response body) of (200, '{"data":[{"data":{"name":"Demo District","id":"4fd43cc56d11340000000005"},"uri":"/v1.1/districts/4fd43cc56d11340000000005"}],"links":[{"rel":"self","uri":"/v1.1/districts"}]}')
Result (HTTP status code 200):
--
{"data":[{"data":{"name":"Demo District","id":"4fd43cc56d11340000000005"},"uri":"/v1.1/districts/4fd43cc56d11340000000005"}],"links":[{"rel":"self","uri":"/v1.1/districts"}]}
--
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i $PATH_TO_SWAGGER_API_REPO/v1.2-client.yml -c $PATH_TO_THIS_REPO/override/config.json -l python -o $PATH_TO_THIS_REPO --additional-properties packageVersion=$VERSION
```

Run `clever -h` to see a full list of commands.
4. Run `make override` to copy over the override files

## Feedback
5. Update the CHANGELOG.md with the changes!

Questions, feature requests, or feedback of any kind is always welcome! We're available at [tech-support@clever.com](mailto:tech-support@clever.com).

## Development

### Dependencies

pip install -r requirements.txt
make deps

### Testing

python -m unittest discover test
make test

## Publishing

Update VERSION and CHANGELOG.md and run `publish.sh` to publish a new version of the library.
Run `make publish` to publish a new version of the library.

In order to publish to PyPI you will need a `.pypirc` file in your `$HOME` directory with the following contents:
```
Expand Down
Loading