~ubuntu-branches/ubuntu/vivid/unity-scope-click/vivid

« back to all changes in this revision

Viewing changes to scope/clickstore/pay.h

  • Committer: Package Import Robot
  • Author(s): CI Train Bot, Alejandro J. Cura, CI Train Bot, Pawel Stolowski
  • Date: 2015-03-26 18:49:47 UTC
  • mfrom: (1.1.87)
  • Revision ID: package-import@ubuntu.com-20150326184947-ixmeux4m98o3nkat
Tags: 0.1.1+15.04.20150326-0ubuntu1
[ Alejandro J. Cura ]
* Fake webservices for the integration tests
* Fetch the "refundable_until" field from the /purchases endpoint, and
  store it as a GMT timestamp
* Use table widget in previews (LP: #1407680)

[ CI Train Bot ]
* New rebuild forced.

[ Pawel Stolowski ]
* Initial set of python integration tests using the scope harness

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
 
33
33
#include <click/webclient.h>
34
34
 
 
35
#include <ctime>
35
36
#include <map>
36
37
#include <memory>
37
38
#include <unordered_set>
39
40
 
40
41
namespace pay
41
42
{
42
 
    typedef std::unordered_set<std::string> PurchasedList;
 
43
    struct Purchase
 
44
    {
 
45
        std::string name;
 
46
        time_t refundable_until;
 
47
 
 
48
        Purchase() = default;
 
49
        Purchase(const std::string &name) : name(name), refundable_until(0)
 
50
        {
 
51
        }
 
52
 
 
53
        Purchase(const std::string& name, time_t refundable_until) :
 
54
            name(name), refundable_until(refundable_until)
 
55
        {
 
56
        }
 
57
 
 
58
        struct hash_name {
 
59
        public :
 
60
            size_t operator()(const Purchase &purchase ) const
 
61
            {
 
62
                return std::hash<std::string>()(purchase.name);
 
63
            }
 
64
        };
 
65
 
 
66
    };
 
67
 
 
68
    bool operator==(const Purchase& lhs, const Purchase& rhs);
 
69
 
 
70
    typedef std::unordered_set<Purchase, Purchase::hash_name> PurchaseSet;
 
71
 
43
72
    typedef std::function<void(const std::string& item_id,
44
73
                               bool status)> StatusFunction;
45
74
 
46
 
 
47
75
    constexpr static const char* BASE_URL_ENVVAR{"PAY_BASE_URL"};
48
76
    constexpr static const char* BASE_URL{"https://software-center.ubuntu.com"};
49
77
    constexpr static const char* API_ROOT{"/api/2.0/click/"};
55
83
        JsonKeys() = delete;
56
84
 
57
85
        constexpr static const char* package_name{"package_name"};
 
86
        constexpr static const char* refundable_until{"refundable_until"};
58
87
        constexpr static const char* state{"state"};
59
88
    };
60
89
 
68
97
        virtual ~Package();
69
98
 
70
99
        virtual bool verify(const std::string& pkg_name);
71
 
        virtual click::web::Cancellable get_purchases(std::function<void(const PurchasedList& purchased_apps)> callback);
 
100
        virtual click::web::Cancellable get_purchases(std::function<void(const PurchaseSet& purchased_apps)> callback);
72
101
 
73
102
        static std::string get_base_url();
74
103