def hottest_news():
    hacker_news_service = Service('hacker news', 'http')
    get_top = hacker_news_service.register('https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty',
                                           transform=find_top)
    get_info = hacker_news_service.register('https://hacker-news.firebaseio.com/v0/item/{name}.json?print=pretty',
                                            transform=get_url)

    top_stories_query = get_top()
    if top_stories_query.errors:
        print(top_stories_query.errors)
        return
    detail_info_first = get_info(name=top_stories_query.data[0])
    if detail_info_first.errors:
        print(detail_info_first.errors)
        return
    print(detail_info_first.data)
    detail_info_second = get_info(name=top_stories_query.data[1])
    if detail_info_second.errors:
        print(detail_info_second.errors)
        return
    print(detail_info_second.data)
def hottest_news():
    hacker_news_service = Service('hacker news', 'http')
    get_top = hacker_news_service.register(
        'https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty',
        transform=find_top)
    get_info = hacker_news_service.register(
        'https://hacker-news.firebaseio.com/v0/item/{name}.json?print=pretty',
        transform=get_url)

    top_stories_query = get_top()
    if top_stories_query.errors:
        print(top_stories_query.errors)
        return
    detail_info_first = get_info(name=top_stories_query.data[0])
    if detail_info_first.errors:
        print(detail_info_first.errors)
        return
    print(detail_info_first.data)
    detail_info_second = get_info(name=top_stories_query.data[1])
    if detail_info_second.errors:
        print(detail_info_second.errors)
        return
    print(detail_info_second.data)
Example #3
0
def test_proper_initializing_service():
    tiv_api = Service('api tripinview', protocols.HTTP)
    assert hasattr(tiv_api, 'name')
    assert hasattr(tiv_api, 'client')
    assert isinstance(tiv_api.client, HTTPClient)
Example #4
0
def test_service_register_method():
    multi_resource_service = Service('members', protocols.HTTP)
    assert hasattr(multi_resource_service, 'register')
    get_all_users = multi_resource_service.register('get all users')
    assert hasattr(get_all_users, '__call__')
Example #5
0
def test_pretty_service_info():
    github_service = Service('my github repo', protocols.HTTP)
    assert str(github_service) == 'my github repo Service'
    assert repr(
        github_service) == 'Name: my github repo, Type: http, Instances: 1'
Example #6
0
def test_errors_initializing_service_protocol():
    with pytest.raises(ServiceTypeException) as e:
        fail_type = Service('test service', 'peinaw')
    assert 'protocol type' in str(e.value)
Example #7
0
def test_errors_initializing_service_name():
    with pytest.raises(ServiceTypeException) as e:
        fail_name = Service(45, protocols.DB)
    assert 'Name of service' in str(e.value)
def test_service_register_method():
    multi_resource_service = Service('members', protocols.HTTP)
    assert hasattr(multi_resource_service, 'register')
    get_all_users = multi_resource_service.register('get all users')
    assert hasattr(get_all_users, '__call__')
Example #9
0
from external_service.service import Service

random_numbers_service = Service('random org', 'http')


def get_random_numbers(data):
    return data.get('results').get('random').get('data')


post_data = {
    "jsonrpc": "2.0",
    "method": "generateIntegers",
    "params": {
        "apiKey": "c3292e99-4221-441c-a74f-e81987876f89",
        "n": 12,
        "min": 1,
        "max": 80
    },
    "id": 42
}


class Lottery:
    history = []

    def __init__(self, choice, win=None):
        self.choice = choice
        if win or self._lottery_result():
            self.history.append('YOU WIN!!! \n with number {}'.format(
                self.choice))
        else:
Example #10
0
def members_service():
    return Service('members', 'http')