Skip to content

Commit

Permalink
Merge branch 'master' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
salvoventura committed Nov 28, 2018
2 parents cd40f5f + b9e3f7b commit c110b8f
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 48 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ cache: pip

python:
- "2.7"
- "3.5"
- "3.6"
- "pypy"

before_install:
Expand Down
8 changes: 8 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ Documentation is published on `ReadTheDocs <http://pypexels.readthedocs.io/>`_.
#######
Version
#######
**PyPexels v1.0.0b2 (beta, v2)**

Second beta release introduces Python3 support.

Note that using this library you still need to abide to Pexels Guidelines, which
are explained on `Pexels API page <https://www.pexels.com/api/>`_


**PyPexels v1.0.0b1 (beta, v1)**

First release with wrappers around the two Pexels API for `search` and `popular`.
Expand Down
11 changes: 6 additions & 5 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
]

# autosummary_generate = False
# Boolean indicating whether to scan all found documents for autosummary directives, and to generate stub pages for each.
# Boolean indicating whether to scan all found documents for autosummary directives,
# and to generate stub pages for each.
# Can also be a list of documents for which stub pages should be generated.
# The new files will be placed in the directories specified in the :toctree: options of the directives.
autosummary_generate = True
Expand Down Expand Up @@ -135,10 +136,10 @@
#
# html_theme = 'alabaster'
# html_theme = 'classic'
html_theme = 'sphinxdoc'
html_theme = 'scrolls'
html_theme = 'agogo'
html_theme = 'nature'
# html_theme = 'sphinxdoc'
# html_theme = 'scrolls'
# html_theme = 'agogo'
# html_theme = 'nature'
html_theme = 'sphinx_rtd_theme'


Expand Down
4 changes: 2 additions & 2 deletions docs/source/version.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Version
=======
**PyPexels v1.0.0b1 (beta, v1)**
**PyPexels v1.0.0b2 (beta, v2)**

First release with wrappers around the two Pexels API for `search` and `popular`.
Second beta release introduces Python3 support.

Note that using this library you still need to abide to Pexels Guidelines, which
are explained on `Pexels API page <https://www.pexels.com/api/>`_
5 changes: 2 additions & 3 deletions pypexels/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@
# Comment: What's new in revision 1
#
###############################################################################

"""An open source Python wrapper for the Unsplash REST API"""

from pypexels import PyPexels
from .pypexels import PyPexels
# TRAVIS_BUILD_NUMBER
# TRAVIS_COMMIT
# TRAVIS_COMMIT_RANGE
# TRAVIS_TAG
__version__ = '1.0.0b1'
__version__ = '1.0.0b2'
__author__ = 'Salvatore Ventura <salvoventura@gmail.com>'
__license__ = 'MIT'
6 changes: 4 additions & 2 deletions pypexels/src/pexelspage.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ def _sanitized_query_parameters(self, kwargs):
return query_params

def _parse_navigation(self):
nopaging_query_parameters = ['{}={}'.format(k, v) for k, v in self._query_parameters.items() if k not in ['page', 'per_page']]
nopaging_query_parameters = ['{}={}'.format(k, v) for k, v in self._query_parameters.items() if
k not in ['page', 'per_page']]
self.nopaging_url = '?'.join([self._url, '&'.join(nopaging_query_parameters)])
self.page = int(self.body.get('page', 1))
self.per_page = int(self.body.get('per_page', 15))
Expand All @@ -131,7 +132,8 @@ def _parse_navigation(self):
'first': '%s&per_page=%s&page=%s' % (self.nopaging_url, self.per_page, 1),
'prev': self.body.get('prev_page', None),
'next': self.body.get('next_page', None),
'last': '%s&per_page=%s&page=%s' % (self.nopaging_url, self.per_page, self.total_results/self.per_page + 1),
'last': '%s&per_page=%s&page=%s' % (
self.nopaging_url, self.per_page, self.total_results / self.per_page + 1),
}

def _ret_link(self, which):
Expand Down
5 changes: 3 additions & 2 deletions pypexels/src/popular.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@

class Popular(PexelsPage):

def __init__(self, api_key, url='/popular', api_version=API_VERSION, **kwargs):
def __init__(self, api_key, url='/popular', api_version=API_VERSION, **kwargs):

if url.find('/popular') == -1:
raise PexelsError('Invalid _url for class Popular(): %s' % url)

valid_options = ['page', 'per_page']
super(Popular, self).__init__(url=url, api_key=api_key, api_version=api_version, valid_options=valid_options, **kwargs)
super(Popular, self).__init__(url=url, api_key=api_key, api_version=api_version, valid_options=valid_options,
**kwargs)

@property
def entries(self):
Expand Down
5 changes: 3 additions & 2 deletions pypexels/src/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ def _request(self, url, method, query_params=None, data=None, **kwargs):
logger.debug('Wiring REST %s %s %s %s', method, req_url, query_params, data)

try:
response = requests.request(method, req_url, params=query_params, data=data, headers=self.req_headers, **kwargs)
response = requests.request(method, req_url, params=query_params, data=data, headers=self.req_headers,
**kwargs)
except Exception as e:
raise PexelsError("Connection error: %s" % e)

Expand All @@ -80,7 +81,7 @@ def _request(self, url, method, query_params=None, data=None, **kwargs):
'HTTP status %s: %s', self._status_code, self._body.get('errors', ['No error message'])
)

except ValueError, e:
except ValueError as e:
logger.error('EXCEPTION: %s', e)
if self._status_code != requests.codes.ok:
logger.error('HTTP EXC status %s: %s', self._status_code, response.text)
Expand Down
3 changes: 2 additions & 1 deletion pypexels/src/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def __init__(self, api_key, url='/search', api_version=API_VERSION, **kwargs):
raise PexelsError('Parameter "query" is mandatory for class Search()')

