1. #1
    Sencha User
    Join Date
    Apr 2012
    Posts
    16
    Vote Rating
    0
    bino is on a distinguished road

      0  

    Default Answered: How to implement a CURL command on Sencha Touch.

    Answered: How to implement a CURL command on Sencha Touch.


    Hi,

    I am trying create a sencha touch implementation of this CURL command.

    Code:
    curl -X GET \
      -H "X-Parse-Application-Id: ${APPLICATION_ID}" \
      -H "X-Parse-REST-API-Key: ${REST_API_KEY}" \
      -G \
      --data-urlencode 'limit=10' \
      --data-urlencode 'where={
            "location": {
              "$nearSphere": {
                "__type": "GeoPoint",
                "latitude": 30.0,
                "longitude": -20.0
              }
            }
          }' \
      https://api.parse.com/1/classes/PlaceObject
    but no matter how I try I cannot get any result, here's my store proxy implementation not sure if this is correct.

    Code:
    Ext.define('App.store.Routes', {
    	extend: 'Ext.data.Store',
    	requires: ['Ext.data.proxy.Rest'],
    	config: {
    		storeId: 'routes',
    		model: 'App.model.Route',
    		autoLoad: true,
    		proxy: {
    			type: 'rest',
    			useDefaultXhrHeader: false,
    			method: 'GET',
    			url: 'https://api.parse.com/1/classes/Routes',
    			headers: {
    				'Content-Type': 'application/json',
    				'X-Parse-Application-Id':'${APPLICATION_ID}',
    				'X-Parse-REST-API-Key': '${REST_API_KEY}'
    			},
    			extraParams: {
    				'where': {
    					'location': {
    						'$nearSphere' : {
    							'__type' : 'GeoPoint',
    							'latitude' : 30.0,
    							'longitude' : -20.0
    						}
    					}
    				}
    			},
    			format: 'json',
    			reader: {
    				type: 'json',
    				rootProperty: 'results'
    			}
    		}
    	}
    });
    Bit of help is highly appreciated. Thanks in advance.

  2. Seems like the curl command is sending out a string for the "where"-parameter, but in Sencha you're trying to send a JS-object. I think the back-end expects a string too.

    And then something like this I guess:
    Code:
    ..
    config: {
            ..
            listeners: {
                    beforeload: 'onBeforeLoad'
            }
    },
        onBeforeLoad: function (store, operation, eOpts) {
            var proxy = this.getProxy();
            proxy.setExtraParam("where", encodeURI(
                            '{'+
                            '"location": {' +
                            '    "$nearSphere": {' +
                            '        "__type": "GeoPoint",' +
                            '            "latitude": 30.0,' +
                            '            "longitude": -20.0' +
                            '    }' +
                            '}' +
                            '}'));
    
        }
    Debug it using the Developer tools of Chrome (Network tab).

  3. #2
    Sencha User
    Join Date
    Sep 2012
    Posts
    65
    Answers
    7
    Vote Rating
    1
    warrean is on a distinguished road

      0  

    Default


    Seems like the curl command is sending out a string for the "where"-parameter, but in Sencha you're trying to send a JS-object. I think the back-end expects a string too.

    And then something like this I guess:
    Code:
    ..
    config: {
            ..
            listeners: {
                    beforeload: 'onBeforeLoad'
            }
    },
        onBeforeLoad: function (store, operation, eOpts) {
            var proxy = this.getProxy();
            proxy.setExtraParam("where", encodeURI(
                            '{'+
                            '"location": {' +
                            '    "$nearSphere": {' +
                            '        "__type": "GeoPoint",' +
                            '            "latitude": 30.0,' +
                            '            "longitude": -20.0' +
                            '    }' +
                            '}' +
                            '}'));
    
        }
    Debug it using the Developer tools of Chrome (Network tab).
    Last edited by warrean; 26 Feb 2013 at 6:14 AM. Reason: typo

  4. #3
    Sencha User
    Join Date
    Apr 2012
    Posts
    16
    Vote Rating
    0
    bino is on a distinguished road

      0  

    Default


    Hi warrean thanks for the response, I tried your suggestion however it just returns 400 bad request

    Failed to load resource: the server responded with a status of 400 (Bad Request)

    The server returns the following response.


    {"code":107,"error":"invalid json: {"from": { "$nearSphere": { "__type": "GeoPoint", "latitude": 30.0, "longitude": -20.0 }}}"}

  5. #4
    Sencha User
    Join Date
    Sep 2012
    Posts
    65
    Answers
    7
    Vote Rating
    1
    warrean is on a distinguished road

      0  

    Default


    What happens? Do you get a response from the server?

    Perhaps you can post a screenshot of the request being sent (in Chrome - Dev tools - Network) with its parameters.

  6. #5
    Sencha User
    Join Date
    Apr 2012
    Posts
    16
    Vote Rating
    0
    bino is on a distinguished road

      0  

    Default


    Hi again warrean, I got errors here's the screenshot from chrome.

    Error.jpg

  7. #6
    Sencha User
    Join Date
    Sep 2012
    Posts
    65
    Answers
    7
    Vote Rating
    1
    warrean is on a distinguished road

      0  

    Default


    Ok, you get a 400 Bad Request from the server.
    In our case, I think this means one of the parameters is:
    - missing
    - incorrect value
    - incorrect format

    You need to check this further. (you can check the params in Chrome if you click a request)

    Can you get a good response with CURL, do you fill in the $nearSphere, ${APPLICATION_ID} etc ?

  8. #7
    Sencha User
    Join Date
    Apr 2012
    Posts
    16
    Vote Rating
    0
    bino is on a distinguished road

      0  

    Default


    Yes with CURL I do get a correct response and I am able to grab data from the server.

  9. #8
    Sencha User
    Join Date
    Sep 2012
    Posts
    65
    Answers
    7
    Vote Rating
    1
    warrean is on a distinguished road

      0  

    Default


    You need to give more info then, I'm thinking it's just a bad parameter value.

    - Is there a way to compare the request of CURL with the one from the browser (using a proxy tool like Charles).
    - Perhaps you can use a Chrome tool like this one ( https://chrome.google.com/webstore/d...ajhfbgofnpcjmb ) to get a valid response

  10. #9
    Sencha User
    Join Date
    Apr 2012
    Posts
    16
    Vote Rating
    0
    bino is on a distinguished road

      0  

    Default


    This is what I get using a REST Console tool plugin from chrome.

    Code:
    • {
    • "results":[{
    • "from":{
    • "__type":"GeoPoint",
    • "latitude":0.0,
    • "longitude":0.0
    • },
    • "name":"Arvin Dacumos",
    • "rating":5,
    • "routeId":1977473123,
    • "to":{
    • "__type":"GeoPoint",
    • "latitude":14.539222,
    • "longitude":120.981789
    • },
    • "username":"arvindacumos",
    • "createdAt":"2013-02-24T09:09:15.153Z",
    • "updatedAt":"2013-02-24T09:13:42.214Z",
    • "objectId":"pnlWFfpmtI"
    • },{
    • "from":{
    • "__type":"GeoPoint",
    • "latitude":14.752411,
    • "longitude":121.037064
    • },
    • "name":"Arvin Dacumos",
    • "rating":5,
    • "routeId":1977473123,
    • "to":{
    • "__type":"GeoPoint",
    • "latitude":0.0,
    • "longitude":0.0
    • },
    • "username":"arvindacumos",
    • "createdAt":"2013-02-23T06:29:30.087Z",
    • "updatedAt":"2013-02-24T09:13:46.044Z",
    • "objectId":"UPgI0iTYbS"
    • },{
    • "from":{
    • "__type":"GeoPoint",
    • "latitude":14.75239,
    • "longitude":121.037149
    • },
    • "name":"Risavel Aguado",
    • "rating":4,
    • "routeId":6675849932,
    • "to":{
    • "__type":"GeoPoint",
    • "latitude":0.0,
    • "longitude":0.0
    • },
    • "username":"risavelaguado",
    • "createdAt":"2013-02-24T09:24:38.105Z",
    • "updatedAt":"2013-02-24T09:26:38.235Z",
    • "objectId":"Giex48RgH3"
    • },{
    • "from":{
    • "__type":"GeoPoint",
    • "latitude":0.0,
    • "longitude":0.0
    • },
    • "name":"Risavel Aguado",
    • "rating":4,
    • "routeId":6675849932,
    • "to":{
    • "__type":"GeoPoint",
    • "latitude":14.597538,
    • "longitude":121.153107
    • },
    • "username":"risavelaguado",
    • "createdAt":"2013-02-24T09:25:12.521Z",
    • "updatedAt":"2013-02-24T09:26:52.112Z",
    • "objectId":"l7Y71W71fj"
    • }]
    • }
    And this is what I get from CURL command

    Code:
    curl -X GET \
    >   -H "X-Parse-Application-Id: ${APPLICATION_ID}" \
    >   -H "X-Parse-REST-API-Key: ${REST_API_KEY}" \
    >   -G \
    >   --data-urlencode 'limit=10' \
    >   --data-urlencode 'where={
    >         "from": {
    >           "$nearSphere": {
    >             "__type": "GeoPoint",
    >             "latitude": 14.539222,
    >             "longitude": 120.981789
    >           }
    >         }
    >       }' \
    >   https://api.parse.com/1/classes/Routes
    {"results":[{"from":{"__type":"GeoPoint","latitude":14.75239,"longitude":121.037149},"name":"Risavel Aguado","rating":4,"routeId":6675849932,"to":{"__type":"GeoPoint","latitude":0.0,"longitude":0.0},"username":"risavelaguado","createdAt":"2013-02-24T09:24:38.105Z","updatedAt":"2013-02-24T09:26:38.235Z","objectId":"Giex48RgH3"},{"from":{"__type":"GeoPoint","latitude":14.752411,"longitude":121.037064},"name":"Arvin Dacumos","rating":5,"routeId":1977473123,"to":{"__type":"GeoPoint","latitude":0.0,"longitude":0.0},"username":"arvindacumos","createdAt":"2013-02-23T06:29:30.087Z","updatedAt":"2013-02-24T09:13:46.044Z","objectId":"UPgI0iTYbS"},{"from":{"__type":"GeoPoint","latitude":0.0,"longitude":0.0},"name":"Arvin Dacumos","rating":5,"routeId":1977473123,"to":{"__type":"GeoPoint","latitude":14.539222,"longitude":120.981789},"username":"arvindacumos","createdAt":"2013-02-24T09:09:15.153Z","updatedAt":"2013-02-24T09:13:42.214Z","objectId":"pnlWFfpmtI"},{"from":{"__type":"GeoPoint","latitude":0.0,"longitude":0.0},"name":"Risavel Aguado","rating":4,"routeId":6675849932,"to":{"__type":"GeoPoint","latitude":14.597538,"longitude":121.153107},"username":"risavelaguado","createdAt":"2013-02-24T09:25:12.521Z","updatedAt":"2013-02-24T09:26:52.112Z","objectId":"l7Y71W71fj"}]}

  11. #10
    Sencha User
    Join Date
    Apr 2012
    Posts
    16
    Vote Rating
    0
    bino is on a distinguished road

      0  

    Default


    Reading through parse.com's REST API it states that.

    The value of the where parameter should be encoded JSON. Thus, if you look at the actual URL requested, it would be JSON-encoded, then URL-encoded. The simplest use of the whereparameter is constraining the value for keys.



Thread Participants: 1

Tags for this Thread

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar