Subversion Repositories SmartDukaan

Rev

Rev 13633 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 13633 Rev 13682
Line -... Line 1...
-
 
1
<?php
1
App::uses('HttpSocket', 'Network/Http');
2
App::uses('HttpSocket', 'Network/Http');
2
 
3
 
3
class FarAwaySource extends DataSource {
4
class FarAwaySource extends DataSource {
4
 
5
 
5
/**
6
/**
Line 10... Line 11...
10
/**
11
/**
11
 * Our default config options. These options will be customized in our
12
 * Our default config options. These options will be customized in our
12
 * ``app/Config/database.php`` and will be merged in the ``__construct()``.
13
 * ``app/Config/database.php`` and will be merged in the ``__construct()``.
13
 */
14
 */
14
    public $config = array(
15
    public $config = array(
15
        'apiKey' => '',
16
        'apiHost' => '',
16
    );
17
    );
17
 
18
 
18
/**
19
/**
19
 * If we want to create() or update() we need to specify the fields
20
 * If we want to create() or update() we need to specify the fields
20
 * available. We use the same array keys as we do with CakeSchema, eg.
21
 * available. We use the same array keys as we do with CakeSchema, eg.
21
 * fixtures and schema migrations.
22
 * fixtures and schema migrations.
22
 */
23
 */
23
    protected $_schema = array(
24
    protected $_schema = array(
24
        'id' => array(
25
        'sku' => array(
25
            'type' => 'integer',
26
            'type' => 'integer',
26
            'null' => false,
27
            'null' => false,
27
            'key' => 'primary',
28
            'key' => 'primary',
28
            'length' => 11,
29
            'length' => 11,
29
        ),
30
        ),
30
        'name' => array(
31
        'startDate' => array(
31
            'type' => 'string',
32
            'type' => 'integer',
32
            'null' => true,
33
            'null' => false,
33
            'length' => 255,
34
            'length' => 20,
34
        ),
35
        ),
35
        'message' => array(
36
        'endDate' => array(
36
            'type' => 'text',
37
            'type' => 'integer',
37
            'null' => true,
38
            'null' => false,
-
 
39
            'length' => 20,
38
        ),
40
        ),
-
 
41
        'scheme_amount' => array(
-
 
42
            'type' => 'float',
-
 
43
            'null' => false,
-
 
44
            // 'length' => 8,
-
 
45
        ),        
39
    );
46
    );
40
 
47
 
41
/**
48
/**
42
 * Create our HttpSocket and handle any config tweaks.
49
 * Create our HttpSocket and handle any config tweaks.
43
 */
50
 */
Line 65... Line 72...
65
 * You may want a different schema for each model but still use a single
72
 * You may want a different schema for each model but still use a single
66
 * datasource. If this is your case then set a ``schema`` property on your
73
 * datasource. If this is your case then set a ``schema`` property on your
67
 * models and simply return ``$model->schema`` here instead.
74
 * models and simply return ``$model->schema`` here instead.
68
 */
75
 */
69
    public function describe($model) {
76
    public function describe($model) {
-
 
77
        return $model->schema;
70
        return $this->_schema;
78
        // return $this->_schema;
71
    }
79
    }
72
 
80
 
73
/**
81
/**
74
 * calculate() is for determining how we will count the records and is
82
 * calculate() is for determining how we will count the records and is
75
 * required to get ``update()`` and ``delete()`` to work.
83
 * required to get ``update()`` and ``delete()`` to work.
Line 100... Line 108...
100
        /**
108
        /**
101
         * Now we get, decode and return the remote data.
109
         * Now we get, decode and return the remote data.
102
         */
110
         */
103
        $queryData['conditions']['apiKey'] = $this->config['apiKey'];
111
        $queryData['conditions']['apiKey'] = $this->config['apiKey'];
104
        $json = $this->Http->get(
112
        $json = $this->Http->get(
105
            'http://example.com/api/list.json',
113
            'http://104.200.25.40:8057/discountInfo/getAllSkuSchemeDetails',
106
            $queryData['conditions']
114
            $queryData['conditions']
107
        );
115
        );
108
        $res = json_decode($json, true);
116
        $res = json_decode($json, true);
109
        if (is_null($res)) {
117
        if (is_null($res)) {
110
            $error = json_last_error();
118
            $error = json_last_error();