Esempio n. 1
0
def create_local_project(session, title, description, currency, budget, jobs,
                         location):
    """
    Create a fixed project
    """
    project_data = {
        'title': title,
        'description': description,
        'currency': currency,
        'budget': budget,
        'jobs': jobs,
        'local': True,
        'location': location
    }

    # POST /api/projects/0.1/projects/
    response = make_post_request(session, 'projects', json_data=project_data)
    json_data = response.json()
    if response.status_code == 200:
        project_data = json_data['result']
        p = Project(project_data)
        p.url = urljoin(session.url, 'projects/%s' % p.seo_url)
        return p
    else:
        raise ProjectNotCreatedException(
            message=json_data['message'],
            error_code=json_data['error_code'],
        )
Esempio n. 2
0
def create_hireme_project(session, title, description, currency, budget, jobs,
                          hireme_initial_bid):
    """
    Create a fixed project
    """
    jobs.append(create_job_object(id=417))  # Hire Me job, required

    project_data = {
        'title': title,
        'description': description,
        'currency': currency,
        'budget': budget,
        'jobs': jobs,
        'hireme': True,
        'hireme_initial_bid': hireme_initial_bid
    }

    # POST /api/projects/0.1/projects/
    response = make_post_request(session, 'projects', json_data=project_data)
    json_data = response.json()
    if response.status_code == 200:
        project_data = json_data['result']
        p = Project(project_data)
        p.url = urljoin(session.url, 'projects/%s' % p.seo_url)
        return p
    else:
        raise ProjectNotCreatedException(
            message=json_data['message'],
            error_code=json_data['error_code'],
        )
Esempio n. 3
0
def create_milestone_payment(session, project_id, amount, bidder_id,
                             description, reason):
    """
    Create a milestone payment
    """
    milestone_data = {
        'project_id': project_id,
        'bidder_id': bidder_id,
        'description': description,
        'amount': amount,
        'reason': reason,
    }
    session.session.headers[
        'X-Freelancer-Time-V1'] = session.session.headers.get(
            'X-Freelancer-Time-V1', int(time.time()))
    # POST /api/projects/0.1/milestones/
    response = make_post_request(session,
                                 'milestones',
                                 json_data=milestone_data)
    json_data = response.json()
    if response.status_code == 200:
        milestone_data = json_data['result']
        return Milestone(milestone_data)
    else:
        raise MilestoneNotCreatedException(
            message=json_data['message'],
            error_code=json_data['error_code'],
        )
Esempio n. 4
0
def post_review(session, review):
    """
    Post a review
    """
    # POST /api/projects/0.1/reviews/
    response = make_post_request(session, 'reviews', json_data=review)
    json_data = response.json()
    if response.status_code == 200:
        return json_data['status']
    else:
        raise ReviewNotPostedException(message=json_data['message'],
                                       error_code=json_data['error_code'])
Esempio n. 5
0
def create_milestone_request(session, project_id, bid_id, description, amount):
    """
    Create a milestone request
    """
    milestone_request_data = {
        'project_id': project_id,
        'bid_id': bid_id,
        'description': description,
        'amount': amount,
    }
    # POST /api/projects/0.1/milestone_requests/
    response = make_post_request(session,
                                 'milestone_requests',
                                 json_data=milestone_request_data)
    json_data = response.json()
    if response.status_code == 200:
        milestone_request_data = json_data['result']
        return MilestoneRequest(milestone_request_data)
    else:
        raise MilestoneRequestNotCreatedException(
            message=json_data['message'], error_code=json_data['error_code'])
Esempio n. 6
0
def post_track(session, user_id, project_id, latitude, longitude):
    """
    Start tracking a project by creating a track
    """
    tracking_data = {
        'user_id': user_id,
        'project_id': project_id,
        'track_point': {
            'latitude': latitude,
            'longitude': longitude
        }
    }

    # POST /api/projects/0.1/tracks/
    response = make_post_request(session, 'tracks', json_data=tracking_data)
    json_data = response.json()
    if response.status_code == 200:
        return json_data['result']
    else:
        raise TrackNotCreatedException(message=json_data['message'],
                                       error_code=json_data['error_code'])
Esempio n. 7
0
def place_project_bid(session, project_id, bidder_id, description, amount,
                      period, milestone_percentage):
    """
    Place a bid on a project
    """
    bid_data = {
        'project_id': project_id,
        'bidder_id': bidder_id,
        'description': description,
        'amount': amount,
        'period': period,
        'milestone_percentage': milestone_percentage,
    }
    # POST /api/projects/0.1/bids/
    response = make_post_request(session, 'bids', json_data=bid_data)
    json_data = response.json()
    if response.status_code == 200:
        bid_data = json_data['result']
        return Bid(bid_data)
    else:
        raise BidNotPlacedException(message=json_data['message'],
                                    error_code=json_data['error_code'])
Esempio n. 8
0
def place_project_bid(session, project_id, bidder_id, description,
                      amount, period, milestone_percentage):
    """
    Place a bid on a project
    """
    bid_data = {'project_id': project_id,
                'bidder_id': bidder_id,
                'description': description,
                'amount': amount,
                'period': period,
                'milestone_percentage': milestone_percentage
                }
    # POST /api/projects/0.1/bids/
    response = make_post_request(session, 'bids', json_data=bid_data)
    json_data = response.json()
    if response.status_code == 200:
        bid_data = json_data['result']
        return Bid(bid_data)
    else:
        raise BidNotPlacedException(message=json_data['message'],
                                    error_code=json_data['error_code'],
                                    )
Esempio n. 9
0
def create_milestone_payment(session, project_id, amount, bidder_id, description,
                             reason):
    """
    Create a milestone payment
    """
    milestone_data = {'project_id': project_id,
                      'bidder_id': bidder_id,
                      'description': description,
                      'amount': amount,
                      'reason': reason,
                     }
    session.session.headers['X-Freelancer-Time-V1'] = session.session.headers.get(
        'X-Freelancer-Time-V1', int(time.time()))
    # POST /api/projects/0.1/milestones/
    response = make_post_request(session, 'milestones', json_data=milestone_data)
    json_data = response.json()
    if response.status_code == 200:
        milestone_data = json_data['result']
        return Milestone(milestone_data)
    else:
        raise MilestoneNotCreatedException(message=json_data['message'],
                                           error_code=json_data['error_code'],
                                           )
Esempio n. 10
0
def create_project(session, title, description,
                   currency, budget, jobs):
    """
    Create a project
    """
    project_data = {'title': title,
                    'description': description,
                    'currency': currency,
                    'budget': budget,
                    'jobs': jobs
                    }

    # POST /api/projects/0.1/projects/
    response = make_post_request(session, 'projects', json_data=project_data)
    json_data = response.json()
    if response.status_code == 200:
        project_data = json_data['result']
        p = Project(project_data)
        p.url = urljoin(session.url, 'projects/%s' % p.seo_url)
        return p
    else:
        raise ProjectNotCreatedException(message=json_data['message'],
                                         error_code=json_data['error_code'],
                                         )