Skip to content

Commit

Permalink
Merge pull request #15 from sivakov512/support-api-key
Browse files Browse the repository at this point in the history
Support api key
  • Loading branch information
sivakov512 authored Feb 25, 2020
2 parents 03feac3 + db20fae commit 828f2b1
Show file tree
Hide file tree
Showing 20 changed files with 841 additions and 241 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
root = true

[*]
end_of_line = lf
charset = utf-8

[*.{yaml,yml}]
indent_style = space
indent_size = 2

[*.json]
indent_style = space
indent_size = 4
3 changes: 2 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[flake8]
exclude = .env
inline-quotes = "
max-line-length = 88
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ jobs:
strategy:
max-parallel: 4
matrix:
python-version: [3.6, 3.7]
python-version: [3.6, 3.7, 3.8]

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
Expand Down
5 changes: 3 additions & 2 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[settings]
line-length=79
multi_line_output=3
combine_as_imports=true
include_trailing_comma=true
line-length=88
multi_line_output=3
use_parentheses = true
29 changes: 0 additions & 29 deletions .travis.yml

This file was deleted.

19 changes: 13 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Yandex Geocoder
===
Get address coordinates via Yandex geocoder

[![Build Status](https://github.com/sivakov512/yandex-geocoder/workflows/test/badge.svg)](https://github.com/sivakov512/yandex-geocoder)
[![Build Status](https://github.com/sivakov512/yandex-geocoder/workflows/test/badge.svg)](https://github.com/sivakov512/yandex-geocoder/actions?query=workflow%3Atest)
[![Coverage Status](https://coveralls.io/repos/github/sivakov512/yandex-geocoder/badge.svg?branch=master)](https://coveralls.io/github/sivakov512/yandex-geocoder?branch=master)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)
[![Python versions](https://img.shields.io/pypi/pyversions/yandex-geocoder.svg)](https://pypi.python.org/pypi/yandex-geocoder)
Expand All @@ -18,10 +18,21 @@ pip install yandex-geocoder

Usage example
---
Yandex Geocoder requires an API developer key, you can get it [here](https://developer.tech.yandex.ru/services/) to use this library.

``` python
from decimal import Decimal

from yandex_geocoder import Client
Client.coordinates('Хабаровск 60 октября 150') # ('135.114326', '48.47839')


client = Client("your-api-key")

coordinates = client.coordinates("Москва Льва Толстого 16")
assert coordinates == (Decimal("37.587093"), Decimal("55.733969"))

address = client.address(Decimal("37.587093"), Decimal("55.733969"))
assert address == "Россия, Москва, улица Льва Толстого, 16"
```

Development and contribution
Expand Down Expand Up @@ -49,7 +60,3 @@ black --check ./
```

* feel free to contribute!

Credits
---
- [f213](https://github.com/f213)
3 changes: 0 additions & 3 deletions pyproject.toml

This file was deleted.

44 changes: 22 additions & 22 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
appdirs==1.4.3
atomicwrites==1.3.0
attrs==19.3.0
black==19.3b0
certifi==2019.9.11
black==19.10b0
certifi==2019.11.28
chardet==3.0.4
Click==7.0
coverage==4.5.4
coverage==5.0.3
entrypoints==0.3
flake8==3.7.8
flake8-debugger==3.2.0
flake8-isort==2.7.0
flake8-print==3.1.1
flake8-quotes==2.1.0
flake8==3.7.9
flake8-debugger==3.2.1
flake8-isort==2.8.0
flake8-print==3.1.4
flake8-quotes==2.1.1
idna==2.8
importlib-metadata==0.23
isort==4.3.21
mccabe==0.6.1
more-itertools==7.2.0
packaging==19.2
pluggy==0.13.0
py==1.8.0
more-itertools==8.2.0
packaging==20.1
pathspec==0.7.0
pluggy==0.13.1
py==1.8.1
pycodestyle==2.5.0
pyflakes==2.1.1
pyparsing==2.4.2
pytest==5.2.2
pyparsing==2.4.6
pytest==5.3.5
pytest-cov==2.8.1
pytest-mock==1.11.2
pytest-mock==2.0.0
regex==2020.1.8
requests==2.22.0
requests-mock==1.7.0
six==1.12.0
testfixtures==6.10.0
six==1.14.0
testfixtures==6.12.0
toml==0.10.0
urllib3==1.25.6
wcwidth==0.1.7
zipp==0.6.0
typed-ast==1.4.1
urllib3==1.25.8
wcwidth==0.1.8
9 changes: 4 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,21 @@ def read(fname):
setup(
author="Nikita Sivakov",
author_email="[email protected]",
description=(
"Simple library for getting address coordinates via Yandex geocoder"
),
description="Simple library for getting address or coordinates via Yandex geocoder",
install_requires=["requests~=2.22"],
keywords="yandex geocoder geo coordinates maps api",
keywords="yandex geocoder geo coordinates address maps api",
license="MIT",
long_description=read("README.md"),
long_description_content_type="text/markdown",
name="yandex_geocoder",
packages=["yandex_geocoder"],
python_requires=">=3.6",
url="https://github.com/sivakov512/yandex-geocoder",
version="1.0.1",
version="2.0.0",
classifiers=[
"Programming Language :: Python",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
],
)
36 changes: 36 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import json
from urllib.parse import urlencode

import pytest
import requests_mock


@pytest.fixture
def mock_api():
def _encode(geocode: str, api_key: str = "well-known-key") -> str:
params = {"format": "json", "apikey": api_key, "geocode": geocode}
query = urlencode(params)
return f"https://geocode-maps.yandex.ru/1.x/?{query}"

with requests_mock.mock() as _m:
yield lambda resp, status, **encode_kw: _m.get(
_encode(**encode_kw),
json=load_fixture(resp) if isinstance(resp, str) else resp,
status_code=status,
)


def load_fixture(fixture_name: str) -> dict:
with open(f"./tests/fixtures/{fixture_name}.json") as fixture:
return json.load(fixture)


@pytest.fixture
def mock_client_response(mocker):
def _mock(fixture_name):
with open("./tests/fixtures/{}.json".format(fixture_name)) as fixture:
return mocker.patch(
"yandex_geocoder.Client.request", return_value=json.load(fixture),
)

return _mock
Loading

0 comments on commit 828f2b1

Please sign in to comment.