valid_options = ['page', 'per_page', 'query']
super(Search, self).__init__(url=url, api_key=api_key, api_version=api_version, valid_options=valid_options, **kwargs)
super(Search, self).__init__(url=url, api_key=api_key, api_version=api_version, valid_options=valid_options,
**kwargs)

@property
def entries(self):
Expand Down
29 changes: 16 additions & 13 deletions pypexels/tests/test_popular.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# Comment: What's new in revision 1
#
###############################################################################
from __future__ import print_function
import responses
import json
import os
Expand All @@ -29,7 +30,8 @@ class TestPopular:
root_path = os.environ.get('TRAVIS_BUILD_DIR', None) or os.environ.get('TOXINIDIR', None)

store_mapping = {
'popular': os.sep.join([root_path, 'pypexels', 'tests', 'resources', 'resource__popular_per_page_5_page_2.json']),
'popular': os.sep.join(
[root_path, 'pypexels', 'tests', 'resources', 'resource__popular_per_page_5_page_2.json']),
}

@responses.activate
Expand All @@ -40,7 +42,8 @@ def test_popular(self):

responses.add(
responses.GET,
'{}/{}{}'.format(API_ROOT, API_VERSION, stored_response.get('_url')), # _url contains only the short path like /popular?page=2&per_page=5
'{}/{}{}'.format(API_ROOT, API_VERSION, stored_response.get('_url')),
# _url contains only the short path like /popular?page=2&per_page=5
json=stored_response.get('body'),
status=stored_response.get('status_code'),
content_type='application/json',
Expand All @@ -51,17 +54,17 @@ def test_popular(self):
popular_results_page = py_pexels.popular(page=2, per_page=5)

# Page properties
print popular_results_page.page
print popular_results_page.per_page
print popular_results_page.has_next
print popular_results_page.has_previous
print popular_results_page.link_self
print popular_results_page.link_first
print popular_results_page.link_last
print popular_results_page.link_next
print popular_results_page.link_previous
print(popular_results_page.page)
print(popular_results_page.per_page)
print(popular_results_page.has_next)
print(popular_results_page.has_previous)
print(popular_results_page.link_self)
print(popular_results_page.link_first)
print(popular_results_page.link_last)
print(popular_results_page.link_next)
print(popular_results_page.link_previous)

# Entries
for photo in popular_results_page.entries:
print photo.id, photo.photographer, photo.width, photo.height, photo.url
print photo.src
print(photo.id, photo.photographer, photo.width, photo.height, photo.url)
print(photo.src)
29 changes: 16 additions & 13 deletions pypexels/tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# Comment: What's new in revision 1
#
###############################################################################
from __future__ import print_function
import responses
import json
import os
Expand All @@ -29,7 +30,8 @@ class TestSearch:
root_path = os.environ.get('TRAVIS_BUILD_DIR', None) or os.environ.get('TOXINIDIR', None)

store_mapping = {
'redflower': os.sep.join([root_path, 'pypexels', 'tests', 'resources', 'resource__search_per_page_5_page_2_query_red_flower.json']),
'redflower': os.sep.join(
[root_path, 'pypexels', 'tests', 'resources', 'resource__search_per_page_5_page_2_query_red_flower.json']),
}

@responses.activate
Expand All @@ -40,7 +42,8 @@ def test_search(self):

responses.add(
responses.GET,
'{}/{}{}'.format(API_ROOT, API_VERSION, stored_response.get('_url')), # _url contains only the short path like /popular?page=2&per_page=5
'{}/{}{}'.format(API_ROOT, API_VERSION, stored_response.get('_url')),
# _url contains only the short path like /popular?page=2&per_page=5
json=stored_response.get('body'),
status=stored_response.get('status_code'),
content_type='application/json',
Expand All @@ -51,17 +54,17 @@ def test_search(self):
search_results_page = py_pexels.search(query='red flower', page=2, per_page=5)

# Page properties
print search_results_page.page
print search_results_page.per_page
print search_results_page.has_next
print search_results_page.has_previous
print search_results_page.link_self
print search_results_page.link_first
print search_results_page.link_last
print search_results_page.link_next
print search_results_page.link_previous
print(search_results_page.page)
print(search_results_page.per_page)
print(search_results_page.has_next)
print(search_results_page.has_previous)
print(search_results_page.link_self)
print(search_results_page.link_first)
print(search_results_page.link_last)
print(search_results_page.link_next)
print(search_results_page.link_previous)

# Entries
for photo in search_results_page.entries:
print photo.id, photo.photographer, photo.width, photo.height, photo.url
print photo.src
print(photo.id, photo.photographer, photo.width, photo.height, photo.url)
print(photo.src)
11 changes: 7 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name='pypexels',
version='1.0.0b1',
version='1.0.0b2',
packages=['pypexels', 'pypexels.src'],
url='https://github.com/salvoventura/pypexels',
license='MIT',
Expand All @@ -25,10 +25,13 @@

# Specify the Python versions you support here. In particular, ensure
# that you indicate whether you support Python 2, Python 3 or both.
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 2.7'
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
],
keywords=['pexels', 'rest', 'api', 'python', 'wrapper', 'development', 'pexels.com', 'photography'],
install_requires=['requests'],
python_requires='>=2.7, <3'
python_requires='>=2.7'
)
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py27
envlist = py27,py35,py36

[testenv]
deps =
Expand Down

0 comments on commit c110b8f

Please sign in to comment.