Dragma

Members
  • Content Count

    55
  • Joined

  • Last visited

  • Days Won

    3

Posts posted by Dragma


  1. Whew,  it has been a long road,  but the latest mile stone is here,  a fully stable working version of the first phase of Rebrickable has launched.

    You may find it here: https://play.google.com/store/apps/details?id=com.coding.dragmas.reinstructable

    and a page for it here: https://www.facebook.com/Reinstructable

    There is more to come,  much more.  I just wanted to get this out before I go to bed.


  2. yep,  just keep on pulling till the next param gives you a null value.  So similar to this (it is essentially how I do it)

    while (Next != null) {	
    	url = Next
    	Result = API_Call(url)
    	...Process the result
    	Next = Result.Next
    }

    Basic psudo code, but you should get the idea,  and this will work no matter how small the page size gets.


  3. Well, looks like I may have bitten off much more then I can chew at this time.  Testing was going fine but then I got the bright idea of loading my full collection and the parts,  needless to say the app is now bogged down and runs horribly slow.

    I gots alot more to learn about SQLite on android.

    As such I have closed down Beta testing (will impact maybe one person) until I can get this running at a satisfactory speed.


  4. Finally got it,  sheesh I did not have this much trouble doing it in c#.  Anyways if anyone else has the problem:

    String postData =  "username=" + URLEncoder.encode ("*******@***.***") + "&password=" + URLEncoder.encode ("********");
    URL url = new URL("https://rebrickable.com/api/v3/users/_token/?key={MyKey}");
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    
    conn.setDoInput(true);
    conn.setDoOutput(true);
    conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
    conn.setRequestProperty("Accept", "application/json");
    conn.setRequestMethod("POST");
    
    // Write body
    OutputStream output = conn.getOutputStream();
    output.write(postData.getBytes());
    int statusCode = conn.getResponseCode();
    if (statusCode == 200) {
        InputStream inputStream = new BufferedInputStream(conn.getInputStream());
        response = convertStreamToString(inputStream);
    }
    output.close();

    it seems the key for this method is to build a flat string with the properties and their encoded values instead of doing from a Key / encoded Value pair.  In this case the postData looks like:

    username=******%40*****.***&password=*******


  5. 6 hours ago, Thomas Jensen said:

    Be quick and grab a promotion code and get my new app "Bricks Quick Sort" for free.

    The app is a paid app so you will not be bothered by any kind of ads what so ever.

    It is an open beta so everyone are welcome.

    Not bad in the UI, and I would like to know how you did your menu (mine is a bit on the plane side).

    But what is the use of the app?  the way you described it is it sounded a bit like the reverse of mine; where set up a collection of sets and import the elements.

    I thought yours would be:  where you enter all the parts you own then figure out what sets can be built.

    Just a bit confused.


  6. I think I may have it, the CURL I get from the test page is:

    curl -X POST --header 'Content-Type: application/x-www-form-urlencoded' --header 'Accept: application/json' --header 'Authorization: key {myKey}' -d 'username=********&password=*******' 'https://rebrickable.com/api/v3/users/_token/'

    it looks like I just need to make sure the username is first,  and separated by &, and maybe single quotes surrounding the login and password.

    I'll test tonight and post my responce.  It could help someone else.


  7. 4 hours ago, dkurok said:

    Hi Dragma,

    I guess that {mykey} will really be replaced with your API-key here and you've used the {myKey}-notation just for clearing out your real key. If not, there may be a problem here.

    At the end of the day when going over the wire, post-data key-valuepairs have to be separated by a "&" and not ",". Otherwise the comma will be part of the password and this breaks your authorization (which explains the 403 - Not authorized)

    Maybe it helps

    Dietmar

    Yes the myKey and ****** are to hide my info.

    And I had tried swapping the "," with "&", And the curly braces with nothing.

     

    Though with a clearer head in the morn I may have a few ideas.


  8. Starting over in Android I am once again having some issues:  I keep on getting a 403 error with this call,  here is the code I am using from Android Studio:

    url = new URL("https://rebrickable.com/api/v3/users/_token/");
    conn = (HttpURLConnection) url.openConnection();
    conn.setDoInput(true);
    conn.setDoOutput(true);
    conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
    conn.setRequestProperty("Accept", "application/json");
    conn.setRequestProperty("Authorization", "key {myKey}");
    conn.setRequestMethod("POST");
    
    // Send the post body
    
    if (prop.PostData != null) {
      String postData = prop.PostData.toString();
      //example postData:
      //"{password=******, username=********}"
      OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream());
      writer.write(postData);
      writer.flush();
    }
    
    int statusCode = conn.getResponseCode();
    if (statusCode ==  200) {
      InputStream inputStream = new BufferedInputStream(conn.getInputStream());
      response = convertStreamToString(inputStream);
    }

    Any ideas?


  9. Well, I have gotten Reinstructable into open Beta,  and it is looking good so far.  

    Search for sets you own from the vast database here on Rebrickable, and then assign locations to the elements within.

    It now pulls that image locations correctly, the previous method seems to have broken, if the mod is watching this I have posted what I think is the fix in the API section, but no one seems to be paying attention there.

    I need to add 2 things to move to production:

    1. Syncing to the users account here at Rebrickable
    2. allow the user to show all the elements listed in the database at once.

    once those are added, I will move this fully to production, but the additions will not end there......

    Planned additions:

    1. Allow the user to import loose pieces, and sync those into their Rebrickable account.
    2. Breakdown sets to allow the user to filter the element list to a more  managable size when rebuilding a set.
    3. SET UP MOCS, as well as import them from Rebrickable.
    4. Allow the user to sync from other sites as well.

    as a reminder or those that want to join in the Beta follow the link:
    https://play.google.com/apps/testing/com.coding.dragmas.reinstructable


  10. Assuming you have gotten a KEY for the API (if not follow the directions here:https://rebrickable.com/api/)

    then you can construct a URL in Access (using vb) similar to this

    https://rebrickable.com/api/v3/lego/colors/?key=<*Your Key*>

    where the <*Your Key*> = the key you had generated.

    After which it will return a JSON object that you will need to parse out into a vb object, which then you should be able to import into your data base.

    Here is a thread which should get you started: https://stackoverflow.com/questions/32768235/creating-a-microsoft-access-database-connection-to-a-rest-based-api

     

    It will take a bit of work, but is well worth it.


  11. I think I have found a fix/workaround for this issue,  looks like the call for:/api/v3/lego/parts/{part_num}/colors/ is still getting the correct URLs.

    {
      "count": 4,
      "next": null,
      "previous": null,
      "results": [
        {
          "color_id": 1,
          "color_name": "Blue",
          "num_sets": 1,
          "num_set_parts": 1,
          "part_img_url": "https://m.rebrickable.com/media/parts/elements/4612111.jpg",
          "elements": [
            "4612111"
          ]
        },
        {
          "color_id": 5,
          "color_name": "Dark Pink",
          "num_sets": 1,
          "num_set_parts": 1,
          "part_img_url": "https://m.rebrickable.com/media/parts/elements/6056386.jpg",
          "elements": [
            "6056386"
          ]
        },
        {
          "color_id": 15,
          "color_name": "White",
          "num_sets": 3,
          "num_set_parts": 4,
          "part_img_url": "https://m.rebrickable.com/media/parts/elements/4560938.jpg",
          "elements": [
            "4560938"
          ]
        },
        {
          "color_id": 72,
          "color_name": "Dark Bluish Gray",
          "num_sets": 4,
          "num_set_parts": 6,
          "part_img_url": "https://m.rebrickable.com/media/parts/elements/4581526.jpg",
          "elements": [
            "4581526"
          ]
        }
      ]
    }

    looks like the part image URL does have the correct info,  also it seems for the parts, it is using the 1st one it comes across in: /api/v3/lego/sets/{set_num}/partsat least for the part_image_url and is not properly linked in the query.