2
# -*- coding: utf-8 -*-
5
# Copyright (C) 2013 ~ 2014 National University of Defense Technology(NUDT) & Kylin Ltd
8
# This program is free software: you can redistribute it and/or modify it
9
# under the terms of the GNU General Public License version 3, as published
10
# by the Free Software Foundation.
12
# This program is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranties of
14
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15
# PURPOSE. See the GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License along
18
# with this program. If not, see <http://www.gnu.org/licenses/>.
21
"""This module provides the RatingsAndReviewsAPI class for talking to the
22
ratings and reviews API, plus a few helper classes.
27
sys.setdefaultencoding('utf8')
28
from urllib import quote_plus
29
from piston_mini_client import (
37
from piston_mini_client.validators import validate_pattern, validate
38
from piston_mini_client import APIError
41
# These are factored out as constants for if you need to work against a
42
# server that doesn't support both schemes (like http-only dev servers)
43
PUBLIC_API_SCHEME = 'http'
44
AUTHENTICATED_API_SCHEME = 'https'
47
class WeatherPistonAPI(PistonAPI):
48
"""A client for talking to the reviews and ratings API.
50
If you pass no arguments into the constructor it will try to connect to
51
localhost:8000 so you probably want to at least pass in the
52
``service_root`` constructor argument.
54
default_service_observe = 'observe'
55
default_content_type = 'application/x-www-form-urlencoded'
57
@validate_pattern('cityid', r'[0-9a-z+-.:/]+', required=False)
59
def get_cma_observe_weather(self, cityid):
60
url = '%s/%s/' % (self.default_service_observe, cityid)
61
return self._get(url, scheme=PUBLIC_API_SCHEME)